pytorch-cifar
pytorch-cifar copied to clipboard
The problem of 'shufflenet.py'
Hello, when I run the 'shufflenet.py', it comes to this bug:
"Traceback (most recent call last): File "/home/w/Documents/code/cifar10/practice/models/shufflenet.py", line 218, in test() File "/home/w/Documents/code/cifar10/practice/models/shufflenet.py", line 214, in test net = ShuffleNetG2() File "/home/w/Documents/code/cifar10/practice/models/shufflenet.py", line 202, in ShuffleNetG2 return ShuffleNet(cfg) File "/home/w/Documents/code/cifar10/practice/models/shufflenet.py", line 171, in init self.layer1 = self._make_layer(out_planes[0], num_blocks[0], groups) File "/home/w/Documents/code/cifar10/practice/models/shufflenet.py", line 181, in _make_layer layers.append(Bottleneck(self.in_planes, out_planes-cat_planes, stride=stride, groups=groups)) File "/home/w/Documents/code/cifar10/practice/models/shufflenet.py", line 139, in init self.conv1 = nn.Conv2d(in_planes, mid_planes, kernel_size=1, groups=g, bias=False) File "/home/w/.local/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 297, in init False, _pair(0), groups, bias) File "/home/w/.local/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 33, in init out_channels, in_channels // groups, *kernel_size)) TypeError: new() received an invalid combination of arguments - got (float, int, int, int), but expected one of:
(torch.device device)
(tuple of ints size, torch.device device)
(torch.Storage storage)
(Tensor other)
(object data, torch.device device)"
Do you meet the same problems? I wonder if you could help me solve this bug? Thanks a lot!
I know the reason. in 27 line, it should be 'int (mid_planes = out_planes/4)'
However, I couldn't understand the shuffle operation in the 'ShuffleBlock' absolutely, I hope someone could discuss this with me.
Let's say you want to shuffle [1, 2, 3, 4, 5, 6] into [1, 4, 2, 5, 3, 6], just do: torch.Tensor([1, 2, 3, 4, 5, 6]).view(2, 3).permute(1, 0).contiguous().view(6)
To shuffle it into [1, 3, 5, 2, 4, 6], similarly do: torch.Tensor([1, 2, 3, 4, 5, 6]).view(3, 2).permute(1, 0).contiguous().view(6)
Can you solved it? I have the same problem...
I have the same problem. --
As @flexibility2 mentioned in his reply
you should change the 27th line in shufflenet.py from
mid_planes = out_planes/4 --> cause float type value
to
mid_planes = int(out_planes/4) --> force to integer
`class Bottleneck(nn.Module): def init(self, in_planes, out_planes, stride, groups):
mid_planes = int(out_planes/4)`