# Only batches of spatial targets supported error

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fonly-batches-of-spatial-targets-supported-error%2F28757%3E%5C
**Category:** 🤗Transformers\
**Created:** [January 1, 2023, 10:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fonly-batches-of-spatial-targets-supported-error%2F28757 "2023-01-01T22:54:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FahriBilici](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/fahribilici/32/5950_2.png) [@FahriBilici](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FFahriBilici)%5C
**Post date:** [January 1, 2023, 10:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fonly-batches-of-spatial-targets-supported-error%2F28757%2F1 "2023-01-01T22:54:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![nullkatar](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@nullkatar](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnullkatar)%5C
**Post date:** [February 7, 2023, 8:01am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fonly-batches-of-spatial-targets-supported-error%2F28757%2F2 "2023-02-07T08:01:24Z")

</div>

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](https://github.com/huggingface/transformers/tree/main/examples/pytorch/semantic-segmentation#note-on-custom-data)

---

<div class="post-metadata">

**Author:** ![saulls](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@saulls](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsaulls)%5C
**Post date:** [March 8, 2023, 3:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fonly-batches-of-spatial-targets-supported-error%2F28757%2F3 "2023-03-08T15:25:37Z")

</div>

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!
