Hi, i encountered an error when using THOP to count models with nn.AdaptiveAvgPool.
Here is the code:
`
import torch
from torch import nn
from thop import profile
from thop import clever_format
The result is:
`
Traceback (most recent call last):
File "D:/gitlab/playground/test_thop.py", line 20, in
flops, params = profile(model, inputs=(input_rand, ))
File "C:\Users.conda\envs\pytorch\lib\site-packages\thop\profile.py", line 188, in profile
model(inputs)
File "C:\Users.conda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(input, *kwargs)
File "D:/gitlab/playground/test_thop.py", line 15, in forward
return self.ConvNet(input)
File "C:\Users.conda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(input, *kwargs)
File "C:\Users.conda\envs\pytorch\lib\site-packages\torch\nn\modules\container.py", line 100, in forward
input = module(input)
File "C:\Users.conda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 552, in call
hook_result = hook(self, input, result)
File "C:\Users.conda\envs\pytorch\lib\site-packages\thop\vision\basic_hooks.py", line 92, in count_adap_avgpool
kernel = torch.DoubleTensor([(x[0].shape[2:])]) // torch.DoubleTensor(list((m.output_size,))).squeeze()
TypeError: must be real number, not NoneType
Process finished with exit code 1
`
And when i change
nn.AdaptiveAvgPool2d((None, 1)))
to
nn.AdaptiveAvgPool2d(1))
It works normally.
Hi, i encountered an error when using THOP to count models with nn.AdaptiveAvgPool. Here is the code: ` import torch from torch import nn from thop import profile from thop import clever_format
class toy_net(nn.Module):
model = toy_net(3) input_rand = torch.randn(1, 3, 224, 224) flops, params = profile(model, inputs=(input_rand, )) flops, params = clever_format([flops, params], '%.3f') print(flops, params) `
The result is: ` Traceback (most recent call last): File "D:/gitlab/playground/test_thop.py", line 20, in
flops, params = profile(model, inputs=(input_rand, ))
File "C:\Users.conda\envs\pytorch\lib\site-packages\thop\profile.py", line 188, in profile
model(inputs)
File "C:\Users.conda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(input, *kwargs)
File "D:/gitlab/playground/test_thop.py", line 15, in forward
return self.ConvNet(input)
File "C:\Users.conda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(input, *kwargs)
File "C:\Users.conda\envs\pytorch\lib\site-packages\torch\nn\modules\container.py", line 100, in forward
input = module(input)
File "C:\Users.conda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 552, in call
hook_result = hook(self, input, result)
File "C:\Users.conda\envs\pytorch\lib\site-packages\thop\vision\basic_hooks.py", line 92, in count_adap_avgpool
kernel = torch.DoubleTensor([(x[0].shape[2:])]) // torch.DoubleTensor(list((m.output_size,))).squeeze()
TypeError: must be real number, not NoneType
Process finished with exit code 1 `
And when i change
nn.AdaptiveAvgPool2d((None, 1)))
tonn.AdaptiveAvgPool2d(1))
It works normally.Looking forward to your reply.