pytorch / pytorch/vision

num_classes in segmentation examle

Open
#5,822 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

Hi, I have some questions about num_classes in the segmentation example.

Since the pretraining classes is 21, should the target mask be integers from 0 to 21, where 0 is the background?

If so, my next question is do we need to compute loss over 0 (background)? I think generally background pixels is the majority, will it hurt the model so that the model would always predict 0 (background) as the majority? Or should we ignore background label by passing ignore_index=0 in cross entropy loss? I see that here we are ignoring index 255, but I am not sure where 255 comes from.

Thanks! Any input is highly appreciated!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the references/segmentation example and references/segmentation/train.py at the ignore_index=255 usage. Trace how num_classes, target masks, and the loss are defined, then compare the example's behavior with the linked pretrained segmentation classes. Done means the example clearly documents the class and background-label conventions and explains the source of 255.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision, machine-learning
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.