Skip to content

Commit

Permalink
Fix origin ambiguity with carla dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer@primus committed Apr 8, 2024
1 parent 92e19a0 commit f0b1989
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
25 changes: 16 additions & 9 deletions CUSTOM/convert_any_avstack_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def process_frame(
obj_filepath,
calib_filepath,
lidar_filepath,
nominal_height=1.8,
):
# -- load information
objs = read_objects_from_file(obj_filepath)
Expand All @@ -222,14 +223,7 @@ def process_frame(
filepath = "/" + filepath

# get the new reference frame
ref_integ = calib.reference.integrate(start_at=GlobalOrigin3D)
x_new = np.array([*ref_integ.x[:2], 0])
q_new = tforms.transform_orientation(
[0, 0, tforms.transform_orientation(ref_integ.q, "quat", "euler")[2]],
"euler",
"quat",
)
ref_new = ReferenceFrame(x=x_new, q=q_new, reference=GlobalOrigin3D)
ref_new = calib.reference.get_ground_projected_reference()

# perform compensation and save new file
if not os.path.exists(filepath):
Expand Down Expand Up @@ -280,14 +274,27 @@ def process_frame(
*reversed(bbox_3d.hwl),
bbox_3d.yaw,
]
# ann_info['bbox_3d'][2] = 0 # HACK: consider the bottom of the box.
ann_info[
"num_lidar_pts"
] = 400 # HACK: make this wayyy faster by ignoring sum(maskfilters.filter_points_in_box(pc, bbox_3d.corners))
ann_info["num_radar_pts"] = 0
ann_info["velocity"] = obj.velocity.x[:2]
ann_info["token"] = -1

# -- modifications:
# (1) box is bottom centered
if bbox_3d.where_is_t == "center":
ann_info["bbox_3d"][2] -= bbox_3d.h/2

# (2) yaw is defined as: yaw=0 --> along x, yaw=pi/2 --> along y
pass # already this way

# (3) the anchor generation assumes a nominal sensor height
dx = nominal_height - bbox_3d.reference.x[2]
ann_info["bbox_3d"][2] -= dx

print(ann_info["bbox_3d"][2])

# -- merge infos
instances.append(ann_info)

Expand Down
5 changes: 5 additions & 0 deletions CUSTOM/visualize_converted_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@



if __name__ == "__main__":
pass
2 changes: 1 addition & 1 deletion configs/_base_/datasets/carla-3d-infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class_names = ['car', 'bicycle', 'truck', 'motorcycle']
metainfo = dict(classes=class_names)
dataset_type = 'CarlaDataset'
data_root = 'data/carla/infrastructure/skip_0'
data_root = 'data/carla/infrastructure/skip_0/' # trailing / is necessary
# Input modality for nuScenes dataset, this is consistent with the submission
# format which requires the information in input_modality.
# Input modality for carla dataset
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/carla-3d-vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class_names = ['car', 'bicycle', 'truck', 'motorcycle']
metainfo = dict(classes=class_names)
dataset_type = 'CarlaDataset'
data_root = 'data/carla/vehicle/skip_0'
data_root = 'data/carla/vehicle/skip_0/' # trailing / is nessary
# Input modality for nuScenes dataset, this is consistent with the submission
# format which requires the information in input_modality.
# Input modality for carla dataset
Expand Down
3 changes: 2 additions & 1 deletion configs/_base_/models/pointpillars_hv_fpn_carla_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# If point cloud range is modified, do remember to change all related
# keys in the config.
pc_range = [-100, -100, -5, 100, 100, 5]
anchor_range = [-100, -100, -1.8, 100, 100, -1.8]
nom_h = 1.8 # using a nominal height - this number must be in dataset conversion scripts
anchor_range = [-100, -100, -nom_h, 100, 100, -nom_h]
num_classes = 4

model = dict(
Expand Down
8 changes: 4 additions & 4 deletions mmdet3d/datasets/carla_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,19 @@ def parse_ann_info(self, info: dict) -> dict:
ann_info['centers_2d'] = np.zeros((0, 2), dtype=np.float32)
ann_info['depths'] = np.zeros((0), dtype=np.float32)

# the nuscenes box center is [0.5, 0.5, 0.5], we change it to be
# the same as KITTI (0.5, 0.5, 0)
# the carla box center is [0.5, 0.5, 0] which is the
# same as KITTI
# TODO: Unify the coordinates
if self.load_type in ['fov_image_based', 'mv_image_based']:
gt_bboxes_3d = CameraInstance3DBoxes(
ann_info['gt_bboxes_3d'],
box_dim=ann_info['gt_bboxes_3d'].shape[-1],
origin=(0.5, 0.5, 0.5))
origin=(0.5, 0.5, 0.0))
else:
gt_bboxes_3d = LiDARInstance3DBoxes(
ann_info['gt_bboxes_3d'],
box_dim=ann_info['gt_bboxes_3d'].shape[-1],
origin=(0.5, 0.5, 0.5)).convert_to(self.box_mode_3d)
origin=(0.5, 0.5, 0.0)).convert_to(self.box_mode_3d)

ann_info['gt_bboxes_3d'] = gt_bboxes_3d

Expand Down

0 comments on commit f0b1989

Please sign in to comment.