Code Monkey home page Code Monkey logo

Comments (5)

JunMa11 avatar JunMa11 commented on July 18, 2024

Hi @GuobinZhangTJU ,

Sorry for my late reply. I'm quite busy recently.

I used this implementation

https://github.com/JunMa11/SegLoss/blob/8838616323b6ffa7fdb522c7d0a5250be4610221/test/loss_functions/boundary_loss.py#L286

I also upload the trainer https://github.com/JunMa11/SegLoss/blob/master/test/network_training/nnUNetTrainer_DiceHD.py

Tip: I would recommend to first train your network with Dice loss and then finetune with DiceHD loss.

Best,
Jun

from seglossodyssey.

GuobinZhangTJU avatar GuobinZhangTJU commented on July 18, 2024

Hi @GuobinZhangTJU ,

Sorry for my late reply. I'm quite busy recently.

I used this implementation

https://github.com/JunMa11/SegLoss/blob/8838616323b6ffa7fdb522c7d0a5250be4610221/test/loss_functions/boundary_loss.py#L286

I also upload the trainer https://github.com/JunMa11/SegLoss/blob/master/test/network_training/nnUNetTrainer_DiceHD.py

Tip: I would recommend to first train your network with Dice loss and then finetune with DiceHD loss.

Best,
Jun

Many thanks, Jun, wish the work is great~~

from seglossodyssey.

GuobinZhangTJU avatar GuobinZhangTJU commented on July 18, 2024

Hi @GuobinZhangTJU ,

Sorry for my late reply. I'm quite busy recently.

I used this implementation

https://github.com/JunMa11/SegLoss/blob/8838616323b6ffa7fdb522c7d0a5250be4610221/test/loss_functions/boundary_loss.py#L286

I also upload the trainer https://github.com/JunMa11/SegLoss/blob/master/test/network_training/nnUNetTrainer_DiceHD.py

Tip: I would recommend to first train your network with Dice loss and then finetune with DiceHD loss.

Best,
Jun

class DC_and_HD_loss(nn.Module):
    def __init__(self, soft_dice_kwargs, hd_kwargs, aggregate="sum"):
        super(DC_and_HD_loss, self).__init__()
        self.aggregate = aggregate
        self.dc = SoftDiceLoss(apply_nonlin=softmax_helper, **soft_dice_kwargs)
        self.hd = HDLoss(**hd_kwargs)

    def forward(self, net_output, target):
        dc_loss = self.dc(net_output, target)
        hd_loss = self.hd(net_output, target)
        if self.aggregate == "sum":
            with torch.no_grad():
                alpha = hd_loss / (dc_loss + 1e-5 )   ##  Here 1
            result = alpha * dc_loss + hd_loss  ##  Here 2
        else:
            raise NotImplementedError("nah son")
        return result 

Hi, Jun, in ## Here 1 and ## Here 2,
alpha = hd_loss / (dc_loss + 1e-5 ),
result = alpha * dc_loss + hd_loss,
alpha * dc_loss = hd_loss / (dc_loss + 1e-5 ) * dc_loss, where 1e-5 is too small which can be ignore, then the result will be
hd_loss , the final result will equals to 2*hd_loss, not hd_loss+dc_loss, isn't it?

from seglossodyssey.

JunMa11 avatar JunMa11 commented on July 18, 2024

@GuobinZhangTJU ,

The direct answer is no.

alpha is a scalar, which does not participate in BP and can not be merged in Here 2.
In other words, it is just a weight.

from seglossodyssey.

GuobinZhangTJU avatar GuobinZhangTJU commented on July 18, 2024

@GuobinZhangTJU ,

The direct answer is no.

alpha is a scalar, which does not participate in BP and can not be merged in Here 2.
In other words, it is just a weight.

Got it~ Thanks~~Jun~

from seglossodyssey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.