flops-counter.pytorch icon indicating copy to clipboard operation
flops-counter.pytorch copied to clipboard

There was a bug with computing FLOPs in OpenPCdet

Open M0NSTERCOCO opened this issue 1 year ago • 1 comments

When I use this function to compute FLOPs in OpenPCdet framework, it didn't work well.

Can I use this function this way?

    macs, params = get_model_complexity_info(model, (1,), as_strings=True,
                                           print_per_layer_stat=False, verbose=True)
    print('{:<30}  {:<8}'.format('Computational complexity: ', macs))
    print('{:<30}  {:<8}'.format('Number of parameters: ', params))
Traceback (most recent call last):
  File "test.py", line 219, in <module>
    main()
  File "test.py", line 209, in main
    stat(model,(3,224,224))
  File "/opt/conda/lib/python3.7/site-packages/torchstat/statistics.py", line 71, in stat
    ms.show_report()
  File "/opt/conda/lib/python3.7/site-packages/torchstat/statistics.py", line 64, in show_report
    collected_nodes = self._analyze_model()
  File "/opt/conda/lib/python3.7/site-packages/torchstat/statistics.py", line 57, in _analyze_model
    model_hook = ModelHook(self._model, self._input_size)
  File "/opt/conda/lib/python3.7/site-packages/torchstat/model_hook.py", line 24, in __init__
    self._model(x)
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "../pcdet/models/detectors/IASSD.py", line 13, in forward
    batch_dict = cur_module(batch_dict)
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "../pcdet/models/backbones_3d/IASSD_backbone.py", line 143, in forward
    batch_size = batch_dict['batch_size']
IndexError: too many indices for tensor of dimension 4

M0NSTERCOCO avatar Jul 05 '23 12:07 M0NSTERCOCO

Hi. ptflops is designed to support 2d images as test input, so input shape (1,) seems to be not quite correct. Which input shape is consumed by your model? Whatever it is, you could use input_constructor parameter to create an input tensor of any shape: https://github.com/sovrasov/flops-counter.pytorch/issues/14. You can ignore the resolution parameter and hardcode the required shape in prepare_input()

sovrasov avatar Jul 13 '23 09:07 sovrasov