Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HausdorffERLoss is not differentiable #21

Closed
shijianjian opened this issue Jan 27, 2021 · 6 comments
Closed

HausdorffERLoss is not differentiable #21

shijianjian opened this issue Jan 27, 2021 · 6 comments

Comments

@shijianjian
Copy link

I wrote a doctest for the erosion based hausdorff loss and I found it is not differentiable:

    Examples:
        >>> image_preds = torch.tensor([[
        ...    [0, 0.1, 0.1, 0],
        ...    [0, 0.3, 0.6, 0],
        ...    [0, 0.4, 0.8, 0],
        ...    [0, 0, 0, 0],
        ... ]], requires_grad=True)[None]
        >>> image_gt = torch.tensor([[
        ...    [0, 1, 0, 0],
        ...    [1, 1, 1, 0],
        ...    [1, 1, 1, 0],
        ...    [0, 0, 0, 0],
        ... ]])[None]
        >>> hdloss = HausdorffERLoss(from_logits=False)
        >>> hdloss(image_preds, image_gt)
        tensor(0.0625)
        >>> hdloss(image_preds, image_gt).backward()

I would suspect something is missing from your implementation.

@JunMa11
Copy link
Owner

JunMa11 commented Feb 1, 2021

Hi, @shijianjian
I do not implement the erosion-based HD loss.
I only use the DTM-based HD loss in my repo.

@shijianjian
Copy link
Author

@JunMa11
Copy link
Owner

JunMa11 commented Feb 1, 2021

Oh, I apologize for the inconvenience.

The erosion-based HD loss was copied from https://github.com/SilmarilBearer/HausdorffLoss and I have not tested it.

https://github.com/JunMa11/SegLoss/blob/71b14900e91ea9405d9705c95b451fc819f24c70/losses_pytorch/hausdorff.py#L15

I would recommend raising an issue in the original repo.

@lucafei
Copy link

lucafei commented Feb 1, 2021

is the HausdorffDLoss possible for multi class segmentation?

@shijianjian
Copy link
Author

@JunMa11 Sure.

@lucafei It worked in multi-label segmentation from BCHW to BCHW.

@CheeseInTrap
Copy link

Hi, I wonder why there is no normalize operation when calculating edt in HausdorffDTLoss, the loss value may be too large

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants