-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 #123
Comments
Hi, you can't really one-hot encode your masks in a png image. You could however assign one color to each mask (e.g. (10, 0, 0) for the first class, (20, 0, 0) for the second one, ... ), and then modify the preprocessing function of the Dataset class to modify these colors into one-hot vectors after loading the masks. |
Ok thanks for your quick response; so I have to modify your code to get it working with multiple classes, didn't know that. Will take some time here to try and check. |
Hi, I'm having the same issue with multiclass segmentation. My masks are grayscale PNGs in which every class has his own grayscale value. @alkeksibusiii Have you found a solution? Thank you in advance, |
@tim-vdl I think you don't need to create a batch dimension, as this is the job of the Dataloader |
Hi, I've found a solution for my problem. It turns out you don't need the one-hot encoding (CxHxW). I could just use my masks as they are: HxW where the pixel values range between 0 and C-1. I had to change some other parts in the code, however, to make it work:
You can checkout my fork here @alkeksibusiii maybe this works for you as well. |
Did you have to make any changes to your predict.py file in order for it to work? |
hello,thanks for your slolution. It works. But I get another problem: File "train.py", line 180, in my mask image is single channel,the pixel values range between 0 and C-1 |
Closing, as this issue is now outdated after the recent code refactor. |
Hello Alex,
when trying to train an 8 class u-net model with 86 images, soon after start I receive an error message (below):
INFO: Network:
3 input channels
8 output channels (classes)
Bilinear upscaling
INFO: Creating dataset with 86 examples
INFO: Starting training:
Epochs: 5
Batch size: 1
Learning rate: 0.1
Training size: 78
Validation size: 8
Checkpoints: True
Device: cuda
Images scaling: 0.5
Epoch 1/5: 0%
RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of size: : [1, 1, 384, 512]
I think it is related due to my uncertainty how to encode the masks correctly - currently placed
as one png per training image in the masks directory. But how to "one-hot-encode" 8 different classes in one png file ? Do the color values have to be like 1,2,4,8,16,32 .. or do I have to
modify the dataset loader respectively ?
The text was updated successfully, but these errors were encountered: