Best method to change ground-truth labels (IndexError: Target {} is out of bounds)

Hi. I’m new to HF Transformers, so please excuse this simple question.

I’m working through the Fine-Tune a Semantic Segmentation Model with a Custom Dataset blog post and continue to receive the IndexError: Target 4 is out of bounds. error that many folks reference here. I understand that i need my labels to be 0-3 rather than 1-4, however i’m not sure how best to do this with my custom HF dataset that i created using

I’ve attempted to update the groundtruth labels using .map() and np.where(), as well as updating the label ids on

I’ve reconfigured the id2label.json to reflect 0-3 rather than 1-4. what am i missing here?


As a follow up to this post I want to share how I solved, as I assume beginners like myself will have a similar issue. When labelling your images using do not create a “background” label. Any object that doesn’t have a specific label leave blank. Once you push to HF, create a json file called label2id.json formatted with “no label” in the 0 index like this:

{“0”:“no-label”, “1”:“object1”, “2”:“object2”, “3”:“object3”}