1adrianb / pytorch-estimate-flops

Estimate/count FLOPS for a given neural network using pytorch
https://www.adrianbulat.com
BSD 3-Clause "New" or "Revised" License
305 stars 22 forks source link

Error in Calculating Flops #6

Closed Allhailankurgupta closed 3 years ago

Allhailankurgupta commented 4 years ago

I was using this code below

class LeNet(nn.Module):
    def __init__(self):
        super(LeNet, self).__init__()
        self.conv1 = nn.Conv2d(1, 6, 5, padding=2)
        self.conv2 = nn.Conv2d(6, 16, 5)
        self.fc1   = nn.Linear(16*5*5, 120)
        self.fc2   = nn.Linear(120, 84)
        self.fc3   = nn.Linear(84, 10)

    def forward(self, x):
        x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))
        x = F.max_pool2d(F.relu(self.conv2(x)), (2, 2))
        x = x.view(-1, self.num_flat_features(x))
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x

    def num_flat_features(self, x):
        size = x.size()[1:]
        return np.prod(size)

new_model = LeNet()
new_model.to(DEVICE)
from pthflops import count_ops
false_inp = torch.rand(1,1,28,28).to(DEVICE)
# # Count the number of FLOPs
v = count_ops(new_model, false_inp)

and I got this error

Screenshot (41) It was working perfectly fine a few days back Could you please resolve this issue

1adrianb commented 4 years ago

Hi @Allhailankurgupta,

I tried running your code but I was unable to reproduce your error using pytorch 1.6/1.7 & pthflops 0.3.3 Could you please let me know what versions you are using?

Allhailankurgupta commented 4 years ago

I was running the code on colab so didn't pay that much attention to the versions But I checked I am using pytorch 1.7 And pthflops 0.3.3

Allhailankurgupta commented 4 years ago

I am facing the same error with the code given as illustration for resnet18

1adrianb commented 4 years ago

Unfortunately I am unable to reproduce it. I've also just triggered a build (https://travis-ci.com/github/1adrianb/pytorch-estimate-flops/builds/200193700) and as you can see the code run successfully.
Perhaps there is other code around that interferes?

Allhailankurgupta commented 4 years ago

It is kind of strange I just installed pthflops on my local machine It gave no error at all

But the exact same code is giving error on colab

Can you please check if the error comes on colab?

Allhailankurgupta commented 4 years ago

I just checked it is working with pytorch 1.6.0 but not with pytorch 1.7.0

1adrianb commented 3 years ago

Fixed in 0.3.4