Skip to content

Remove deprecated functionality for v1.5 - #8430

Merged
KumoLiu merged 10 commits into
Project-MONAI:devfrom
KumoLiu:remove-deprecated
May 9, 2025
Merged

KumoLiu merged 10 commits into
Project-MONAI:devfrom
KumoLiu:remove-deprecated

Conversation

@KumoLiu

@KumoLiu KumoLiu commented Apr 25, 2025 •

Copy link
Copy Markdown
Contributor

remove deprecated functionality

Part of #8421

Description

Removed Functionality:

  • metrics: Removed compute_percent_hausdorff_distance. Use compute_hausdorff_distance with the percentile argument instead.
  • bundle: Removed net_name, net_kwargs, and return_state_dict arguments from load(). Use the model argument for network instantiation.
  • bundle: Removed workflow argument from BundleWorkflow and ConfigWorkflow. Use workflow_type instead.
  • networks: Removed img_size argument from SwinUNETR. Input size checks are now performed during forward().

Default Value Changes:

  • GeneralizedDiceScore: Changed default reduction from MEAN_BATCH to MEAN.
  • CropForeground / CropForegroundd: Changed default allow_smaller from True to False.
  • get_mask_edges: Changed default always_return_as_numpy from True to False.
  • generate_spatial_bounding_box: Changed default allow_smaller from True to False.

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.

KumoLiu and others added 5 commits April 25, 2025 21:55
remove deprecated functionality

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
@KumoLiu
KumoLiu requested a review from ericspod April 27, 2025 09:13
KumoLiu added 2 commits April 27, 2025 17:15
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
@KumoLiu

KumoLiu commented May 8, 2025

Copy link
Copy Markdown
Contributor Author

/build

@KumoLiu

KumoLiu commented May 9, 2025

Copy link
Copy Markdown
Contributor Author

Error log:

[2025-05-08T08:11:12.365Z] ======================================================================
[2025-05-08T08:11:12.365Z] ERROR: test_get_history (tests.integration.test_auto3dseg_hpo.TestHPO)
[2025-05-08T08:11:12.365Z] ----------------------------------------------------------------------
[2025-05-08T08:11:12.365Z] Traceback (most recent call last):
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/integration/test_auto3dseg_hpo.py", line 180, in test_get_history
[2025-05-08T08:11:12.365Z]     NNIGen().run_algo(obj_filename, self.work_dir)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/hpo_gen.py", line 233, in run_algo
[2025-05-08T08:11:12.365Z]     self.algo.train(self.params)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/bundle_gen.py", line 300, in train
[2025-05-08T08:11:12.365Z]     return self._run_cmd(cmd)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/bundle_gen.py", line 277, in _run_cmd
[2025-05-08T08:11:12.365Z]     return run_cmd(cmd.split(), run_cmd_verbose=True, env=ps_environ, check=True)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/utils/misc.py", line 892, in run_cmd
[2025-05-08T08:11:12.365Z]     return subprocess.run(cmd_list, **kwargs)
[2025-05-08T08:11:12.365Z]   File "/usr/lib/python3.10/subprocess.py", line 526, in run
[2025-05-08T08:11:12.365Z]     raise CalledProcessError(retcode, process.args,
[2025-05-08T08:11:12.365Z] subprocess.CalledProcessError: Command '['python', '/tmp/tmpz6gujw0_/workdir/swinunetr_0_override_None/scripts/train.py', 'run', "--config_file='/tmp/tmpz6gujw0_/workdir/swinunetr_0_override_None/configs/hyper_parameters.yaml,/tmp/tmpz6gujw0_/workdir/swinunetr_0_override_None/configs/network.yaml,/tmp/tmpz6gujw0_/workdir/swinunetr_0_override_None/configs/transforms_infer.yaml,/tmp/tmpz6gujw0_/workdir/swinunetr_0_override_None/configs/transforms_train.yaml,/tmp/tmpz6gujw0_/workdir/swinunetr_0_override_None/configs/transforms_validate.yaml'"]' returned non-zero exit status 1.
[2025-05-08T08:11:12.365Z] 
[2025-05-08T08:11:12.365Z] ======================================================================
[2025-05-08T08:11:12.365Z] ERROR: test_run_algo (tests.integration.test_auto3dseg_hpo.TestHPO)
[2025-05-08T08:11:12.365Z] ----------------------------------------------------------------------
[2025-05-08T08:11:12.365Z] Traceback (most recent call last):
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/integration/test_auto3dseg_hpo.py", line 148, in test_run_algo
[2025-05-08T08:11:12.365Z]     NNIGen().run_algo(obj_filename, self.work_dir)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/hpo_gen.py", line 233, in run_algo
[2025-05-08T08:11:12.365Z]     self.algo.train(self.params)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/bundle_gen.py", line 300, in train
[2025-05-08T08:11:12.365Z]     return self._run_cmd(cmd)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/bundle_gen.py", line 277, in _run_cmd
[2025-05-08T08:11:12.365Z]     return run_cmd(cmd.split(), run_cmd_verbose=True, env=ps_environ, check=True)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/utils/misc.py", line 892, in run_cmd
[2025-05-08T08:11:12.365Z]     return subprocess.run(cmd_list, **kwargs)
[2025-05-08T08:11:12.365Z]   File "/usr/lib/python3.10/subprocess.py", line 526, in run
[2025-05-08T08:11:12.365Z]     raise CalledProcessError(retcode, process.args,
[2025-05-08T08:11:12.365Z] subprocess.CalledProcessError: Command '['python', '/tmp/tmpg8livo0_/workdir/swinunetr_0_override_None/scripts/train.py', 'run', "--config_file='/tmp/tmpg8livo0_/workdir/swinunetr_0_override_None/configs/hyper_parameters.yaml,/tmp/tmpg8livo0_/workdir/swinunetr_0_override_None/configs/network.yaml,/tmp/tmpg8livo0_/workdir/swinunetr_0_override_None/configs/transforms_infer.yaml,/tmp/tmpg8livo0_/workdir/swinunetr_0_override_None/configs/transforms_train.yaml,/tmp/tmpg8livo0_/workdir/swinunetr_0_override_None/configs/transforms_validate.yaml'"]' returned non-zero exit status 1.
[2025-05-08T08:11:12.365Z] 
[2025-05-08T08:11:12.365Z] ======================================================================
[2025-05-08T08:11:12.365Z] ERROR: test_run_optuna (tests.integration.test_auto3dseg_hpo.TestHPO)
[2025-05-08T08:11:12.365Z] ----------------------------------------------------------------------
[2025-05-08T08:11:12.365Z] Traceback (most recent call last):
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/integration/test_auto3dseg_hpo.py", line 163, in test_run_optuna
[2025-05-08T08:11:12.365Z]     study.optimize(
[2025-05-08T08:11:12.365Z]   File "/usr/local/lib/python3.10/dist-packages/optuna/study/study.py", line 475, in optimize
[2025-05-08T08:11:12.365Z]     _optimize(
[2025-05-08T08:11:12.365Z]   File "/usr/local/lib/python3.10/dist-packages/optuna/study/_optimize.py", line 63, in _optimize
[2025-05-08T08:11:12.365Z]     _optimize_sequential(
[2025-05-08T08:11:12.365Z]   File "/usr/local/lib/python3.10/dist-packages/optuna/study/_optimize.py", line 160, in _optimize_sequential
[2025-05-08T08:11:12.365Z]     frozen_trial = _run_trial(study, func, catch)
[2025-05-08T08:11:12.365Z]   File "/usr/local/lib/python3.10/dist-packages/optuna/study/_optimize.py", line 248, in _run_trial
[2025-05-08T08:11:12.365Z]     raise func_err
[2025-05-08T08:11:12.365Z]   File "/usr/local/lib/python3.10/dist-packages/optuna/study/_optimize.py", line 197, in _run_trial
[2025-05-08T08:11:12.365Z]     value_or_values = func(trial)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/hpo_gen.py", line 338, in __call__
[2025-05-08T08:11:12.365Z]     self.run_algo(obj_filename, output_folder, template_path)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/hpo_gen.py", line 396, in run_algo
[2025-05-08T08:11:12.365Z]     self.algo.train(self.params)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/bundle_gen.py", line 300, in train
[2025-05-08T08:11:12.365Z]     return self._run_cmd(cmd)
[2025-05-08T08:11:12.365Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/apps/auto3dseg/bundle_gen.py", line 277, in _run_cmd
[2025-05-08T08:11:12.365Z]     return run_cmd(cmd.split(), run_cmd_verbose=True, env=ps_environ, check=True)
[2025-05-08T08:11:12.366Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/utils/misc.py", line 892, in run_cmd
[2025-05-08T08:11:12.366Z]     return subprocess.run(cmd_list, **kwargs)
[2025-05-08T08:11:12.366Z]   File "/usr/lib/python3.10/subprocess.py", line 526, in run
[2025-05-08T08:11:12.366Z]     raise CalledProcessError(retcode, process.args,
[2025-05-08T08:11:12.366Z] subprocess.CalledProcessError: Command '['python', '/tmp/tmpjt2los39/optuna_test/swinunetr_0_override_learning_rate_0.01/scripts/train.py', 'run', "--config_file='/tmp/tmpjt2los39/optuna_test/swinunetr_0_override_learning_rate_0.01/configs/hyper_parameters.yaml,/tmp/tmpjt2los39/optuna_test/swinunetr_0_override_learning_rate_0.01/configs/network.yaml,/tmp/tmpjt2los39/optuna_test/swinunetr_0_override_learning_rate_0.01/configs/transforms_infer.yaml,/tmp/tmpjt2los39/optuna_test/swinunetr_0_override_learning_rate_0.01/configs/transforms_train.yaml,/tmp/tmpjt2los39/optuna_test/swinunetr_0_override_learning_rate_0.01/configs/transforms_validate.yaml'", '--learning_rate=0.01']' returned non-zero exit status 1.

@ericspod

ericspod commented May 9, 2025

Copy link
Copy Markdown
Member

Hi @KumoLiu can you set MONAI_DEBUG=1 in the blossom script? This should cause the commands that are failing to save their outputs, this statement is causing the output to be discarded.

KumoLiu added a commit to Project-MONAI/research-contributions that referenced this pull request May 9, 2025
Remove deprecated `img_size` args in `SwinUNETR`
Add `allow_smaller=True` in CropForeground / CropForegroundd since
default value has been changed

Project-MONAI/MONAI#8430

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
@KumoLiu

KumoLiu commented May 9, 2025

Copy link
Copy Markdown
Contributor Author

Hi @KumoLiu can you set MONAI_DEBUG=1 in the blossom script? This should cause the commands that are failing to save their outputs, this statement is causing the output to be discarded.

Hi @ericspod, it should be fixed by this PR: Project-MONAI/research-contributions#416.
If not, I will try to add MONAI_DEBUG=1.

KumoLiu and others added 2 commits May 9, 2025 10:42
@KumoLiu

KumoLiu commented May 9, 2025

Copy link
Copy Markdown
Contributor Author

/build

@KumoLiu

KumoLiu commented May 9, 2025

Copy link
Copy Markdown
Contributor Author

Identify the issue: There’s a dependency between this one and #8443. They must be merged simultaneously. If the changes to core aren’t merged, the algo adjustments won’t function properly.

@ericspod

ericspod commented May 9, 2025

Copy link
Copy Markdown
Member

Identify the issue: There’s a dependency between this one and #8443. They must be merged simultaneously. If the changes to core aren’t merged, the algo adjustments won’t function properly.

OK it's fine to just copy the change from #8443 here then.

@KumoLiu
KumoLiu enabled auto-merge (squash) May 9, 2025 15:40
@KumoLiu
KumoLiu merged commit f97a0e9 into Project-MONAI:dev May 9, 2025
@KumoLiu
KumoLiu deleted the remove-deprecated branch June 12, 2025 09:24
nishanthta pushed a commit to nishanthta/monai-dae that referenced this pull request Sep 9, 2025
Remove deprecated `img_size` args in `SwinUNETR`
Add `allow_smaller=True` in CropForeground / CropForegroundd since
default value has been changed

Project-MONAI/MONAI#8430

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
ericspod added a commit to Project-MONAI/model-zoo that referenced this pull request Oct 20, 2026
Fixes Project-MONAI/MONAILabel#1894.

### Description
`SwinUNETR` no longer accepts `img_size` (deprecated in MONAI 1.3 via
Project-MONAI/MONAI#7093, removed in 1.5 via Project-MONAI/MONAI#8430).
Two bundles still pass it in `network_def`, so on current MONAI they
fail to instantiate their network:

```
TypeError: SwinUNETR.__init__() got an unexpected keyword argument 'img_size'
```

This removes the argument from:
- `swin_unetr_btcv_segmentation`: `inference.json`, `train.json`
(version 0.5.9 → 0.6.0)
- `pediatric_abdominal_ct_segmentation`: `inference_swinunetr.yaml`
(version 0.4.7 → 0.4.8)

Because `img_size` is still a required argument in MONAI 1.3 and 1.4,
both bundles now declare `monai_version` 1.5.0, with `pytorch_version`
2.6.0 and `numpy_version` 1.26.4 to satisfy MONAI 1.5's requirements
(`torch>=2.4.1`, `numpy>=1.24`), matching other MONAI 1.5 bundles.

`img_size` never affected the network weights, so the pretrained
checkpoints are unaffected. (`patch_norm`, whose `SwinUNETR` default was
added in 1.5, is `False` both before and after, so the architecture is
unchanged.)

Verified with MONAI 1.5.2 by parsing `network_def` with `ConfigParser`:
all three configs fail before the change and instantiate `SwinUNETR`
after it.

### Status
**Ready**

### Please ensure all the checkboxes:
- [x] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [x] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.




<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Updates**
* SwinUNETR inference and training configurations, including the
pediatric abdominal CT model, no longer specify `img_size`; other
network settings remain unchanged.
* Updated version information and changelogs for the pediatric abdominal
CT and BTCV segmentation models.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
ericspod pushed a commit to Project-MONAI/model-zoo that referenced this pull request Oct 20, 2026
…800)

### Description
Follow-up to #799, checking the other changes in
Project-MONAI/MONAI#8430 ("Remove deprecated functionality for v1.5")
against the bundles on `dev`.

None of the removed arguments are still used, but one changed default
affects a bundle: `CropForeground(d)` now defaults to
`allow_smaller=False` (was `True`).
`wholeBody_ct_segmentation/configs/train.json` uses `CropForegroundd`
with `margin: 10` and `k_divisible: [96, 96, 96]` in both training and
validation preprocessing and does not set `allow_smaller`, so on MONAI
1.5 the crop changes whenever the foreground touches the volume border,
which is common for whole-body CT.

Checked with MONAI 1.5.2 on a synthetic volume with the bundle's
parameters: for foreground touching the border, `allow_smaller=True` and
`False` give crops with the same shape and foreground voxel count but
different contents (shifted placement); for interior foreground they are
identical.

This sets `"allow_smaller": true` explicitly in both transforms, so the
bundle behaves as it did on MONAI 1.4 (its declared `monai_version`) on
any version; 1.4 already accepts the argument. Bundle version 0.2.8 →
0.2.9.

Verified that `train#preprocessing` and `validate#preprocessing` parse
with `ConfigParser` on MONAI 1.5.2 and both `CropForegroundd` instances
have `allow_smaller=True`.

Other bundles using `CropForeground(d)`: `vista3d` already sets
`allow_smaller`, and `pediatric_abdominal_ct_segmentation` uses no
`margin`/`k_divisible`, so the default does not affect it.

### Status
**Ready**

### Please ensure all the checkboxes:
- [x] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [x] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Updated training and validation cropping behavior to allow regions
smaller than the configured target dimensions.
- Preserved previous cropping results when processing images with
dimensions smaller than the requested crop size, improving compatibility
with the latest framework version.
- **Documentation**
- Updated the model metadata changelog to record the cropping behavior
adjustment.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

4 participants