RuntimeError: mat1 dim 1 must match mat2 dim 0
wwdok opened this issue · comments
Hi, @bentrevett, I met another issue in running the colab of Alexnet.
My amount of classe is 4, so i modified the OUTPUT_DIM = 4
only without anything else changed, then when colab run to lrs, losses = lr_finder.range_test(train_iterator, END_LR, NUM_ITER)
, it happened following error:
RuntimeError Traceback (most recent call last)
<ipython-input-39-937508221c7d> in <module>()
3
4 lr_finder = LRFinder(model, optimizer, criterion, device)
----> 5 lrs, losses = lr_finder.range_test(train_iterator, END_LR, NUM_ITER)
8 frames
<ipython-input-37-f3b559f5a5f9> in range_test(self, iterator, end_lr, num_iter, smooth_f, diverge_th)
22 for iteration in range(num_iter):
23
---> 24 loss = self._train_batch(iterator)
25
26 lrs.append(lr_scheduler.get_last_lr()[0])
<ipython-input-37-f3b559f5a5f9> in _train_batch(self, iterator)
58 y = y.to(self.device)
59
---> 60 y_pred, _ = self.model(x)
61
62 loss = self.criterion(y_pred, y)
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
<ipython-input-32-1ea0008653c6> in forward(self, x)
32 x = self.features(x)
33 h = x.view(x.shape[0], -1)
---> 34 x = self.classifier(h)
35 return x, h
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py in forward(self, input)
115 def forward(self, input):
116 for module in self:
--> 117 input = module(input)
118 return input
119
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/linear.py in forward(self, input)
91
92 def forward(self, input: Tensor) -> Tensor:
---> 93 return F.linear(input, self.weight, self.bias)
94
95 def extra_repr(self) -> str:
/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in linear(input, weight, bias)
1688 if input.dim() == 2 and bias is not None:
1689 # fused op is marginally faster
-> 1690 ret = torch.addmm(bias, input, weight.t())
1691 else:
1692 output = input.matmul(weight.t())
RuntimeError: mat1 dim 1 must match mat2 dim 0
Would you please give me some tips to debug it ? Thanks !
Hi @wwdok, sorry it took a while to get back to you. I'm unable to re-create your issue. What sizes images are used in your dataset?
I also guess it maybe related with dataset, the image sizes are veried, the dataset is this.
To reproduce this issue, this is the colab notebook