Pytorch-UNet
Pytorch-UNet copied to clipboard
RuntimeError
How to resolve "RuntimeError: 1only batches of spatial targets supported (3D tensors) but got targets of size: : [1, 640, 959, 3]"
The details are as followed:
Epoch 1/5: 0%| | 0/4580 [00:08<?, ?img/s]
Traceback (most recent call last):
File "/home/ubuntu/workplace/Pytorch_Unet/train.py", line 185, in
File "/home/ubuntu/.conda/envs/gpu/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/ubuntu/.conda/envs/gpu/lib/python3.8/site-packages/torch/nn/modules/loss.py", line 961, in forward
return F.cross_entropy(input, target, weight=self.weight,
File "/home/ubuntu/.conda/envs/gpu/lib/python3.8/site-packages/torch/nn/functional.py", line 2468, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File "/home/ubuntu/.conda/envs/gpu/lib/python3.8/site-packages/torch/nn/functional.py", line 2266, in nll_loss
ret = torch._C._nn.nll_loss2d(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: 1only batches of spatial targets supported (3D tensors) but got targets of size: : [1, 640, 959, 3]
#123 again (occurs to me too)
Hi,targets of size: : [1, 640, 959, 3] should be [1, 640, 959].Input of 3 channels image should be 1 channel label like 0,1,2,3...
I don't understand, which part of the code is supposed to do that ?
the shape of your label is not matched. you should covert your current mask file into gray mode and get the shape like below:
img size: (4000, 2248) img shape: (2248, 4000)
which has only two channels.
I don't understand, which part of the code is supposed to do that ?
https://blog.csdn.net/weixin_57203027/article/details/124148410?spm=1001.2014.3001.5501 Use it to recreate your targets
emmm, I think she will not understand chinese ...
No, I don't but I found the culprit code anyway. Thanks for your answers.