-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'torch.Size' object has no attribute 'numel' #45
Comments
Upgrade your PyTorch and thop to lastest version. |
can you tell me which version for pytorch you use , and I use pytorch 0.4.0 and upgrade the thop, but meet the same problem. thank you a lot |
PyTorch version should be newer than 1.0 |
@sureJ0824, if you want to use pytorch 0.4.0 (which I needed to do as I was calculating flops for a legacy project), you can use dummy variable to get its number of elements. For example, in This essentially creates a same sized tensor of zeros, which then can be passed to numel(). This worked for me in pytorch=0.4.0 |
Traceback (most recent call last):
File "/home/gpu/chen/IMIXNet-PyTorch/code/get_Netpara.py", line 21, in
print("Torch:", thop.profile(torch.nn.Conv2d(1, 128, (3, 3)), inputs=(torch.zeros((1, 1, 128, 128)),), verbose=False)[0])
File "/home/gpu/.conda/envs/pytorch4/lib/python3.6/site-packages/thop/profile.py", line 92, in profile
model(*inputs)
File "/home/gpu/.conda/envs/pytorch4/lib/python3.6/site-packages/torch/nn/modules/module.py", line 479, in call
hook_result = hook(self, input, result)
File "/home/gpu/.conda/envs/pytorch4/lib/python3.6/site-packages/thop/count_hooks.py", line 20, in count_convNd
kernel_ops = m.weight.size()[2:].numel() # Kw x Kh
AttributeError: 'torch.Size' object has no attribute 'numel'
what‘s the problem here ?
the version of thop is wrong?
The text was updated successfully, but these errors were encountered: