Skip to content
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: only batches of spatial targets supported (3D tensors) but got targets of size: : [1, 215, 245, 3] #373

Open
40618233 opened this issue Jun 15, 2022 · 4 comments

Comments

@40618233
Copy link

Hi,
I have a problem with this place, can you help me?

image

@xhh12381
Copy link

I have the same question!

@MotsPassant
Copy link

I fixed this issue by making sure my masks files only had 1 channel and not 3.

With open cv it was :
img = cv2.imread('path/to/your/mask')
img_1_channel = img[:,:,0]
cv2.imwrite('path/to/new/mask', img_1_channel)

@xhh12381
Copy link

Thanks, I know exactly what the problem is too.
Pytorch nn.CrossEntropyLoss() requires input dimension is (N,C,H,W), target dimension is (N,H,W).
So the mask must be pre-processed as a single channel.
I learned this from the following blog, hope it can give you some help.
https://blog.csdn.net/Fcc_bd_stars/article/details/105158215

@milesial
Copy link
Owner

milesial commented Dec 6, 2022

Hi, can you try the latest master? I improved the support for custom datasets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants