sksq96 / pytorch-summary

Model summary in PyTorch similar to `model.summary()` in Keras
MIT License
4.01k stars 412 forks source link

RuntimeWarning: overflow encountered in long_scalars #158

Open HamaguchiKazuki opened 3 years ago

HamaguchiKazuki commented 3 years ago

An overflow occurred when I ran the following code. This is why the model estimation, including batch size, is not successful.

 import torch
 from torchvision import models
 from torchsummary import summary

 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 vgg = models.vgg16().to(device)

 summary(vgg, (3, 600, 600), 20)

The output result is this.

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
            Conv2d-1         [20, 64, 600, 600]           1,792
              ReLU-2         [20, 64, 600, 600]               0
            Conv2d-3         [20, 64, 600, 600]          36,928
              ReLU-4         [20, 64, 600, 600]               0
         MaxPool2d-5         [20, 64, 300, 300]               0
torchsummary.py:93: RuntimeWarning: overflow encountered in long_scalars
  total_output += np.prod(summary[layer]["output_shape"])
            Conv2d-6        [20, 128, 300, 300]          73,856
              ReLU-7        [20, 128, 300, 300]               0
            Conv2d-8        [20, 128, 300, 300]         147,584
              ReLU-9        [20, 128, 300, 300]               0
        MaxPool2d-10        [20, 128, 150, 150]               0
           Conv2d-11        [20, 256, 150, 150]         295,168
             ReLU-12        [20, 256, 150, 150]               0
           Conv2d-13        [20, 256, 150, 150]         590,080
             ReLU-14        [20, 256, 150, 150]               0
           Conv2d-15        [20, 256, 150, 150]         590,080
             ReLU-16        [20, 256, 150, 150]               0
        MaxPool2d-17          [20, 256, 75, 75]               0
           Conv2d-18          [20, 512, 75, 75]       1,180,160
             ReLU-19          [20, 512, 75, 75]               0
           Conv2d-20          [20, 512, 75, 75]       2,359,808
             ReLU-21          [20, 512, 75, 75]               0
           Conv2d-22          [20, 512, 75, 75]       2,359,808
             ReLU-23          [20, 512, 75, 75]               0
        MaxPool2d-24          [20, 512, 37, 37]               0
           Conv2d-25          [20, 512, 37, 37]       2,359,808
             ReLU-26          [20, 512, 37, 37]               0
           Conv2d-27          [20, 512, 37, 37]       2,359,808
             ReLU-28          [20, 512, 37, 37]               0
           Conv2d-29          [20, 512, 37, 37]       2,359,808
             ReLU-30          [20, 512, 37, 37]               0
        MaxPool2d-31          [20, 512, 18, 18]               0
AdaptiveAvgPool2d-32            [20, 512, 7, 7]               0
           Linear-33                 [20, 4096]     102,764,544
             ReLU-34                 [20, 4096]               0
          Dropout-35                 [20, 4096]               0
           Linear-36                 [20, 4096]      16,781,312
             ReLU-37                 [20, 4096]               0
          Dropout-38                 [20, 4096]               0
           Linear-39                 [20, 1000]       4,097,000
================================================================
Total params: 138,357,544
Trainable params: 138,357,544
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 82.40
Forward/backward pass size (MB): 1444.29
Params size (MB): 527.79
Estimated Total Size (MB): 2054.48
----------------------------------------------------------------

Development Environment

cainmagi commented 3 years ago

I have fixed this problem in #165.