Skip to content

Gradients of the existing bilateral filter layers (normal and PHL) #5772

Description

@faebstn96

Describe the bug
The backward operations of the existing bilateral filter layers (normal and PHL) do not calculate the correct derivative of the filter prediction with respect to the filter input. Currently, they use the exact same filter forward function as the backward operation, which is not the correct derivative as shown in here. This issue is related to #1840 and may be partly fixed by pull-request #5757.

As discussed with @wyli we should think about how to treat the existing bilateral filter implementations (normal and PHL). I believe that their forward operations are fast and valid operators which can be valuable for users. However, their provided gradient is not correct I think. The normal bilateral filter implementation could be replaced by the #5757 version in the medium term as their forward operations are almost identical.

To Reproduce
Steps to reproduce the behavior:

  1. Install BUILD_MONAI=1 pip install --no-build-isolation git+https://github.com/Project-MONAI/MONAI#egg=monai
  2. Run the gradcheck
import torch
from monai.networks.layers import BilateralFilter


tensor_in = (torch.randn(2, 1, 10, 10, 10, dtype=torch.double, requires_grad=True))
filter = BilateralFilter.apply
gradcheck(filter, (tensor_in, 1.1, 0.5), eps=1e-6, atol=1e-5)

Expected behavior
Gradcheck passes.

Current behavior
Gradcheck fails as visible in the screenshot.
gradcheck

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions