Project-MONAI / Project-MONAI/MONAI
Gradients of the existing bilateral filter layers (normal and PHL)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.7k
- Forks
- 1.6k
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 20
Description
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:
- Install
BUILD_MONAI=1 pip install --no-build-isolation git+https://github.com/Project-MONAI/MONAI#egg=monai - 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.

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided PyTorch gradcheck for BilateralFilter.apply and inspect the existing bilateral filter layer implementation for the normal and PHL variants. Compare the backward behavior with the derivative described in the cited paper and review pull request #5757 for related changes. Done means the relevant gradient checks pass for the existing implementations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100