Skip to content

Add support for optional conditioning in PatchInferer, SliceInferer, and SlidingWindowInferer #8400

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

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

FinnBehrendt
Copy link

@FinnBehrendt FinnBehrendt commented Mar 25, 2025

Fixes #8220

Description

This PR adds support for optional conditioning in MONAI’s inferers, allowing models to receive auxiliary inputs for conditioning that are processed (patched, sliced) the same way as the inputs. This is particularly relevant for generative models like conditional GANs or DMs.

Example Usage:

# Given a conditioned model, inputs of shape (1, C, H, W, D) and condition of shape (1, C, H, W, D)
output = SliceInferer(...)(inputs, model, condition=cond_tensor)

Types of changes

  • Extended PatchInferer, SliceInferer, and SlidingWindowInferer to optionally accept a condition tensor (passed as a kwarg).
  • The condition can now be:
    • None (default)
    • A tensor of the same shape as inputs
  • The inferers now slice/patch the conditions alongside the corresponding inputs and feed them to the network.
  • Updated unit tests for each inferer:
    • Verified with and without conditioning
  • 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.

Additional extensions such as support for dense vector conditioning (e.g., (1, C, Z), with Z being the conditional dimension) could be explored in a follow-up PR if there’s interest.

@FinnBehrendt FinnBehrendt marked this pull request as draft March 25, 2025 11:02
FinnBehrendt and others added 5 commits March 25, 2025 12:08
I, FinnBehrendt <[email protected]>, hereby add my Signed-off-by to this commit: 248d3c3
I, FinnBehrendt <[email protected]>, hereby add my Signed-off-by to this commit: c4c65ae

Signed-off-by: FinnBehrendt <[email protected]>
I, FinnBehrendt <[email protected]>, hereby add my Signed-off-by to this commit: dbb856a
I, FinnBehrendt <[email protected]>, hereby add my Signed-off-by to this commit: 3c63c1d

Signed-off-by: FinnBehrendt <[email protected]>
@FinnBehrendt FinnBehrendt marked this pull request as ready for review March 25, 2025 16:19
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.

SliceInferer may need to handle conditional-based models
2 participants