DeepLabV3Plus-Pytorch icon indicating copy to clipboard operation
DeepLabV3Plus-Pytorch copied to clipboard

question about ignore_index 255?

Open hezichuanqi opened this issue 4 years ago • 6 comments

hi, i have a question about the ignore index 255 when i trainning the dataset of citysacpes. while training, the background will be set to label 255, and in the loss function it will not be calculated. So, my questions is: when i test the new image, it will predict a 255 label? in the cityscapes.py, the decode_target function can transfer 255 to 19?? Looking forward your answer, Thank you!

hezichuanqi avatar Nov 23 '21 05:11 hezichuanqi

Hi @hezichuanqi, ignoring backgroud pixels is a common practice in scene parsing. These background pixels are typically outliers which can not appropriately annotated.

So, my questions is: when i test the new image, it will predict a 255 label?

No. During inference, the network will predict a [0, 18] label for all pixels. And during evaluation, background pixels with label 255 will be masked and ignored.

in the cityscapes.py, the decode_target function can transfer 255 to 19??

The decode_fn transfers 255 to 19 to visualize the groud truth.

VainF avatar Nov 23 '21 06:11 VainF

Thank you very much for your answers.I'm still have a question: ------During inference, the network will predict a [0, 18] label for all pixels. I can understand the class number is 19. but, if we want to inference a new picture, how those pixels belong to the background can be recognized.In other words, the backgound pixels doesn't belong to [0,18] labels.

hezichuanqi avatar Nov 24 '21 05:11 hezichuanqi

The model will output the most likely class of [0, 18], that's why you have the following codes

https://github.com/VainF/DeepLabV3Plus-Pytorch/blob/3f84cd27d5e845c9d92aed6639b0685ef22ed964/main.py#L174

Since the background was never learned, the probabilities (namely the logits) of the background class should be relatively small.

bb846 avatar Nov 30 '21 09:11 bb846

Hi, there, what if my background class is 0, but others is from 1 to 13? How to ignore the background prediction? because at the test part, I got the background predicted as some else foreground class like 12. It has disturbed me for such long time. Thanks a lot.

DISAPPEARED13 avatar Jan 14 '23 06:01 DISAPPEARED13

Hi, there, what if my background class is 0, but others is from 1 to 13? How to ignore the background prediction? because at the test part, I got the background predicted as some else foreground class like 12. It has disturbed me for such long time. Thanks a lot.

Don't quite understand your question. If you want to neglect class 0 during training, you can set ignore_index=0 for the loss. Or if you want it during validating, then just use something like

preds = outputs.detach()[1:].max(dim=1)[1].cpu().numpy()

Hope this helps.

bb846 avatar Feb 02 '23 08:02 bb846

Hi, there, what if my background class is 0, but others is from 1 to 13? How to ignore the background prediction? because at the test part, I got the background predicted as some else foreground class like 12. It has disturbed me for such long time. Thanks a lot.

Don't quite understand your question. If you want to neglect class 0 during training, you can set ignore_index=0 for the loss. Or if you want it during validating, then just use something like

preds = outputs.detach()[1:].max(dim=1)[1].cpu().numpy()

Hope this helps.

I wondered if setting the ignorable index is necessary, cause my code goes wrong with a bug. Now got fixed, but the performance is not that good. Thanks a lot!

DISAPPEARED13 avatar Feb 02 '23 13:02 DISAPPEARED13