Skip to content

use get_flops.py to calculate the FLOPs and parameter count of the Grounding DINO model #12419

@wzqisverystrong

Description

@wzqisverystrong

When I use get_flops.py to calculate the FLOPs and parameter count of the Grounding DINO model, I encountered the following error. How should I resolve it?

(openmmlab) root@autodl-container-b51142b66e-2d373801:~/autodl-tmp/mmdetection# python "/root/autodl-tmp/mmdetection/tools/analysis_tools/get_flops.py" "/root/autodl-tmp/mmdetection/configs/grounding_dino/grounding_dino_swin-t_finetune_8xb2_20e_cat.py"
/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torchvision/datapoints/init.py:12: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: pytorch/vision#6753, and you can also check out pytorch/vision#7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().
warnings.warn(_BETA_TRANSFORMS_WARNING)
/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torchvision/transforms/v2/init.py:54: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: pytorch/vision#6753, and you can also check out pytorch/vision#7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().
warnings.warn(_BETA_TRANSFORMS_WARNING)
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
Traceback (most recent call last):
File "/root/autodl-tmp/mmdetection/tools/analysis_tools/get_flops.py", line 140, in
main()
File "/root/autodl-tmp/mmdetection/tools/analysis_tools/get_flops.py", line 120, in main
result = inference(args, logger)
File "/root/autodl-tmp/mmdetection/tools/analysis_tools/get_flops.py", line 98, in inference
outputs = get_model_complexity_info(
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmengine/analysis/print_helper.py", line 748, in get_model_complexity_info
flops = flop_handler.total()
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmengine/analysis/jit_analysis.py", line 268, in total
stats = self._analyze()
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmengine/analysis/jit_analysis.py", line 570, in _analyze
graph = _get_scoped_trace_graph(self._model, self._inputs,
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmengine/analysis/jit_analysis.py", line 194, in _get_scoped_trace_graph
graph, _ = _get_trace_graph(module, inputs)
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/jit/_trace.py", line 1268, in _get_trace_graph
outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/jit/_trace.py", line 127, in forward
graph, out = torch._C._create_graph_by_tracing(
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/jit/_trace.py", line 118, in wrapper
outs.append(self.inner(*trace_inputs))
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1538, in _call_impl
result = forward_call(*args, **kwargs)
File "/root/miniconda3/envs/openmmlab/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1488, in _slow_forward
result = self.forward(*input, **kwargs)
File "/root/autodl-tmp/mmdetection/mmdet/models/detectors/base.py", line 96, in forward
return self._forward(inputs, data_samples)
File "/root/autodl-tmp/mmdetection/mmdet/models/detectors/base_detr.py", line 162, in _forward
head_inputs_dict = self.forward_transformer(img_feats,
File "/root/autodl-tmp/mmdetection/mmdet/models/detectors/grounding_dino.py", line 309, in forward_transformer
encoder_inputs_dict, decoder_inputs_dict = self.pre_transformer(
File "/root/autodl-tmp/mmdetection/mmdet/models/detectors/deformable_detr.py", line 152, in pre_transformer
assert batch_data_samples is not None
AssertionError

A placeholder for trackback.

Bug fix
If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions