-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError #350
Comments
#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: |
https://blog.csdn.net/weixin_57203027/article/details/124148410?spm=1001.2014.3001.5501 |
emmm, I think she will not understand chinese ... |
No, I don't but I found the culprit code anyway. Thanks for your answers. |
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
train_net(net=net,
File "/home/ubuntu/workplace/Pytorch_Unet/train.py", line 93, in train_net
loss = criterion(masks_pred, true_masks)
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]
The text was updated successfully, but these errors were encountered: