Skip to content

Commit

Permalink
fix(non_annotated_t4_to_deepen): fix frame skipping logic (#153)
Browse files Browse the repository at this point in the history
* fix skip frame logic

Signed-off-by: Shunsuke Miura <[email protected]>

* increment the version number

Signed-off-by: Shunsuke Miura <[email protected]>

* refactor: extract get_camera_token into a separate function

Signed-off-by: Shunsuke Miura <[email protected]>

---------

Signed-off-by: Shunsuke Miura <[email protected]>
  • Loading branch information
miursh authored Sep 19, 2024
1 parent 76286a6 commit 4853518
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
36 changes: 23 additions & 13 deletions perception_dataset/deepen/non_annotated_t4_to_deepen_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,7 @@ def _convert_one_frame(self, input_dir: str, output_dir: str, frame_index: int):

for camera_sensor_type in self._camera_sensor_types:
camera_channel = camera_sensor_type.value["channel"]

if camera_channel in sample["data"].keys():
camera_token = sample["data"][camera_channel]
else:
sample_data = [s for s in nusc.sample_data if s["sample_token"] == sample["token"]]
for sensor in sample_data:
if sensor["channel"] == camera_channel:
camera_token = sensor["token"]
break
logger.warning(
f"camera: {camera_channel} not found in frame {frame_index}, skipping this frame..."
)
return
camera_token: str | None = self._get_camera_token(camera_channel, sample, nusc)

camera_path, _, cam_intrinsic = nusc.get_sample_data(camera_token)
data_dict: Dict[str, Any] = self._get_data(nusc, camera_token)
Expand Down Expand Up @@ -139,6 +127,28 @@ def _convert_one_frame(self, input_dir: str, output_dir: str, frame_index: int):

config_data.save_json(output_dir)

@staticmethod
def _get_camera_token(camera_channel: str, sample, nusc) -> str | None:
"""Get camera token for `camera_channel` in the given `sample` data from a NuScenes dataset.
Args:
camera_channel (str): Camera channel name e.g. CAM_FRONT to look for
sample: Sample data for a specific frame from NuScenes = `nusc.sample[frame_index]`
nusc (NuScenes): NuScenes dataset
Return:
camera_token: str | None
None if not found
"""
camera_token: str | None = None
if camera_channel in sample["data"].keys():
camera_token = sample["data"][camera_channel]
else:
sample_data = [s for s in nusc.sample_data if s["sample_token"] == sample["token"]]
for sensor in sample_data:
if sensor["channel"] == camera_channel:
camera_token = sensor["token"]
break
return camera_token

def _get_data(self, nusc: NuScenes, sensor_channel_token: str) -> Dict[str, Any]:
sd_record = nusc.get("sample_data", sensor_channel_token)
cs_record = nusc.get("calibrated_sensor", sd_record["calibrated_sensor_token"])
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "perception-dataset"
version = "1.0.14"
version = "1.0.15"
description = "TIER IV Perception dataset has modules to convert dataset from rosbag to t4_dataset"
authors = [
"Yusuke Muramatsu <[email protected]>",
Expand Down

0 comments on commit 4853518

Please sign in to comment.