Skip to content

Commit 0c98432

Browse files
committed
part of #8421
remove deprecated functionality Signed-off-by: YunLiu <[email protected]>
1 parent b58e883 commit 0c98432

File tree

11 files changed

+18
-118
lines changed

11 files changed

+18
-118
lines changed

docs/source/metrics.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Metrics
9898
`Hausdorff distance`
9999
--------------------
100100
.. autofunction:: compute_hausdorff_distance
101-
.. autofunction:: compute_percent_hausdorff_distance
102101

103102
.. autoclass:: HausdorffDistanceMetric
104103
:members:

monai/bundle/scripts.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,6 @@ def download(
629629
_check_monai_version(bundle_dir_, name_)
630630

631631

632-
@deprecated_arg("net_name", since="1.2", removed="1.5", msg_suffix="please use ``model`` instead.")
633-
@deprecated_arg("net_kwargs", since="1.2", removed="1.5", msg_suffix="please use ``model`` instead.")
634-
@deprecated_arg("return_state_dict", since="1.2", removed="1.5")
635632
def load(
636633
name: str,
637634
model: torch.nn.Module | None = None,
@@ -650,10 +647,6 @@ def load(
650647
workflow_name: str | BundleWorkflow | None = None,
651648
args_file: str | None = None,
652649
copy_model_args: dict | None = None,
653-
return_state_dict: bool = True,
654-
net_override: dict | None = None,
655-
net_name: str | None = None,
656-
**net_kwargs: Any,
657650
) -> object | tuple[torch.nn.Module, dict, dict] | Any:
658651
"""
659652
Load model weights or TorchScript module of a bundle.
@@ -699,11 +692,6 @@ def load(
699692
workflow_name: specified bundle workflow name, should be a string or class, default to "ConfigWorkflow".
700693
args_file: a JSON or YAML file to provide default values for all the args in "download" function.
701694
copy_model_args: other arguments for the `monai.networks.copy_model_state` function.
702-
return_state_dict: whether to return state dict, if True, return state_dict, else a corresponding network
703-
from `_workflow.network_def` will be instantiated and load the achieved weights.
704-
net_override: id-value pairs to override the parameters in the network of the bundle, default to `None`.
705-
net_name: if not `None`, a corresponding network will be instantiated and load the achieved weights.
706-
This argument only works when loading weights.
707695
net_kwargs: other arguments that are used to instantiate the network class defined by `net_name`.
708696
709697
Returns:
@@ -719,9 +707,6 @@ def load(
719707
when `model` and `net_name` are all `None`.
720708
721709
"""
722-
if return_state_dict and (model is not None or net_name is not None):
723-
warnings.warn("Incompatible values: model and net_name are all specified, return state dict instead.")
724-
725710
bundle_dir_ = _process_bundle_dir(bundle_dir)
726711
net_override = {} if net_override is None else net_override
727712
copy_model_args = {} if copy_model_args is None else copy_model_args
@@ -757,11 +742,8 @@ def load(
757742
warnings.warn(f"the state dictionary from {full_path} should be a dictionary but got {type(model_dict)}.")
758743
model_dict = get_state_dict(model_dict)
759744

760-
if return_state_dict:
761-
return model_dict
762-
763745
_workflow = None
764-
if model is None and net_name is None:
746+
if model is None:
765747
bundle_config_file = bundle_dir_ / name / "configs" / f"{workflow_type}.json"
766748
if bundle_config_file.is_file():
767749
_net_override = {f"network_def#{key}": value for key, value in net_override.items()}
@@ -781,10 +763,6 @@ def load(
781763
return model_dict
782764
else:
783765
model = _workflow.network_def
784-
elif net_name is not None:
785-
net_kwargs["_target_"] = net_name
786-
configer = ConfigComponent(config=net_kwargs)
787-
model = configer.instantiate() # type: ignore
788766

789767
model.to(device) # type: ignore
790768

monai/bundle/workflows.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ class BundleWorkflow(ABC):
4545
or "infer", "inference", "eval", "evaluation" for a inference workflow,
4646
other unsupported string will raise a ValueError.
4747
default to `None` for only using meta properties.
48-
workflow: specifies the workflow type: "train" or "training" for a training workflow,
49-
or "infer", "inference", "eval", "evaluation" for a inference workflow,
50-
other unsupported string will raise a ValueError.
51-
default to `None` for common workflow.
5248
properties_path: the path to the JSON file of properties. If `workflow_type` is specified, properties will be
5349
loaded from the file based on the provided `workflow_type` and meta. If no `workflow_type` is specified,
5450
properties will default to loading from "meta". If `properties_path` is None, default properties
@@ -65,17 +61,9 @@ class BundleWorkflow(ABC):
6561
supported_train_type: tuple = ("train", "training")
6662
supported_infer_type: tuple = ("infer", "inference", "eval", "evaluation")
6763

68-
@deprecated_arg(
69-
"workflow",
70-
since="1.2",
71-
removed="1.5",
72-
new_name="workflow_type",
73-
msg_suffix="please use `workflow_type` instead.",
74-
)
7564
def __init__(
7665
self,
7766
workflow_type: str | None = None,
78-
workflow: str | None = None,
7967
properties_path: PathLike | None = None,
8068
meta_file: str | Sequence[str] | None = None,
8169
logging_file: str | None = None,
@@ -102,7 +90,6 @@ def __init__(
10290
)
10391
meta_file = None
10492

105-
workflow_type = workflow if workflow is not None else workflow_type
10693
if workflow_type is not None:
10794
if workflow_type.lower() in self.supported_train_type:
10895
workflow_type = "train"
@@ -403,10 +390,6 @@ class ConfigWorkflow(BundleWorkflow):
403390
or "infer", "inference", "eval", "evaluation" for a inference workflow,
404391
other unsupported string will raise a ValueError.
405392
default to `None` for common workflow.
406-
workflow: specifies the workflow type: "train" or "training" for a training workflow,
407-
or "infer", "inference", "eval", "evaluation" for a inference workflow,
408-
other unsupported string will raise a ValueError.
409-
default to `None` for common workflow.
410393
properties_path: the path to the JSON file of properties. If `workflow_type` is specified, properties will be
411394
loaded from the file based on the provided `workflow_type` and meta. If no `workflow_type` is specified,
412395
properties will default to loading from "train". If `properties_path` is None, default properties
@@ -419,13 +402,6 @@ class ConfigWorkflow(BundleWorkflow):
419402
420403
"""
421404

422-
@deprecated_arg(
423-
"workflow",
424-
since="1.2",
425-
removed="1.5",
426-
new_name="workflow_type",
427-
msg_suffix="please use `workflow_type` instead.",
428-
)
429405
def __init__(
430406
self,
431407
config_file: str | Sequence[str],
@@ -436,11 +412,9 @@ def __init__(
436412
final_id: str = "finalize",
437413
tracking: str | dict | None = None,
438414
workflow_type: str | None = "train",
439-
workflow: str | None = None,
440415
properties_path: PathLike | None = None,
441416
**override: Any,
442417
) -> None:
443-
workflow_type = workflow if workflow is not None else workflow_type
444418
if config_file is not None:
445419
_config_files = ensure_tuple(config_file)
446420
config_root_path = Path(_config_files[0]).parent

monai/metrics/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .fid import FIDMetric, compute_frechet_distance
2020
from .froc import compute_fp_tp_probs, compute_fp_tp_probs_nd, compute_froc_curve_data, compute_froc_score
2121
from .generalized_dice import GeneralizedDiceScore, compute_generalized_dice
22-
from .hausdorff_distance import HausdorffDistanceMetric, compute_hausdorff_distance, compute_percent_hausdorff_distance
22+
from .hausdorff_distance import HausdorffDistanceMetric, compute_hausdorff_distance
2323
from .loss_metric import LossMetric
2424
from .meandice import DiceHelper, DiceMetric, compute_dice
2525
from .meaniou import MeanIoU, compute_iou

monai/metrics/generalized_dice.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,19 @@ class GeneralizedDiceScore(CumulativeIterationMetric):
3737
reduction: Define mode of reduction to the metrics. Available reduction modes:
3838
{``"none"``, ``"mean"``, ``"sum"``, ``"mean_batch"``, ``"sum_batch"``,
3939
``"mean_channel"``, ``"sum_channel"``}, default to ``"mean"``. if "none", will not do reduction.
40+
Default value is changed from `MetricReduction.MEAN_BATCH` to `MetricReduction.MEAN` in v1.5.0.
41+
Old versions computed `mean` when `mean_batch` was provided due to bug in reduction.
4042
weight_type: {``"square"``, ``"simple"``, ``"uniform"``}. Type of function to transform
4143
ground truth volume into a weight factor. Defaults to ``"square"``.
4244
4345
Raises:
4446
ValueError: When the `reduction` is not one of MetricReduction enum.
4547
"""
4648

47-
@deprecated_arg_default(
48-
"reduction",
49-
old_default=MetricReduction.MEAN_BATCH,
50-
new_default=MetricReduction.MEAN,
51-
since="1.4.0",
52-
replaced="1.5.0",
53-
msg_suffix=(
54-
"Old versions computed `mean` when `mean_batch` was provided due to bug in reduction, "
55-
"If you want to retain the old behavior (calculating the mean), please explicitly set the parameter to 'mean'."
56-
),
57-
)
5849
def __init__(
5950
self,
6051
include_background: bool = True,
61-
reduction: MetricReduction | str = MetricReduction.MEAN_BATCH,
52+
reduction: MetricReduction | str = MetricReduction.MEAN,
6253
weight_type: Weight | str = Weight.SQUARE,
6354
) -> None:
6455
super().__init__()

monai/metrics/hausdorff_distance.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from .metric import CumulativeIterationMetric
3030

31-
__all__ = ["HausdorffDistanceMetric", "compute_hausdorff_distance", "compute_percent_hausdorff_distance"]
31+
__all__ = ["HausdorffDistanceMetric", "compute_hausdorff_distance"]
3232

3333

3434
class HausdorffDistanceMetric(CumulativeIterationMetric):
@@ -216,31 +216,3 @@ def _compute_percentile_hausdorff_distance(
216216
if 0 <= percentile <= 100:
217217
return torch.quantile(surface_distance, percentile / 100)
218218
raise ValueError(f"percentile should be a value between 0 and 100, get {percentile}.")
219-
220-
221-
@deprecated(since="1.3.0", removed="1.5.0")
222-
def compute_percent_hausdorff_distance(
223-
edges_pred: np.ndarray,
224-
edges_gt: np.ndarray,
225-
distance_metric: str = "euclidean",
226-
percentile: float | None = None,
227-
spacing: int | float | np.ndarray | Sequence[int | float] | None = None,
228-
) -> float:
229-
"""
230-
This function is used to compute the directed Hausdorff distance.
231-
"""
232-
233-
surface_distance: np.ndarray = get_surface_distance( # type: ignore
234-
edges_pred, edges_gt, distance_metric=distance_metric, spacing=spacing
235-
)
236-
237-
# for both pred and gt do not have foreground
238-
if surface_distance.shape == (0,):
239-
return np.nan
240-
241-
if not percentile:
242-
return surface_distance.max() # type: ignore[no-any-return]
243-
244-
if 0 <= percentile <= 100:
245-
return np.percentile(surface_distance, percentile) # type: ignore[no-any-return]
246-
raise ValueError(f"percentile should be a value between 0 and 100, get {percentile}.")

monai/metrics/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ def do_metric_reduction(
131131
return f, not_nans
132132

133133

134-
@deprecated_arg_default(
135-
name="always_return_as_numpy", since="1.3.0", replaced="1.5.0", old_default=True, new_default=False
136-
)
137134
@deprecated_arg(
138135
name="always_return_as_numpy",
139136
since="1.5.0",
@@ -146,7 +143,7 @@ def get_mask_edges(
146143
label_idx: int = 1,
147144
crop: bool = True,
148145
spacing: Sequence | None = None,
149-
always_return_as_numpy: bool = True,
146+
always_return_as_numpy: bool = False,
150147
) -> tuple[NdarrayTensor, NdarrayTensor]:
151148
"""
152149
Compute edges from binary segmentation masks. This
@@ -175,6 +172,7 @@ def get_mask_edges(
175172
otherwise `scipy`'s binary erosion is used to calculate the edges.
176173
always_return_as_numpy: whether to a numpy array regardless of the input type.
177174
If False, return the same type as inputs.
175+
The default value is changed from `True` to `False` in v1.5.0.
178176
"""
179177
# move in the funciton to avoid using all the GPUs
180178
cucim_binary_erosion, has_cucim_binary_erosion = optional_import("cucim.skimage.morphology", name="binary_erosion")

monai/networks/nets/swin_unetr.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,8 @@ class SwinUNETR(nn.Module):
5050
<https://arxiv.org/abs/2201.01266>"
5151
"""
5252

53-
@deprecated_arg(
54-
name="img_size",
55-
since="1.3",
56-
removed="1.5",
57-
msg_suffix="The img_size argument is not required anymore and "
58-
"checks on the input size are run during forward().",
59-
)
6053
def __init__(
6154
self,
62-
img_size: Sequence[int] | int,
6355
in_channels: int,
6456
out_channels: int,
6557
patch_size: int = 2,
@@ -83,10 +75,6 @@ def __init__(
8375
) -> None:
8476
"""
8577
Args:
86-
img_size: spatial dimension of input image.
87-
This argument is only used for checking that the input image size is divisible by the patch size.
88-
The tensor passed to forward() can have a dynamic shape as long as its spatial dimensions are divisible by 2**5.
89-
It will be removed in an upcoming version.
9078
in_channels: dimension of input channels.
9179
out_channels: dimension of output channels.
9280
patch_size: size of the patch token.

monai/transforms/croppad/array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,13 +809,12 @@ def threshold_at_one(x):
809809
810810
"""
811811

812-
@deprecated_arg_default("allow_smaller", old_default=True, new_default=False, since="1.2", replaced="1.5")
813812
def __init__(
814813
self,
815814
select_fn: Callable = is_positive,
816815
channel_indices: IndexSelection | None = None,
817816
margin: Sequence[int] | int = 0,
818-
allow_smaller: bool = True,
817+
allow_smaller: bool = False,
819818
return_coords: bool = False,
820819
k_divisible: Sequence[int] | int = 1,
821820
mode: str = PytorchPadMode.CONSTANT,
@@ -830,7 +829,8 @@ def __init__(
830829
margin: add margin value to spatial dims of the bounding box, if only 1 value provided, use it for all dims.
831830
allow_smaller: when computing box size with `margin`, whether to allow the image edges to be smaller than the
832831
final box edges. If `False`, part of a padded output box might be outside of the original image, if `True`,
833-
the image edges will be used as the box edges. Default to `True`.
832+
the image edges will be used as the box edges. Default to `False`.
833+
The default value is changed from `True` to `False` in v1.5.0.
834834
return_coords: whether return the coordinates of spatial bounding box for foreground.
835835
k_divisible: make each spatial dimension to be divisible by k, default to 1.
836836
if `k_divisible` is an int, the same `k` be applied to all the input spatial dimensions.

monai/transforms/croppad/dictionary.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,15 +716,14 @@ class CropForegroundd(Cropd):
716716
for more information.
717717
"""
718718

719-
@deprecated_arg_default("allow_smaller", old_default=True, new_default=False, since="1.2", replaced="1.5")
720719
def __init__(
721720
self,
722721
keys: KeysCollection,
723722
source_key: str,
724723
select_fn: Callable = is_positive,
725724
channel_indices: IndexSelection | None = None,
726725
margin: Sequence[int] | int = 0,
727-
allow_smaller: bool = True,
726+
allow_smaller: bool = False,
728727
k_divisible: Sequence[int] | int = 1,
729728
mode: SequenceStr = PytorchPadMode.CONSTANT,
730729
start_coord_key: str | None = "foreground_start_coord",
@@ -744,7 +743,8 @@ def __init__(
744743
margin: add margin value to spatial dims of the bounding box, if only 1 value provided, use it for all dims.
745744
allow_smaller: when computing box size with `margin`, whether to allow the image edges to be smaller than the
746745
final box edges. If `False`, part of a padded output box might be outside of the original image, if `True`,
747-
the image edges will be used as the box edges. Default to `True`.
746+
the image edges will be used as the box edges. Default to `False`.
747+
The default value is changed from `True` to `False` in v1.5.0.
748748
k_divisible: make each spatial dimension to be divisible by k, default to 1.
749749
if `k_divisible` is an int, the same `k` be applied to all the input spatial dimensions.
750750
mode: available modes for numpy array:{``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``,

0 commit comments

Comments
 (0)