Only batches of spatial targets supported error

Hello, I was following Fine-Tune a Semantic Segmentation Model with a Custom Dataset with my own dataset. In train.train() it gave me this error “only batches of spatial targets supported (3D tensors) but got targets of size: : [32, 512, 512, 3]”. I followed every steps from tutorial. how can I solve this?

1 Like

Faced the same thing today. Did you resolve it by any chance?
P.S. for adding more context to the question, I was following this guide transformers/examples/pytorch/semantic-segmentation at main · huggingface/transformers · GitHub

I had this problem too. To solve it i had to transform my mask images to grayscale, in order to delete the last dimention of the target array. Hope this helps!

1 Like