ceshine/fast-neural-style

error of transformer network

Closed this issue · 2 comments


RuntimeError Traceback (most recent call last)
in ()
20 x = x.cuda()
21
---> 22 y = transformer(x)
23 xc = Variable(x.data, volatile=True)
24

/home/tai/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.pyc in call(self, *input, **kwargs)
222 for hook in self._forward_pre_hooks.values():
223 hook(self, input)
--> 224 result = self.forward(*input, **kwargs)
225 for hook in self._forward_hooks.values():
226 hook_result = hook(self, input, result)

/home/tai/cvpr18/fast-neural-style/transformer_net.py in forward(self, X)
35 def forward(self, X):
36 in_X = X
---> 37 y = self.relu(self.in1(self.conv1(in_X)))
38 y = self.relu(self.in2(self.conv2(y)))
39 y = self.relu(self.in3(self.conv3(y)))

/home/tai/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.pyc in call(self, *input, **kwargs)
222 for hook in self._forward_pre_hooks.values():
223 hook(self, input)
--> 224 result = self.forward(*input, **kwargs)
225 for hook in self._forward_hooks.values():
226 hook_result = hook(self, input, result)

/home/tai/cvpr18/fast-neural-style/transformer_net.py in forward(self, x)
131 t = x.view(x.size(0), x.size(1), n)
132 print (t.size())
--> 133 mean = torch.mean(t, 2).unsqueeze(2).expand_as(x)
134 # Calculate the biased var. torch.var returns unbiased var
135 var = torch.var(t, 2).unsqueeze(2).expand_as(x) * ((n - 1) / float(n))

/home/tai/anaconda2/lib/python2.7/site-packages/torch/autograd/variable.pyc in expand_as(self, tensor)
723
724 def expand_as(self, tensor):
--> 725 return Expand.apply(self, (tensor.size(),))
726
727 def t(self):

/home/tai/anaconda2/lib/python2.7/site-packages/torch/autograd/_functions/tensor.pyc in forward(ctx, i, new_size)
109 # tuple containing torch.Size or a list
110 def forward(ctx, i, new_size):
--> 111 result = i.expand(*new_size)
112 ctx.num_unsqueezed = result.dim() - i.dim()
113 ctx.expanded_dims = [dim for dim, (expanded, original)

RuntimeError: The expanded size of the tensor (256) must match the existing size (32) at non-singleton dimension 2. at /opt/conda/conda-bld/pytorch_1502006348621/work/torch/lib/THC/generic/THCTensor.c:323

I don't remember modifying this part of the code. Looks like it's a PyTorch version compatibility thing.

Checkout abhiskk/fast-neural-style@34edece#diff-5b76d6fcdadc119e60c8612ab8984309 and abhiskk/fast-neural-style#15 .

Don't really have time to update the code to the latest PyTorch and test it. Pull request welcome.