segmentation_models.pytorch icon indicating copy to clipboard operation
segmentation_models.pytorch copied to clipboard

Output n_class is less than len(class_name) in training?

Open ymzlygw opened this issue 3 years ago • 5 comments

Hi, Thanks for your work. I used your code to train a multi-class segmentation task. I have 10 classes, but after training, the output mask just have 8 classes( using np.unique). Do you know how this happend? Thanks for your reply!

ymzlygw avatar Jul 07 '22 09:07 ymzlygw

I make sure that in dataset part, I input all 10 classes name. Note that the two classes( nose, eyebrow) that not be detected are more smaller than other class, is that the reason? My config is :

ENCODER = 'resnet34'
ENCODER_WEIGHTS = 'imagenet'
CLASSES = ['background','face', 'skin', 'clothes', 'hair', 'eye', 'eyeball', 'mouth', 'nose', 'eyebrow']
ACTIVATION = 'softmax2d' 

pr_mask = (pr_mask.squeeze().cpu().numpy().round()) # (10, 512, 512) But after np.argmax: vi_mask = np.argmax(pr_mask, axis=0) n = np.unique(vi_mask) # here just have 8 classes: [0,1,2,3,4,5,6,7] , not included 8,9

Or my config is not ok for segmentation of smaller part?

ymzlygw avatar Jul 07 '22 09:07 ymzlygw

I have a similar problem where my output has 4 classes whereas I expect 5. The training seems to be fine and the the IoU(during training) seems quite high as well. @ymzlygw Have you found a solution yet?

Arunavameister avatar Aug 03 '22 10:08 Arunavameister

@qubvel Have you ever encountered this problem?

Arunavameister avatar Aug 08 '22 11:08 Arunavameister

Your model does not predict some classes, don't see anything strange here suppose you have classes: car, road, sky, grass but on the picture you have only: road, grass and sky

in that case if model not predict "car" and number of predicted classes is less than number of total classes, and that's correct

qubvel avatar Aug 08 '22 11:08 qubvel

Thanks for the reply, what you are saying is obviously true but in my case I am doing inference only on the train set and I have a really low loss and a really high IoU which makes me think that I am obviously missing something. The model should atleast overfit. I dont expect you to debug the problem for me ofcourse, was just wondering if this has been encountered before.

Arunavameister avatar Aug 08 '22 11:08 Arunavameister

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Oct 08 '22 02:10 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Oct 15 '22 02:10 github-actions[bot]