mist-medical / MIST

MIST: A simple, scalable, and end-to-end framework for 3D medical imaging segmentation.
Apache License 2.0
21 stars 12 forks source link

Implemented clDice in args.py and loss.py #26

Closed braykzmi closed 1 month ago

braykzmi commented 2 months ago

Implemented clDice from jocpae's github : https://github.com/jocpae/clDice/tree/master

Changes made in /mist/runtime/args.py and /mist/runtime/loss.py

aecelaya commented 2 months ago

Thanks for submitting a PR! It's looking good so far. I left some comments we need to address before merging the PR. Feel free to let me know if you have any questions. I'm happy to discuss these further.

braykzmi commented 2 months ago

No problem. I will get this fixed tomorrow morning. Thanks!

Warm Regards, Brayden Mi

On Thu, Jul 18, 2024 at 6:09 PM Adrian Celaya @.***> wrote:

Thanks for submitting a PR! It's looking good so far. I left some comments we need to address before merging the PR. Feel free to let me know if you have any questions. I'm happy to discuss these further.

— Reply to this email directly, view it on GitHub https://github.com/mist-medical/MIST/pull/26#issuecomment-2237759537, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVECJP2U5RIUQNTPYKPQUV3ZNBDKPAVCNFSM6AAAAABLC7EN2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZXG42TSNJTG4 . You are receiving this because you authored the thread.Message ID: @.***>

braykzmi commented 1 month ago

Working on this now.

On Sat, Jul 27, 2024 at 10:38 AM Adrian Celaya @.***> wrote:

@.**** commented on this pull request.

In mist/runtime/loss.py https://github.com/mist-medical/MIST/pull/26#discussion_r1693977806:

  • intersection = torch.sum((y_true * y_pred))
  • coeff = (2. * intersection + smooth) / (torch.sum(y_true) + torch.sum(y_pred) + smooth)
  • return (1. - coeff)
  • +class soft_dice_cldice(nn.Module):

  • def init(self, iter_=3, alpha=0.5, smooth = 1., exclude_background=False):
  • super(soft_dice_cldice, self).init()
  • self.iter = iter_
  • self.smooth = smooth
  • self.alpha = alpha
  • self.soft_skeletonize = SoftSkeletonize(num_iter=10)
  • self.exclude_background = exclude_background
  • def forward(self, y_true, y_pred):
  • if self.exclude_background:

Is this using the same implementation as the SoftCLDice? If so, then create an instance of SoftCLDice in __init and call it in the forward pass of this loss. Something like this should do the same thing right? It's always a best practice to reuse your existing implementations if you can. In this case, try reusing your SoftCLDice. Other than this, everything else looks great and we should be ready to merge!

class SoftDiceCLDice(nn.Module): def init(self, iterations=3, alpha=0.5, smooth=1., exclude_background=False): super(SoftDiceCLDice, self).init() self.iterations = iterations self.smooth = smooth self.alpha = alpha self.dice_loss = DiceLoss() self.exclude_background = exclude_background self.cldice_loss = SoftCLDice(self.iterations, self.smooth, self.exclude_background)

   def forward(self, y_true, y_pred):
       dice = self.dice_loss(y_true, y_pred)
       cldice = self.cldice_loss(y_true, y_pred)
       return (1.0 - self.alpha) * dice + self.alpha * cl_dice

— Reply to this email directly, view it on GitHub https://github.com/mist-medical/MIST/pull/26#discussion_r1693977806, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVECJP6GW7ML4HSQHKUSCZDZOO5H5AVCNFSM6AAAAABLC7EN2SVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDEMBTGE4TOMZXHA . You are receiving this because you authored the thread.Message ID: @.***>

aecelaya commented 1 month ago

Looks great! I'll merge this today. We'll need to test this on a dataset before we release it in the next version