Eric-mingjie / network-slimming

Network Slimming (Pytorch) (ICCV 2017)
MIT License
907 stars 214 forks source link

RuntimeError: Given weight of size [9, 3, 3, 3], expected bias to be 1-dimensional with 9 elements, but got bias of size [128] instead #2

Closed Coderx7 closed 6 years ago

Coderx7 commented 6 years ago

@Eric-mingjie : First of all thank you very much. When I try to prune my architecture(Simpnet) , half way through the pruning it crashes with the error : RuntimeError: Given weight of size [9, 3, 3, 3], expected bias to be 1-dimensional with 9 elements, but got bias of size [128] instead

What is wrong here? Can you kindly assist me in resolving this issue ? Here is the whole log :

=> loading checkpoint 'model_best_simpnet8.pth.tar'
=> loaded checkpoint 'model_best_simpnet8.pth.tar' (epoch 101) Prec1: 96.120000
simpnet8m(
  (features): Sequential(
    (0): Conv2d(3, 128, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.05, affine=True)
    (2): ReLU(inplace)
    (3): Dropout2d(p=0.02)
    (4): Conv2d(128, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (5): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (6): ReLU(inplace)
    (7): Dropout2d(p=0.05)
    (8): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (9): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (10): ReLU(inplace)
    (11): Dropout2d(p=0.05)
    (12): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (13): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (14): ReLU(inplace)
    (15): Dropout2d(p=0.05)
    (16): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (17): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (18): ReLU(inplace)
    (19): MaxPool2d(kernel_size=(2, 2), stride=(2, 2), dilation=(1, 1), ceil_mode=False)
    (20): Dropout2d(p=0.05)
    (21): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (22): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (23): ReLU(inplace)
    (24): Dropout2d(p=0.05)
    (25): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (26): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (27): ReLU(inplace)
    (28): Dropout2d(p=0.05)
    (29): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (30): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (31): ReLU(inplace)
    (32): Dropout2d(p=0.05)
    (33): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (34): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (35): ReLU(inplace)
    (36): Dropout2d(p=0.05)
    (37): Conv2d(182, 430, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (38): BatchNorm2d(430, eps=1e-05, momentum=0.05, affine=True)
    (39): ReLU(inplace)
    (40): MaxPool2d(kernel_size=(2, 2), stride=(2, 2), dilation=(1, 1), ceil_mode=False)
    (41): Dropout2d(p=0.1)
    (42): Conv2d(430, 430, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (43): BatchNorm2d(430, eps=1e-05, momentum=0.05, affine=True)
    (44): ReLU(inplace)
    (45): Dropout2d(p=0.1)
    (46): Conv2d(430, 455, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (47): BatchNorm2d(455, eps=1e-05, momentum=0.05, affine=True)
    (48): ReLU(inplace)
    (49): Dropout2d(p=0.1)
    (50): Conv2d(455, 600, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (51): BatchNorm2d(600, eps=1e-05, momentum=0.05, affine=True)
    (52): ReLU(inplace)
  )
  (classifier): Linear(in_features=600, out_features=10, bias=True)
)
layer index: 3   total channel: 128      remaining channel: 9
layer index: 7   total channel: 182      remaining channel: 17
layer index: 11      total channel: 182      remaining channel: 44
layer index: 15      total channel: 182      remaining channel: 34
layer index: 19      total channel: 182      remaining channel: 89
layer index: 24      total channel: 182      remaining channel: 128
layer index: 28      total channel: 182      remaining channel: 102
layer index: 32      total channel: 182      remaining channel: 86
layer index: 36      total channel: 182      remaining channel: 95
layer index: 40      total channel: 430      remaining channel: 9
layer index: 45      total channel: 430      remaining channel: 89
layer index: 49      total channel: 455      remaining channel: 8
layer index: 53      total channel: 600      remaining channel: 339
Pre-processing Successful!
Files already downloaded and verified

Test set: Accuracy: 1000/10000 (10.0%)

[9, 17, 44, 34, 89, 'M', 128, 102, 86, 95, 9, 'M', 89, 8, 339]
In shape: 3, Out shape 9.
In shape: 9, Out shape 17.
In shape: 17, Out shape 44.
In shape: 44, Out shape 34.
In shape: 34, Out shape 89.
In shape: 89, Out shape 128.
In shape: 128, Out shape 102.
In shape: 102, Out shape 86.
In shape: 86, Out shape 95.
In shape: 95, Out shape 9.
In shape: 9, Out shape 89.
In shape: 89, Out shape 8.
In shape: 8, Out shape 339.
simpnet8m(
  (features): Sequential(
    (0): Conv2d(3, 128, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.05, affine=True)
    (2): ReLU(inplace)
    (3): Dropout2d(p=0.02)
    (4): Conv2d(128, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (5): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (6): ReLU(inplace)
    (7): Dropout2d(p=0.05)
    (8): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (9): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (10): ReLU(inplace)
    (11): Dropout2d(p=0.05)
    (12): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (13): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (14): ReLU(inplace)
    (15): Dropout2d(p=0.05)
    (16): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (17): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (18): ReLU(inplace)
    (19): MaxPool2d(kernel_size=(2, 2), stride=(2, 2), dilation=(1, 1), ceil_mode=False)
    (20): Dropout2d(p=0.05)
    (21): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (22): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (23): ReLU(inplace)
    (24): Dropout2d(p=0.05)
    (25): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (26): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (27): ReLU(inplace)
    (28): Dropout2d(p=0.05)
    (29): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (30): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (31): ReLU(inplace)
    (32): Dropout2d(p=0.05)
    (33): Conv2d(182, 182, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (34): BatchNorm2d(182, eps=1e-05, momentum=0.05, affine=True)
    (35): ReLU(inplace)
    (36): Dropout2d(p=0.05)
    (37): Conv2d(182, 430, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (38): BatchNorm2d(430, eps=1e-05, momentum=0.05, affine=True)
    (39): ReLU(inplace)
    (40): MaxPool2d(kernel_size=(2, 2), stride=(2, 2), dilation=(1, 1), ceil_mode=False)
    (41): Dropout2d(p=0.1)
    (42): Conv2d(430, 430, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (43): BatchNorm2d(430, eps=1e-05, momentum=0.05, affine=True)
    (44): ReLU(inplace)
    (45): Dropout2d(p=0.1)
    (46): Conv2d(430, 455, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (47): BatchNorm2d(455, eps=1e-05, momentum=0.05, affine=True)
    (48): ReLU(inplace)
    (49): Dropout2d(p=0.1)
    (50): Conv2d(455, 600, kernel_size=[3, 3], stride=(1, 1), padding=(1, 1))
    (51): BatchNorm2d(600, eps=1e-05, momentum=0.05, affine=True)
    (52): ReLU(inplace)
  )
  (classifier): Linear(in_features=600, out_features=10, bias=True)
)
Files already downloaded and verified
Traceback (most recent call last):
  File "vggprune.py", line 213, in <module>
    test(model)
  File "vggprune.py", line 150, in test
    output = model(data)
  File "/media/hossein/0D8910C60D8910C6/pytorch3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/media/hossein/tmpstore/Network_slimming/network-slimming/models/simpnet8m.py", line 49, in forward
    out = self.features(x)
  File "/media/hossein/0D8910C60D8910C6/pytorch3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/media/hossein/0D8910C60D8910C6/pytorch3/lib/python3.6/site-packages/torch/nn/modules/container.py", line 67, in forward
    input = module(input)
  File "/media/hossein/0D8910C60D8910C6/pytorch3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/media/hossein/0D8910C60D8910C6/pytorch3/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 282, in forward
    self.padding, self.dilation, self.groups)
  File "/media/hossein/0D8910C60D8910C6/pytorch3/lib/python3.6/site-packages/torch/nn/functional.py", line 90, in conv2d
    return f(input, weight, bias)
RuntimeError: Given weight of size [9, 3, 3, 3], expected bias to be 1-dimensional with 9 elements, but got bias of size [128] instead

Thanks a lot

Coderx7 commented 6 years ago

Thanks to God, I found the issue. in each step the model is altered and a new instance of the model is reinstantiated and the pruning goes on. I had to also add the capability of instantiating the model based on an input cfg. (like the way vgg is constructed) when I did that everything started to work flawlessly. Thanks again