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

[Fix] Several bugs #852

Open
wants to merge 1 commit into
base: 1.0
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions mmdet3d/core/bbox/structures/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@
assert isinstance(cam_box, CameraInstance3DBoxes), \
'input bbox should be CameraInstance3DBoxes!'

loc = cam_box.gravity_center
dim = cam_box.dims
yaw = cam_box.yaw
feats = cam_box.tensor[:, 7:]
loc = cam_box.gravity_center.clone()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function will be deprecated soon and we won't use it in the future. Your fix are correct but I'd suggest you not using this function in your code :)

dim = cam_box.dims.clone()
yaw = cam_box.yaw.clone()
feats = cam_box.tensor[:, 7:].clone()

Check warning on line 181 in mmdet3d/core/bbox/structures/utils.py

View check run for this annotation

Codecov / codecov/patch

mmdet3d/core/bbox/structures/utils.py#L178-L181

Added lines #L178 - L181 were not covered by tests
# rotate along x-axis for np.pi / 2
# see also here: https://github.com/open-mmlab/mmdetection3d/blob/master/mmdet3d/datasets/nuscenes_mono_dataset.py#L557 # noqa
dim[:, [1, 2]] = dim[:, [2, 1]]
Expand All @@ -189,8 +189,8 @@
# this is because mono 3D box class such as `NuScenesBox` has different
# definition of rotation with our `CameraInstance3DBoxes`
yaw = -yaw - np.pi / 2
cam_box = torch.cat([loc, dim, yaw[:, None], feats], dim=1)
cam_box = CameraInstance3DBoxes(
cam_box, box_dim=cam_box.shape[-1], origin=(0.5, 0.5, 0.5))
new_cam_box = torch.cat([loc, dim, yaw[:, None], feats], dim=1)
new_cam_box = CameraInstance3DBoxes(

Check warning on line 193 in mmdet3d/core/bbox/structures/utils.py

View check run for this annotation

Codecov / codecov/patch

mmdet3d/core/bbox/structures/utils.py#L192-L193

Added lines #L192 - L193 were not covered by tests
new_cam_box, box_dim=new_cam_box.shape[-1], origin=(0.5, 0.5, 0.5))

return cam_box
return new_cam_box

Check warning on line 196 in mmdet3d/core/bbox/structures/utils.py

View check run for this annotation

Codecov / codecov/patch

mmdet3d/core/bbox/structures/utils.py#L196

Added line #L196 was not covered by tests
2 changes: 2 additions & 0 deletions mmdet3d/core/visualizer/image_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@

img = raw_img.copy()
cam2img = copy.deepcopy(cam2img)
if len(bboxes3d.tensor) is 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if bboxes3d.tensor.shape[0] == 0 would be better? Also please add a comment indicating that # in case there is no boxes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW just to make sure if this modification is necessary, the code will cause an error if no box is presented right?

return img

Check warning on line 186 in mmdet3d/core/visualizer/image_vis.py

View check run for this annotation

Codecov / codecov/patch

mmdet3d/core/visualizer/image_vis.py#L186

Added line #L186 was not covered by tests
corners_3d = bboxes3d.corners
num_bbox = corners_3d.shape[0]
points_3d = corners_3d.reshape(-1, 3)
Expand Down
5 changes: 3 additions & 2 deletions mmdet3d/core/visualizer/show_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import trimesh
from os import path as osp
from os import environ

from .image_vis import (draw_camera_bbox3d_on_img, draw_depth_bbox3d_on_img,
draw_lidar_bbox3d_on_img)
Expand Down Expand Up @@ -92,7 +93,7 @@ def show_result(points,
result_path = osp.join(out_dir, filename)
mmcv.mkdir_or_exist(result_path)

if show:
if show and environ.get('DISPLAY'):
from .open3d_vis import Visualizer

vis = Visualizer(points)
Expand Down Expand Up @@ -241,7 +242,7 @@ def show_multi_modality_result(img,
result_path = osp.join(out_dir, filename)
mmcv.mkdir_or_exist(result_path)

if show:
if show and environ.get('DISPLAY'):
show_img = img.copy()
if gt_bboxes is not None:
show_img = draw_bbox(
Expand Down
2 changes: 1 addition & 1 deletion mmdet3d/datasets/nuscenes_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@DATASETS.register_module()
class NuScenesDataset(Custom3DDataset):
r"""NuScenes Dataset.
"""NuScenes Dataset.

This class serves as the API for experiments on the NuScenes Dataset.

Expand Down
2 changes: 1 addition & 1 deletion mmdet3d/datasets/nuscenes_mono_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@DATASETS.register_module()
class NuScenesMonoDataset(CocoDataset):
r"""Monocular 3D detection on NuScenes Dataset.
"""Monocular 3D detection on NuScenes Dataset.

This class serves as the API for experiments on the NuScenes Dataset.

Expand Down
4 changes: 2 additions & 2 deletions mmdet3d/datasets/pipelines/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _load_points(self, pts_filename):
points = np.frombuffer(pts_bytes, dtype=np.float32)
except ConnectionError:
mmcv.check_file_exist(pts_filename)
if pts_filename.endswith('.npy'):
if pts_filename.endswith('.npy') or pts_filename.endswith('.npz'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loaded npz file is something like a dict instead of a np.ndarray? I think the following transform can't operate correctly on that?

points = np.load(pts_filename)
else:
points = np.fromfile(pts_filename, dtype=np.float32)
Expand Down Expand Up @@ -390,7 +390,7 @@ def _load_points(self, pts_filename):
points = np.frombuffer(pts_bytes, dtype=np.float32)
except ConnectionError:
mmcv.check_file_exist(pts_filename)
if pts_filename.endswith('.npy'):
if pts_filename.endswith('.npy') or pts_filename.endswith('.npz'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

points = np.load(pts_filename)
else:
points = np.fromfile(pts_filename, dtype=np.float32)
Expand Down
4 changes: 2 additions & 2 deletions mmdet3d/ops/norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, *args, **kwargs):
def forward(self, input):
assert input.dtype == torch.float32, \
f'input should be in float32 type, got {input.dtype}'
if dist.get_world_size() == 1 or not self.training:
if not dist.is_initialized() or dist.get_world_size() == 1 or not self.training:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a comment indicating that # if not in distributed training, we don't apply SyncBN

return super().forward(input)
assert input.shape[0] > 0, 'SyncBN does not support empty inputs'
C = input.shape[1]
Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self, *args, **kwargs):
def forward(self, input):
assert input.dtype == torch.float32, \
f'input should be in float32 type, got {input.dtype}'
if dist.get_world_size() == 1 or not self.training:
if not dist.is_initialized() or dist.get_world_size() == 1 or not self.training:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

return super().forward(input)

assert input.shape[0] > 0, 'SyncBN does not support empty inputs'
Expand Down