-
Notifications
You must be signed in to change notification settings - Fork 12
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: 1only batches of spatial targets supported (3D tensors) but got targets of size: : [2, 512, 512, 3] #1
Comments
Please check if you have used my codes to load the data. Also please check if you have loaded the RGB labels or the index labels. |
If you prefer to use RGB labels, you can use the Colorls2Index function in RS_ST.py |
@ggsDing Thanks for your reply, I will try again. |
Hello, I also encounter the same problem as you met. Have you succeeded addressing this issue? |
@ggsDing Excuse me, I have tried adding the following codes: |
@ggsDing I have succeeded solving the issue mentioned above. The solution is modifying "RS_ST.py" file by adding 2 code lines at the last of function "read_RSimages": |
之前粘贴错了位置 感谢Evan1127-Lin提出的方法 注意一定要粘贴到read_RSimages的尾部部不是read_RSimages 内 for循环尾部 Colorls2Index这个函数的作用是把rgb的labels(512,512,3)转化为以类为标签(512,512)型数据 |
Glad that you found a solution. I have added codes for rgb labels in the updated RS_ST.py lines 93-94. |
我也遇到了这个问题,请问您解决了吗?如果解决了烦请赐教!我用的是不是RGB的标签。 |
For RGB labels please uncomment lines 93-94 in RS_ST.py |
您好,我尝试用您的代码训练的时候出现了如下问题。似乎是在计算loss的时候target应该是三维,但是debug进去发现label却还是四维,不知道该如何解决呢
Traceback (most recent call last):
File "/data/yuanyifeng/Bi-SRNet-main/train_SCD.py", line 238, in
main()
File "/data/yuanyifeng/Bi-SRNet-main/train_SCD.py", line 65, in main
train(train_loader, net, criterion, optimizer, scheduler, args, val_loader)
File "/data/yuanyifeng/Bi-SRNet-main/train_SCD.py", line 105, in train
loss_seg = criterion(outputs_A, labels_A) * 0.5 + criterion(outputs_B, labels_B) * 0.5
File "/home/yuanyifeng/anaconda3/envs/ASN3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/data/yuanyifeng/Bi-SRNet-main/utils/loss.py", line 13, in forward
return self.nll_loss(F.log_softmax(inputs, dim=1), targets)
File "/home/yuanyifeng/anaconda3/envs/ASN3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/yuanyifeng/anaconda3/envs/ASN3/lib/python3.7/site-packages/torch/nn/modules/loss.py", line 213, in forward
return F.nll_loss(input, target, weight=self.weight, ignore_index=self.ignore_index, reduction=self.reduction)
File "/home/yuanyifeng/anaconda3/envs/ASN3/lib/python3.7/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: : [2, 512, 512, 3]
The text was updated successfully, but these errors were encountered: