oikosohn / compound-loss-pytorch

Compound loss for PyTorch
Apache License 2.0
45 stars 9 forks source link

multi-class AsymmetricUnifiedFocalLoss #1

Open tomanick opened 2 years ago

tomanick commented 2 years ago

Thanks for your sharing! If I want to use multi-class AsymmetricUnifiedFocalLoss, is current version available?

oikosohn commented 2 years ago

I think you can. Because official code also supports multi-class. I just converted the official repository code into a PyTorch. But I did not test. so If you can't, please let me know.

Sean-asc commented 2 years ago

@tomanick Does AsymmetricUnifiedFocalLoss works fine on multi-class? I tried, but got some unexpected errors.

Sean-asc commented 2 years ago

Calculate losses separately for each class, only enhancing foreground class

    back_dice = (1-dice_class[:,0]) 
    fore_dice = (1-dice_class[:,1]) * torch.pow(1-dice_class[:,1], -self.gamma) 

This is not suitable for multi-class, right?

aliwaqas333 commented 2 years ago

Calculate losses separately for each class, only enhancing foreground class

    back_dice = (1-dice_class[:,0]) 
    fore_dice = (1-dice_class[:,1]) * torch.pow(1-dice_class[:,1], -self.gamma) 

This is not suitable for multi-class, right?

Yes this assumes one channel is background and another is foreground.

AlbertTJU commented 1 year ago

Calculate losses separately for each class, only enhancing foreground class

    back_dice = (1-dice_class[:,0]) 
    fore_dice = (1-dice_class[:,1]) * torch.pow(1-dice_class[:,1], -self.gamma) 

This is not suitable for multi-class, right?

Yes this assumes one channel is background and another is foreground.

Hello, my output tensor and label tensor only have one channel, so how to modify this code?

dyollb commented 7 months ago

There is an issue with a snippet in the official tensor flow repo: https://github.com/mlyg/unified-focal-loss/issues/8