qubvel-org / segmentation_models.pytorch

Semantic segmentation models with 500+ pretrained convolutional and transformer-based backbones.
https://smp.readthedocs.io/
MIT License
9.52k stars 1.66k forks source link

PSPNet blank prediction result #385

Closed mesakh123 closed 3 years ago

mesakh123 commented 3 years ago

Sorry for my broke english

I was trying to train my model using Unet and PSPnet, the both models result of iou and loss scores are pretty, but when i tried to do prediction with my trained model, i found out that pspnet model prediction result is blank/empty, i was make sure to make the all parameters are correct. Since i was train the model of multi classes, both softmax2d and softmax activations were tried, the result still blank/empty. As mentioned on #176 , looks like activation by torch implementation as the main reason, When i used only one class with sigmoid activation, the PSPnet and Unet model works well. But when using softmax as activation, PSPnet can't predict correctly. If you have any suggestion, please comment, thank you.

my ground truth and prediction result (PSPNet) : image

the multiclass implementation similar with the code below : https://github.com/shirokawakita/multiclass-segmentation/blob/main/example_camvid_multiclassB_quita.ipynb

mesakh123 commented 3 years ago

After a week's research and trying many different repos of PSPNet with PyTorch, I found out the way to solve the problem. PSPNet maybe not good enough when the class with ground truth mask size is too small. Just ignore the background classes to calculate metrics and losses. Training with ignoring the background could lead to higher loss, even overfitting, depends on the dataset. On the other hand, UNet and Deeplabv3 work fine even with background channel classes. Also, PSPNet at least needs some activation such as sigmoid or softmax2d, so that the loss will not become negative (Happen only when I try to train with my custom PSPNet model, but I found out even without activation, this repo PSPNet model loss will not become negative, it only let my model prediction result to be a mask without a shape, just like a cloud). If you guys have found a way to train PSPNet without ignoring background class when dataset ground truth masks are small, please tell me, thank you. Also thank you for the great repo