Skip to content

RuntimeError: The size of tensor a (784) must match the size of tensor b (28) at non-singleton dimension 3 #2

@aduk4u

Description

@aduk4u

RuntimeError Traceback (most recent call last)
in
28 engine.hooks['on_end_epoch'] = on_end_epoch
29
---> 30 engine.train(processor, get_iterator(True), maxepoch=NUM_EPOCHS, optimizer=optimizer)

E:\DeepLearning\envs\tensorflow_gpuenv\lib\site-packages\torchnet\engine\engine.py in train(self, network, iterator, maxepoch, optimizer)
61
62 state['optimizer'].zero_grad()
---> 63 state['optimizer'].step(closure)
64 self.hook('on_update', state)
65 state['t'] += 1

E:\DeepLearning\envs\tensorflow_gpuenv\lib\site-packages\torch\optim\adam.py in step(self, closure)
56 loss = None
57 if closure is not None:
---> 58 loss = closure()
59
60 for group in self.param_groups:

E:\DeepLearning\envs\tensorflow_gpuenv\lib\site-packages\torchnet\engine\engine.py in closure()
50
51 def closure():
---> 52 loss, output = state'network'
53 state['output'] = output
54 state['loss'] = loss

in processor(sample)
16 classes, reconstructions = model(data)
17
---> 18 loss = capsule_loss(data, labels, classes, reconstructions)
19 return loss, classes
20

E:\DeepLearning\envs\tensorflow_gpuenv\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)

in forward(self, images, labels, classes, reconstrunctions)
14 #images = images.view(reconstructions.size()[0], -1)
15
---> 16 reconstrunction_loss = self.reconstrunction_loss(reconstrunctions, images)
17
18 return (margin_loss + 0.0005 * reconstrunction_loss) / images.size(0)

E:\DeepLearning\envs\tensorflow_gpuenv\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)

E:\DeepLearning\envs\tensorflow_gpuenv\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target)
429
430 def forward(self, input, target):
--> 431 return F.mse_loss(input, target, reduction=self.reduction)
432
433

E:\DeepLearning\envs\tensorflow_gpuenv\lib\site-packages\torch\nn\functional.py in mse_loss(input, target, size_average, reduce, reduction)
2213 ret = torch.mean(ret) if reduction == 'mean' else torch.sum(ret)
2214 else:
-> 2215 expanded_input, expanded_target = torch.broadcast_tensors(input, target)
2216 ret = torch._C._nn.mse_loss(expanded_input, expanded_target, _Reduction.get_enum(reduction))
2217 return ret

E:\DeepLearning\envs\tensorflow_gpuenv\lib\site-packages\torch\functional.py in broadcast_tensors(*tensors)
50 [0, 1, 2]])
51 """
---> 52 return torch._C._VariableFunctions.broadcast_tensors(tensors)
53
54

RuntimeError: The size of tensor a (784) must match the size of tensor b (28) at non-singleton dimension 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions