Error in building an inception block

I’m trying to implement an inception block to train on, but I seem to be getting an error when I concatenate all the outputs from the convolutional layers.

The code is here:

When I run my training, I get this error


RuntimeError Traceback (most recent call last)
in ()
12
13 # forward + backward + optimize
—> 14 outputs = net(inputs)
15 loss = criterion(outputs, labels)
16 loss.backward()

~/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
489 result = self._slow_forward(*input, **kwargs)
490 else:
–> 491 result = self.forward(*input, **kwargs)
492 for hook in self._forward_hooks.values():
493 hook_result = hook(self, input, result)

in forward(self, x)
33 x3 = self.conv_5(x)
34 x4 = self.max_pool_conv_1(x)
—> 35 x = torch.cat([x1,x2,x3,x4], 1) # concatenate all layers
36 x = x.view(x.size(0), -1) # flatten
37 x = F.relu(self.fc1(x))

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 32 and 10 in dimension 2 at /Users/soumith/code/builder/wheel/pytorch-src/aten/src/TH/generic/THTensorMath.c:3586

It looks like it has something to do with the torch.cat line. Could anyone offer any help?

Print the sizes of x1, … x4. Likely, x4 is smaller than the others in the W,H dimensions, that wouldn’t work.

It’s a good idea to implement models from scratch to learn, but you could peek e.g. at the inception model in torchvision if you are stuck.

Best regards

Thomas