RuntimeError Traceback (most recent call last)
~\FashionMNIST_FlyAI - ResNet\main.py in <module>
106 y_train=y_train.long()
107
--> 108 loss = loss_fn(outputs, y_train)
109 loss_list.append(loss.item())
110 loss.backward()
d:\Anaconda3\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)
d:\Anaconda3\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target)
914 def forward(self, input, target):
915 return F.cross_entropy(input, target, weight=self.weight,
--> 916 ignore_index=self.ignore_index, reduction=self.reduction)
917
918
d:\Anaconda3\lib\site-packages\torch\nn\functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction)
2019 if size_average is not None or reduce is not None:
2020 reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 2021 return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
2022
2023
d:\Anaconda3\lib\site-packages\torch\nn\functional.py in log_softmax(input, dim, _stacklevel, dtype)
1315 dim = _get_softmax_dim('log_softmax', input.dim(), _stacklevel)
1316 if dtype is None:
-> 1317 ret = input.log_softmax(dim)
1318 else:
1319 ret = input.log_softmax(dim, dtype=dtype)
RuntimeError: "log_softmax_lastdim_kernel_impl" not implemented for 'Long'
解决方案:
y_train=y_train.long()