Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support of turn signal annotation conversion #154

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion perception_dataset/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 29 additions & 4 deletions perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -62,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)
Expand Down Expand Up @@ -178,12 +191,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 = (
Expand All @@ -193,15 +208,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],
}
)
Expand Down
Loading