-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add T4 updater from FastLabel annotations
Signed-off-by: ktro2828 <[email protected]>
- Loading branch information
Showing
6 changed files
with
262 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
task: update_t4_with_fastlabel | ||
description: | ||
visibility: | ||
full: "No occlusion of the object." | ||
most: "Object is occluded, but by less than 50%." | ||
partial: "The object is occluded by more than 50% (but not completely)." | ||
none: "The object is 90-100% occluded and no points/pixels are visible in the label." | ||
camera_index: | ||
CAM_FRONT: 0 | ||
CAM_FRONT_RIGHT: 1 | ||
CAM_BACK_RIGHT: 2 | ||
CAM_BACK: 3 | ||
CAM_BACK_LEFT: 4 | ||
CAM_FRONT_LEFT: 5 | ||
|
||
conversion: | ||
input_base: ./data/input/t4_format_2d_annotated # could be non_annotated_t4_format or t4_format_3d_annotated | ||
input_anno_base: ./data/fastlabel | ||
input_bag_base: ./data/rosbag2 | ||
output_base: ./data/output/t4_format_2d_annotated # this only includes the 2D annotations | ||
topic_list: ./config/topic_list_sample.yaml | ||
dataset_corresponding: | ||
# input t4dataset_name: FastLabel json file name | ||
DBv2.0-2-4: 2-4.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
perception_dataset/fastlabel_to_t4/fastlabel_2d_to_t4_updater.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from __future__ import annotations | ||
|
||
import os.path as osp | ||
from pathlib import Path | ||
import shutil | ||
from typing import Dict, List | ||
|
||
from perception_dataset.fastlabel_to_t4.fastlabel_2d_to_t4_converter import ( | ||
FastLabel2dToT4Converter, | ||
) | ||
from perception_dataset.t4_dataset.annotation_files_updater import AnnotationFilesUpdater | ||
from perception_dataset.utils.logger import configure_logger | ||
|
||
logger = configure_logger(modname=__name__) | ||
|
||
|
||
class FastLabel2dToUpdater(FastLabel2dToT4Converter): | ||
def __init__( | ||
self, | ||
input_base: str, | ||
output_base: str, | ||
input_anno_base: str, | ||
dataset_corresponding: Dict[str, int], | ||
overwrite_mode: bool, | ||
description: Dict[str, Dict[str, str]], | ||
input_bag_base: str | None, | ||
topic_list: Dict[str, List[str]] | List[str], | ||
): | ||
super().__init__( | ||
input_base, | ||
output_base, | ||
input_anno_base, | ||
dataset_corresponding, | ||
overwrite_mode, | ||
description, | ||
input_bag_base, | ||
topic_list, | ||
) | ||
|
||
def convert(self) -> None: | ||
anno_jsons_dict = self._load_annotation_jsons() | ||
fl_annotations = self._format_deepen_annotation(anno_jsons_dict) | ||
|
||
for t4dataset_name in self._t4dataset_name_to_merge: | ||
# Check if input directory exists | ||
input_dir = self._input_base / t4dataset_name | ||
input_annotation_dir = input_dir / "annotation" | ||
if not osp.exists(input_annotation_dir): | ||
logger.warning(f"input_dir {input_dir} not exists.") | ||
continue | ||
|
||
# Check if output directory already exists | ||
output_dir = self._output_base / t4dataset_name / "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 | ||
if self._overwrite_mode or not is_dir_exist: | ||
# Remove existing output directory | ||
shutil.rmtree(output_dir, ignore_errors=True) | ||
# Copy input data to output directory | ||
self._copy_data(input_dir, output_dir) | ||
# Make rosbag | ||
if self._input_bag_base is not None and not osp.exists( | ||
osp.join(output_dir, "input_bag") | ||
): | ||
self._find_start_end_time(input_dir) | ||
self._make_rosbag(str(input_bag_dir), str(output_dir)) | ||
else: | ||
raise ValueError("If you want to overwrite files, use --overwrite option.") | ||
|
||
# Start updating annotations | ||
annotation_files_updater = AnnotationFilesUpdater(description=self._description) | ||
annotation_files_updater.convert_one_scene( | ||
input_dir=input_dir, | ||
output_dir=output_dir, | ||
scene_anno_dict=fl_annotations[t4dataset_name], | ||
dataset_name=t4dataset_name, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os.path as osp | ||
from typing import Any | ||
|
||
from perception_dataset.t4_dataset.annotation_files_generator import AnnotationFilesGenerator | ||
|
||
|
||
class AnnotationFilesUpdater(AnnotationFilesGenerator): | ||
def convert_one_scene( | ||
self, | ||
input_dir: str, | ||
output_dir: str, | ||
scene_anno_dict: dict[str, list[dict[str, Any]]], | ||
dataset_name: str, | ||
) -> None: | ||
anno_dir = osp.join(input_dir, "annotation") | ||
if not osp.exists(anno_dir): | ||
raise ValueError(f"Annotations files doesn't exist in {anno_dir}") | ||
|
||
# Load existence annotation files | ||
self._attribute_table.insert_from_json(osp.join(anno_dir, self._attribute_table.FILENAME)) | ||
self._category_table.insert_from_json(osp.join(anno_dir, self._category_table.FILENAME)) | ||
self._instance_table.insert_from_json(osp.join(anno_dir, self._instance_table.FILENAME)) | ||
self._sample_annotation_table.insert_from_json( | ||
osp.join(anno_dir, self._sample_annotation_table.FILENAME) | ||
) | ||
self._object_ann_table.insert_from_json( | ||
osp.join(anno_dir, self._object_ann_table.FILENAME) | ||
) | ||
self._surface_ann_table.insert_from_json( | ||
osp.join(anno_dir, self._surface_ann_table.FILENAME) | ||
) | ||
|
||
super().convert_one_scene( | ||
input_dir=input_dir, | ||
output_dir=output_dir, | ||
scene_anno_dict=scene_anno_dict, | ||
dataset_name=dataset_name, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters