Skip to content

Conversation

@Lucas-rbnt
Copy link
Contributor

@Lucas-rbnt Lucas-rbnt commented Mar 12, 2024

Fixes Issue #7512.

Description

Addition of a transformation allowing values above or below a certain percentile to be clipped.
Clipping can be hard or soft.
With soft clipping, the function remains derivable and the order of the values is respected, with smoother corners.

The soft clipping function is based on this medium article https://medium.com/life-at-hopper/clip-it-clip-it-good-1f1bf711b291

It's important to note that I've chosen to switch from Nones values to percentiles to take account of the fact that soft clipping can be one-sided or two-sided.
In fact, providing percentiles of 100 or 0 doesn't change anything in the case of hard clipping, but it does in the case of soft clipping because the function is smoothed. Hence the interest in introducing the possibility of putting None to avoid smoothing the function on one side or the other.

To implement this we had to define a softplus function in monai.transforms.utils_pytorch_numpy_unification.py. One of the problems is that np.logaddexp do not exactly yields same outputs as torch.logaddexp. I've left it as is and lowered the tolerance of the tests slightly, but it's possible to force the conversion to numpy and then switch back to torch to ensure better unification between the frameworks.

I've also added the soft_clip function in monai.transforms.utils.py with the associated unit tests to ensure that the transformation works properly.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

… soft clipping approaches

Signed-off-by: Lucas Robinet <robinet.lucas@iuct-oncopole.fr>
Signed-off-by: Lucas Robinet <robinet.lucas@iuct-oncopole.fr>
Copy link
Contributor

@KumoLiu KumoLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, overall looks good to me.

@KumoLiu KumoLiu requested a review from dongyang0122 April 1, 2024 02:38
Signed-off-by: Lucas Robinet <robinet.lucas@iuct-oncopole.fr>
Signed-off-by: Lucas Robinet <robinet.lucas@iuct-oncopole.fr>
Lucas-rbnt and others added 3 commits April 4, 2024 20:03
…ames for ClipIntensityPercentiles class

Signed-off-by: Lucas Robinet <robinet.lucas@iuct-oncopole.fr>
…lues

Signed-off-by: Lucas Robinet <robinet.lucas@iuct-oncopole.fr>
@KumoLiu
Copy link
Contributor

KumoLiu commented Apr 5, 2024

/build

2 similar comments
@KumoLiu
Copy link
Contributor

KumoLiu commented Apr 5, 2024

/build

@KumoLiu
Copy link
Contributor

KumoLiu commented Apr 5, 2024

/build

@KumoLiu KumoLiu merged commit c0b9cc0 into Project-MONAI:dev Apr 5, 2024
@Lucas-rbnt Lucas-rbnt deleted the percentile-clipper branch October 15, 2024 13:33
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

Successfully merging this pull request may close these issues.

3 participants