From 644a768a1c89138dc46eccd6d229ea9f52fa1c12 Mon Sep 17 00:00:00 2001 From: ktro2828 Date: Fri, 6 Sep 2024 15:25:42 +0900 Subject: [PATCH 1/3] feat: update to extract turn signal attributes Signed-off-by: ktro2828 --- .../fastlabel_2d_to_t4_converter.py | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_converter.py b/perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_converter.py index 1f352e2f..4756f53e 100644 --- a/perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_converter.py +++ b/perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_converter.py @@ -13,6 +13,15 @@ class FastLabel2dToT4Converter(DeepenToT4Converter): + + # Attribution mapping except of object's instance ID and occlusion state. + ATTRIBUTE_MAPPING = { + "frame_by_frame_left": "left_blinker", + "frame_by_frame_right": "right_blinker", + "frame_by_frame_brake": "brake_lamp", + "facing": "vehicle_front_or_rear_or_side", + } + def __init__( self, input_base: str, @@ -178,12 +187,14 @@ def _format_fastlabel_annotation(self, annotations: Dict[str, List[Dict[str, Any fl_annotations[dataset_name] = defaultdict(list) for a in ann["annotations"]: + attribute_names: list[str] = [] + occlusion_state: str = "occlusion_state.none" visibility: str = "Not available" for att in a["attributes"]: if att["key"] == "id": instance_id = att["value"] - if "occlusion_state" in att["key"]: + elif "occlusion_state" in att["key"]: for v in att["value"]: if frame_no in range(v[0], v[1]): occlusion_state = ( @@ -193,15 +204,25 @@ def _format_fastlabel_annotation(self, annotations: Dict[str, List[Dict[str, Any att["key"].split("_")[-1] ) break + else: + attribute_names.append( + self.ATTRIBUTE_MAPPING[att["key"]] + "." + att["value"] + ) + attribute_names.append(occlusion_state) + label_t4_dict: Dict[str, Any] = { - "category_name": a["title"], + # NOTE: Some annotations are missing "title", use "value" instead + "category_name": (a["title"] if "title" in a else a["value"]), "instance_id": instance_id, - "attribute_names": [occlusion_state], + "attribute_names": attribute_names, "visibility_name": visibility, } + two_d_box: list[float] = ( + a["annotations"][0]["points"] if "annotations" in a else a["points"] + ) label_t4_dict.update( { - "two_d_box": a["annotations"][0]["points"], + "two_d_box": two_d_box, "sensor_id": self._camera2idx[camera], } ) From 3e8da8721c9f8163bfa79a7fe24a0840abfae056 Mon Sep 17 00:00:00 2001 From: ktro2828 Date: Tue, 17 Sep 2024 15:08:27 +0900 Subject: [PATCH 2/3] fix: avoid runtime error by reference to undefined variable Signed-off-by: ktro2828 --- .../fastlabel_to_t4/fastlabel_2d_to_t4_converter.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_converter.py b/perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_converter.py index 4756f53e..a7041296 100644 --- a/perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_converter.py +++ b/perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_converter.py @@ -71,9 +71,13 @@ def convert(self): output_dir = output_dir / "t4_dataset" if self._input_bag_base is not None: input_bag_dir = Path(self._input_bag_base) / t4dataset_name + if osp.exists(output_dir): logger.error(f"{output_dir} already exists.") is_dir_exist = True + else: + is_dir_exist = False + if self._overwrite_mode or not is_dir_exist: # Remove existing output directory shutil.rmtree(output_dir, ignore_errors=True) From bfca485a0966bfab55d9c2580c8dd64b5dd051be Mon Sep 17 00:00:00 2001 From: ktro2828 Date: Tue, 17 Sep 2024 15:11:06 +0900 Subject: [PATCH 3/3] feat: allow input rosbag base is None Signed-off-by: ktro2828 --- perception_dataset/convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perception_dataset/convert.py b/perception_dataset/convert.py index cb50f983..edc093a1 100644 --- a/perception_dataset/convert.py +++ b/perception_dataset/convert.py @@ -344,7 +344,7 @@ def main(): input_anno_base = config_dict["conversion"]["input_anno_base"] dataset_corresponding = config_dict["conversion"]["dataset_corresponding"] description = config_dict["description"] - input_bag_base = config_dict["conversion"]["input_bag_base"] + input_bag_base = config_dict["conversion"].get("input_bag_base") topic_list_yaml_path = config_dict["conversion"]["topic_list"] with open(topic_list_yaml_path) as f: topic_list_yaml = yaml.safe_load(f)