You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for optional conditioning in PatchInferer, SliceInferer, and SlidingWindowInferer (#8400)
Fixes [#8220](#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:
```python
# 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
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] 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).
- [x] New tests added to cover the changes.
- [x] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x] 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.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added support for an optional "condition" tensor in patch-based,
sliding window, and slice inference, allowing conditional inference
workflows.
* The "condition" tensor is validated for shape and type consistency
with inputs and is processed in sync during inference.
* **Tests**
* Introduced extensive new tests for conditional inference across patch,
sliding window, and slice inferers to ensure correct behavior and output
validation when using the "condition" argument.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: FinnBehrendt <[email protected]>
Co-authored-by: YunLiu <[email protected]>
Co-authored-by: Eric Kerfoot <[email protected]>
0 commit comments