# How to separate predictions map to create id2label.json

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%3E%5C
**Category:** Beginners\
**Created:** [December 15, 2024, 3:20am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146 "2024-12-15T03:20:19Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![seand0101](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/seand0101/32/35961_2.png) [@seand0101](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fseand0101)%5C
**Post date:** [December 15, 2024, 3:20am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F1 "2024-12-15T03:20:19Z")

</div>

Dear @John6666 and other community members

Since using self-made mask didn’t work last time, said I need ground-truth image for the model to know what I mean by river area, how should I separate the “river” from the rest of tensors to make the `id2label.json`? Or did I do it the other way around by training the masked image?

The example `semantic_prediction[0]`can spit out a tensor but I don’t think it means anything since matplotlib.pyplot.imshow(semantic\_prediction[0]) can’t show anything

I’m currently making maps for each image, but so far the prediction are weirdly similar for different images, do their information differences negligible or should I do some normalization to make them seen?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [December 15, 2024, 3:31am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F2 "2024-12-15T03:31:05Z")

</div>

I’ve never tried segmentation before…  
I collected some links that might be useful if you’re trying to do segmentation with Hugging Face.

> [@How do I create a Image Segmentation Dataset](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-i-create-a-image-segmentation-dataset%2F23123%2F15)%3A
>
> I was able to solve that part by doing this: feature\_extractor = SegformerFeatureExtractor(do\_resize=False, do\_normalize=False) But I am getting another error [image] Not sure why this is coming

> **[Mask Generation](https://huggingface.co/docs/transformers/main/en/tasks/mask_generation)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> **[Fine-Tune a Semantic Segmentation Model with a Custom Dataset](https://huggingface.co/blog/fine-tune-segformer)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![seand0101](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/seand0101/32/35961_2.png) [@seand0101](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fseand0101)%5C
**Post date:** [December 15, 2024, 3:37am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F3 "2024-12-15T03:37:54Z")

</div>

Thanks I’ll check them out, sorry for keep asking you while you keep highlighting never done segmentation before, almost ran out of people to ask and I don’t know exactly what I’m trying to do

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [December 15, 2024, 3:43am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F4 "2024-12-15T03:43:47Z")

</div>

No problem.😀 It’s also a learning experience for me. However, if you want to ask someone who knows a lot about AI models, it may be quicker to use HF Discord.  
If you’re lucky, HF staff or someone knowledgeable will pass by the forum…

---

<div class="post-metadata">

**Author:** ![seand0101](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/seand0101/32/35961_2.png) [@seand0101](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fseand0101)%5C
**Post date:** [December 15, 2024, 3:52am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F5 "2024-12-15T03:52:16Z")

</div>

The thing is tagging you has been the most dependable results I had so far even compared to discord forum,

Read the forum, it’s exactly what I’m looking for, will try it first then ask again if I need some clarification; maybe there maybe here, thanks John.

---

<div class="post-metadata">

**Author:** ![seand0101](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/seand0101/32/35961_2.png) [@seand0101](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fseand0101)%5C
**Post date:** [December 15, 2024, 7:41am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F6 "2024-12-15T07:41:45Z")

</div>

@John6666 Okay so I get these

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/3/2/3219e6151b7261c8f14051dc0c27f8d83bee6d23.png)

and this

```auto
[{'score': None,
  'label': 'wall',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'building',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'sky',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'tree',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'mountain',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'water',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'fence',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'rock',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'signboard',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'bridge',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'boat',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>},
 {'score': None,
  'label': 'pier',
  'mask': <PIL.Image.Image image mode=L size=1080x1080>}]

```

Is this what I move to here?

```auto

import datasets
import glob

IMAGES = glob.glob("D:\cropped_image_1080x1080\img_0")
SEG_MAPS = glob.glob("D:.\img_0.jpg")

dataset = datasets.Dataset.from_dict({
    "image": IMAGES,
    "label": SEG_MAPS
},
features=datasets.Features({
    "image":datasets.Image(),
    "label":datasets.Image()
                            })
)

```

I still don’t get how I move the fifth member of this `pipeline` that I got from here

```auto
from transformers import pipeline

semantic_segmentation = pipeline("image-segmentation", "shi-labs/oneformer_ade20k_swin_large")

```

to id2label, do I need to label it as implied in [here](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-set-useful-id2label-and-label2id-in-config-json-using-trainer%2F43545%2F2)%3F

---

<div class="post-metadata">

**Author:** ![seand0101](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/seand0101/32/35961_2.png) [@seand0101](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fseand0101)%5C
**Post date:** [December 15, 2024, 7:51am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F7 "2024-12-15T07:51:11Z")

</div>

How do this work for 8725 images that might have different scores, I still don’t understand the concept behind id2label and pretrained model…

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [December 15, 2024, 7:54am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F8 "2024-12-15T07:54:27Z")

</div>

Oh, it seems to have worked out well. No matter which model you use, it’s better to refer to the author’s model card rather than the automatically generated upper part of the HF.  
For this model, it would look something like the link below.  
The format required will vary depending on the model, but as long as you make the dataset in a way that is easy for you to use, that should be fine.  
Uploading and downloading to HF’s dataset repo and organizing large amounts of data is the forte of the datasets library.  
However, there may be a recommended dataset format for HF Trainer.

In the end, it’s the same thing that we need to write a few lines of Python before passing it to the model.😅 I don’t think you need labels for use cases that don’t require labels. I don’t think you need labels for segmentation.

> **[shi-labs/oneformer\_ade20k\_swin\_large · Hugging Face](https://huggingface.co/shi-labs/oneformer_ade20k_swin_large#how-to-use)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![seand0101](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/seand0101/32/35961_2.png) [@seand0101](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fseand0101)%5C
**Post date:** [December 15, 2024, 7:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F9 "2024-12-15T07:56:07Z")

</div>

Then do I only need the mask for training? Every guide I found use id2label though, I understand that this is semantic segmentation so not only it is segmented but its also labelled as something

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [December 15, 2024, 7:57am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F10 "2024-12-15T07:57:12Z")

</div>

Pipelines are convenient, but they perform complex processing internally, so they are like black boxes.  
It might be better to try doing it manually at first. The method on the model explanation page is the most general-purpose method.

> Then do I only need the mask for training?

Yes.

> semantic segmentation so not only it is segmented but its also labelled as something

If that’s the case, you may need to label the data set…  
It’s difficult to create data that doesn’t exist. Only a large AI or a human being could do it.

---

<div class="post-metadata">

**Author:** ![seand0101](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/seand0101/32/35961_2.png) [@seand0101](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fseand0101)%5C
**Post date:** [December 15, 2024, 8:01am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F11 "2024-12-15T08:01:37Z")

</div>

so I need to id2label for my mask, what should I do with each weight? Sorry I’m still confused and don’t know how to explain it tbh…

I know I need these weights for some fine tuning but I don’t know where to store it as. Or if I train my mask I got from applying the model to my picture is it what I need?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [December 15, 2024, 8:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F12 "2024-12-15T08:06:20Z")

</div>

Even if you have to create your own data in the end, semantic segmentation itself is an existing task.  
I think there are already working datasets for semantic segmentation that you can use as samples. If you can imitate that structure, it will be the quickest.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [December 15, 2024, 8:09am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F13 "2024-12-15T08:09:26Z")

</div>

It seems like you need a mask that uses multiple colors or shades to semantic segmentation. Your mask is black and white, 0 or 1, so it should be usable for two types of classification. I think it should be usable for whether or not it’s a river.

> **[Google Colab](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/semantic_segmentation.ipynb)**

> **[huggingface/semantic-segmentation-test-sample · Datasets at Hugging Face](https://huggingface.co/datasets/huggingface/semantic-segmentation-test-sample)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> **[moritzef/mapillary\_vistas\_semantic\_edges\_and\_segmentation · Datasets at...](https://huggingface.co/datasets/moritzef/mapillary_vistas_semantic_edges_and_segmentation)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

by json file like this (or opposite?):

```json
{"0": "not river", "1": "river"}

```

With HF, JSON files that have been carelessly left lying around are sometimes configuration files with fixed file names…😅

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsystem)%5C
**Post date:** [December 15, 2024, 8:09pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-separate-predictions-map-to-create-id2label-json%2F131146%2F14 "2024-12-15T20:09:29Z")

</div>

Closed on December 15, 2024, 8:09pm UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
