Skip to content

Commit

Permalink
[Fix]Place the tensor operation on the corresponding device.
Browse files Browse the repository at this point in the history
  • Loading branch information
LRJKD committed Jan 16, 2024
1 parent adce980 commit 1e72c39
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mmdet3d/evaluation/metrics/nuscenes_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pyquaternion
import torch
from mmengine import Config, load
from mmengine.device import get_device
from mmengine.evaluator import BaseMetric
from mmengine.logging import MMLogger
from nuscenes.eval.detection.config import config_factory
Expand Down Expand Up @@ -767,6 +768,7 @@ def nusc_box_to_cam_box3d(
Tuple[:obj:`CameraInstance3DBoxes`, torch.Tensor, torch.Tensor]:
Converted 3D bounding boxes, scores and labels.
"""
device = get_device()
locs = torch.Tensor([b.center for b in boxes]).view(-1, 3)
dims = torch.Tensor([b.wlh for b in boxes]).view(-1, 3)
rots = torch.Tensor([b.orientation.yaw_pitch_roll[0]
Expand All @@ -777,11 +779,11 @@ def nusc_box_to_cam_box3d(
dims[:, [0, 1, 2]] = dims[:, [1, 2, 0]]
rots = -rots

boxes_3d = torch.cat([locs, dims, rots, velocity], dim=1)
boxes_3d = torch.cat([locs, dims, rots, velocity], dim=1).to(device=device)
cam_boxes3d = CameraInstance3DBoxes(
boxes_3d, box_dim=9, origin=(0.5, 0.5, 0.5))
scores = torch.Tensor([b.score for b in boxes])
labels = torch.LongTensor([b.label for b in boxes])
scores = torch.Tensor([b.score for b in boxes]).to(device=device)
labels = torch.LongTensor([b.label for b in boxes]).to(device=device)
nms_scores = scores.new_zeros(scores.shape[0], 10 + 1)
indices = labels.new_tensor(list(range(scores.shape[0])))
nms_scores[indices, labels] = scores
Expand Down

0 comments on commit 1e72c39

Please sign in to comment.