open-mmlab / mmdetection3d

OpenMMLab's next-generation platform for general 3D object detection.
https://mmdetection3d.readthedocs.io/en/latest/
Apache License 2.0
5.26k stars 1.53k forks source link

[Bug] Cannot calculate FLOPS for FCOS3D and SMOKE #2613

Open acg93-pixel opened 1 year ago

acg93-pixel commented 1 year ago

Prerequisite

Task

I'm using the official example scripts/configs for the officially supported tasks/models/datasets.

Branch

main branch https://github.com/open-mmlab/mmdetection3d

Environment

TorchVision: 0.15.2+cu117 OpenCV: 4.7.0 MMEngine: 0.7.3 MMDetection: 3.0.0 MMDetection3D: 1.1.0+47e56e1 spconv2.0: False

Reproduces the problem - code sample

no sample code, using get_flops.py script

Reproduces the problem - command or script

python tools/analysis_tools/get_flops.py configs/smoke/smoke_dla34_dlaneck_gn-all_4xb8-6x_kitti-mono3d.py --shape 1920 500 --modality image

python tools/analysis_tools/get_flops.py configs/fcos3d/fcos3d_r101-caffe-dcn_fpn_head-gn_8xb2-1x_nus-mono3d.py --shape 1920 500 --modality image

Reproduces the problem - error message

Traceback (most recent call last): File "tools/analysis_tools/get_flops.py", line 83, in main() File "tools/analysis_tools/get_flops.py", line 73, in main flops, params = get_model_complexity_info(model, input_shape) File "/home/admin/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/cnn/utils/flops_counter.py", line 107, in get_model_complexityinfo = flops_model(batch) File "/home/admin/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1538, in _call_impl result = forward_call(*args, **kwargs) File "/home/admin/work/object_detection/mmdetection/mmdet/models/detectors/base.py", line 96, in forward return self._forward(inputs, data_samples) File "/home/admin/work/object_detection/mmdetection/mmdet/models/detectors/single_stage.py", line 132, in _forward x = self.extract_feat(batch_inputs) File "/home/admin/work/object_detection/mmdetection3d/mmdet3d/models/detectors/single_stage_mono3d.py", line 90, in extract_feat batch_imgs = batch_inputs_dict['imgs'] TypeError: new(): invalid data type 'str'

Additional information

I'm interesetd in FCOS3D and SMOKE models complexity for this input resolution but I cannot reproduce this script's result as in: https://github.com/open-mmlab/mmdetection3d/pull/736#issuecomment-878772280

Please help, thanks!

akuzminski commented 1 year ago

Sketchy workaround for FCOS3D:

change line 90 of the mmdet3d/models/detectors/single_stage_mono3d.py from batch_imgs = batch_inputs_dict['imgs'] to batch_imgs = batch_inputs_dict

acg93-pixel commented 1 year ago

Thanks, got the result for FCOS3D. When running for SMOKE, I'm getting a tensor mismatch error:

Traceback (most recent call last): File "tools/analysis_tools/get_flops.py", line 90, in main() File "tools/analysis_tools/get_flops.py", line 80, in main flops, params = get_model_complexity_info(model, input_shape) File "/home/xadmin/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/cnn/utils/flops_counter.py", line 107, in get_model_complexityinfo = flops_model(batch) File "/home/acgagovic/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1538, in _call_impl result = forward_call(*args, kwargs) File "/home/xadmin/work/object_detection/mmdetection/mmdet/models/detectors/base.py", line 96, in forward return self._forward(inputs, data_samples) File "/home/xadmin/work/object_detection/mmdetection/mmdet/models/detectors/single_stage.py", line 132, in _forward x = self.extract_feat(batch_inputs) File "/home/xadmin/work/object_detection/mmdetection3d/mmdet3d/models/detectors/single_stage_mono3d.py", line 91, in extract_feat x = self.backbone(batch_imgs) File "/home/xadmin/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, *kwargs) File "/home/xadmin/work/object_detection/mmdetection3d/mmdet3d/models/backbones/dla.py", line 443, in forward x = getattr(self, 'level{}'.format(i))(x) File "/home/xadmin/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(args, kwargs) File "/home/xadmin/work/object_detection/mmdetection3d/mmdet3d/models/backbones/dla.py", line 274, in forward x = self.tree2(x1, children=children) File "/home/xadmin/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, *kwargs) File "/home/xadmin/work/object_detection/mmdetection3d/mmdet3d/models/backbones/dla.py", line 271, in forward x = self.root(feat_list) File "/home/xadmin/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(args, **kwargs) File "/home/xadmin/work/object_detection/mmdetection3d/mmdet3d/models/backbones/dla.py", line 148, in forward x = self.conv(torch.cat(feat_list, 1)) RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 63 but got size 62 for tensor number 2 in the list.