MrYxJ / calculate-flops.pytorch

The calflops is designed to calculate FLOPs、MACs and Parameters in all various neural networks, such as Linear、 CNN、 RNN、 GCN、Transformer(Bert、LlaMA etc Large Language Model)
https://pypi.org/project/calflops/
MIT License
392 stars 14 forks source link

Cannot calculate EfficientNet #11

Closed QingyuLiu closed 1 month ago

QingyuLiu commented 8 months ago

I tried to calculate the FLOPs of EfficientNet, but there were some errors. Can you help me? File "/.conda/envs/test/lib/python3.8/site-packages/calflops/pytorch_ops.py", line 361, in newFunc flops, macs = funcFlopCompute(*args, **kwds) File "/.conda/envs/test/lib/python3.8/site-packages/calflops/pytorch_ops.py", line 113, in _conv_flops_compute output_dim = (input_dim + 2 * paddings[idx] - (dilations[idx] * TypeError: unsupported operand type(s) for //: 'int' and 'list'

weidel-p commented 1 month ago

I just tried the same and it worked without any issues. Here's my code:

from torchvision.models import efficientnet_b0
efficientnet = efficientnet_b0(weights='IMAGENET1K_V1')

batch_size = 1
input_shape = (batch_size, 3, 224, 224)
flops, macs, params = calculate_flops(model=efficientnet, 
                                      input_shape=input_shape,
                                      output_as_string=True,
                                      output_precision=4)
print("Efficientnet FLOPs:%s   MACs:%s   Params:%s \n" %(flops, macs, params))