From fa360db60692f39869b5097c386f81546aa14a9d Mon Sep 17 00:00:00 2001 From: Shunsuke Miura Date: Mon, 30 Dec 2024 11:14:54 +0900 Subject: [PATCH] change to non-keyframe for no-annotation frame Signed-off-by: Shunsuke Miura --- perception_dataset/deepen/deepen_to_t4_converter.py | 2 +- .../t4_dataset/annotation_files_generator.py | 9 +++++---- .../t4_dataset/annotation_files_updater.py | 11 ++++++++--- .../{ => resolver}/keyframe_consistency_resolver.py | 0 4 files changed, 14 insertions(+), 8 deletions(-) rename perception_dataset/t4_dataset/{ => resolver}/keyframe_consistency_resolver.py (100%) diff --git a/perception_dataset/deepen/deepen_to_t4_converter.py b/perception_dataset/deepen/deepen_to_t4_converter.py index 5290cdd1..e8a44150 100644 --- a/perception_dataset/deepen/deepen_to_t4_converter.py +++ b/perception_dataset/deepen/deepen_to_t4_converter.py @@ -21,7 +21,7 @@ ) from perception_dataset.rosbag2.rosbag2_converter import Rosbag2Converter from perception_dataset.t4_dataset.annotation_files_generator import AnnotationFilesGenerator -from perception_dataset.t4_dataset.keyframe_consistency_resolver import KeyFrameConsistencyResolver +from perception_dataset.t4_dataset.resolver.keyframe_consistency_resolver import KeyFrameConsistencyResolver from perception_dataset.utils.logger import configure_logger import perception_dataset.utils.misc as misc_utils diff --git a/perception_dataset/t4_dataset/annotation_files_generator.py b/perception_dataset/t4_dataset/annotation_files_generator.py index 524d6a4f..7c748690 100644 --- a/perception_dataset/t4_dataset/annotation_files_generator.py +++ b/perception_dataset/t4_dataset/annotation_files_generator.py @@ -87,10 +87,11 @@ def convert_one_scene( nusc = NuScenes(version="annotation", dataroot=input_dir, verbose=False) frame_index_to_sample_token: Dict[int, str] = {} - for frame_index, sample in enumerate(nusc.sample): - frame_index_to_sample_token[frame_index] = sample["token"] + for sample_data in nusc.sample_data: + frame_index = int((sample_data["filename"].split("/")[2]).split(".")[0]) + frame_index_to_sample_token[frame_index] = sample_data["sample_token"] try: - if "LIDAR_TOP" in sample["data"]: + if "LIDAR_TOP" in nusc.sample[0]["data"]: lidar_sensor_channel = SENSOR_ENUM.LIDAR_TOP.value["channel"] else: lidar_sensor_channel = SENSOR_ENUM.LIDAR_CONCAT.value["channel"] @@ -118,7 +119,7 @@ def convert_one_scene( for frame_index_nuim, sample_nuim in enumerate(nuim.sample_data): if ( sample_nuim["fileformat"] == "png" or sample_nuim["fileformat"] == "jpg" - ) and sample_nuim["is_key_frame"]: + ): cam = sample_nuim["filename"].split("/")[1] cam_idx = self._camera2idx[cam] diff --git a/perception_dataset/t4_dataset/annotation_files_updater.py b/perception_dataset/t4_dataset/annotation_files_updater.py index 62d7f4f7..0ed61afb 100644 --- a/perception_dataset/t4_dataset/annotation_files_updater.py +++ b/perception_dataset/t4_dataset/annotation_files_updater.py @@ -1,6 +1,7 @@ import json +from pathlib import Path import os.path as osp -from typing import Any, Dict +from typing import Any, Dict, List from perception_dataset.t4_dataset.annotation_files_generator import AnnotationFilesGenerator from perception_dataset.t4_dataset.classes import ( @@ -12,6 +13,7 @@ SurfaceAnnTable, VisibilityTable, ) +from perception_dataset.t4_dataset.resolver.keyframe_consistency_resolver import KeyFrameConsistencyResolver def _load_json(filepath: str) -> Any: @@ -21,8 +23,8 @@ def _load_json(filepath: str) -> Any: class AnnotationFilesUpdater(AnnotationFilesGenerator): - def __init__(self, with_camera: bool = True, description: Dict[str, Dict[str, str]] = ...): - super().__init__(with_camera, description) + def __init__(self, with_camera: bool = True, description: Dict[str, Dict[str, str]] = ..., surface_categories: List[str] = []): + super().__init__(with_camera, description, surface_categories) self.description = description def convert_one_scene( @@ -46,6 +48,9 @@ def convert_one_scene( dataset_name=dataset_name, ) + modifier = KeyFrameConsistencyResolver() + modifier.inspect_and_fix_t4_segment(Path(output_dir)) + def _init_table_from_json(self, anno_dir: str) -> None: self._attribute_table = AttributeTable.from_json( filepath=osp.join(anno_dir, AttributeTable.FILENAME), diff --git a/perception_dataset/t4_dataset/keyframe_consistency_resolver.py b/perception_dataset/t4_dataset/resolver/keyframe_consistency_resolver.py similarity index 100% rename from perception_dataset/t4_dataset/keyframe_consistency_resolver.py rename to perception_dataset/t4_dataset/resolver/keyframe_consistency_resolver.py