tr3d icon indicating copy to clipboard operation
tr3d copied to clipboard

RuntimeError torch.cat(): expected a non-empty list of Tensors

Open advancing-panda opened this issue 1 year ago • 2 comments

When I use the command python tools/train.py configs/tr3d/tr3d_s3dis-3d-5class.py to train, the following error appears in file tr3d_head.py 189.

RuntimeError torch.cat(): expected a non-empty list of Tensors File "/mmdetection3d/mmdet3d/models/dense_heads/tr3d_head.py", line 189, in _loss bbox_loss=torch.mean(torch.cat(bbox_losses)), File "/mmdetection3d/mmdet3d/models/dense_heads/tr3d_head.py", line 195, in forward_train gt_bboxes, gt_labels, img_metas) File "/mmdetection3d/mmdet3d/models/detectors/mink_single_stage.py", line 88, in forward_train img_metas) File "/mmdetection3d/mmdet3d/models/detectors/base.py", line 60, in forward return self.forward_train(**kwargs) File "/mmdetection3d/mmdet3d/apis/train.py", line 319, in train_detector runner.run(data_loaders, cfg.workflow) File "/mmdetection3d/mmdet3d/apis/train.py", line 351, in train_model meta=meta) File "/mmdetection3d/tools/train.py", line 259, in main meta=meta) File "/mmdetection3d/tools/train.py", line 263, in main() RuntimeError: torch.cat(): expected a non-empty list of Tensors

After debugging, it was found that bbox_losses and gt_bboxes was empty, causing this error to occur. How should it be corrected?

advancing-panda avatar Mar 12 '24 01:03 advancing-panda

Hi @advancing-panda , Did you make any modification in the code?

Looks like this error can happen with the very low probability if all 16 scenes per batch have no ground truth objects. In this case you can check if len(bbox_losses) == 0 then just return zero tensor here.

filaPro avatar Mar 12 '24 09:03 filaPro

Thank you for your reply! Referring to your reply, I changed the code to the following line and the program ran normally.

bbox_loss=torch.mean(torch.cat(bbox_losses)) if bbox_losses != [] else bbox_losses

advancing-panda avatar Mar 15 '24 01:03 advancing-panda