Skip to content

Commit 3282e45

Browse files
Remove deprecated args and class for v1.4 (#8079)
### Types of changes <!--- 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). - [ ] 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. --------- Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 64eee8c commit 3282e45

File tree

10 files changed

+10
-89
lines changed

10 files changed

+10
-89
lines changed

monai/bundle/workflows.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from monai.bundle.properties import InferProperties, MetaProperties, TrainProperties
2727
from monai.bundle.utils import DEFAULT_EXP_MGMT_SETTINGS, EXPR_KEY, ID_REF_KEY, ID_SEP_KEY
2828
from monai.config import PathLike
29-
from monai.utils import BundleProperty, BundlePropertyConfig, deprecated_arg, deprecated_arg_default, ensure_tuple
29+
from monai.utils import BundleProperty, BundlePropertyConfig, deprecated_arg, ensure_tuple
3030

3131
__all__ = ["BundleWorkflow", "ConfigWorkflow"]
3232

@@ -43,7 +43,7 @@ class BundleWorkflow(ABC):
4343
workflow_type: specifies the workflow type: "train" or "training" for a training workflow,
4444
or "infer", "inference", "eval", "evaluation" for a inference workflow,
4545
other unsupported string will raise a ValueError.
46-
default to `None` for common workflow.
46+
default to `train` for train workflow.
4747
workflow: specifies the workflow type: "train" or "training" for a training workflow,
4848
or "infer", "inference", "eval", "evaluation" for a inference workflow,
4949
other unsupported string will raise a ValueError.
@@ -274,7 +274,6 @@ class ConfigWorkflow(BundleWorkflow):
274274
new_name="workflow_type",
275275
msg_suffix="please use `workflow_type` instead.",
276276
)
277-
@deprecated_arg_default("workflow_type", None, "train", since="1.2", replaced="1.4")
278277
def __init__(
279278
self,
280279
config_file: str | Sequence[str],
@@ -284,7 +283,7 @@ def __init__(
284283
run_id: str = "run",
285284
final_id: str = "finalize",
286285
tracking: str | dict | None = None,
287-
workflow_type: str | None = None,
286+
workflow_type: str | None = "train",
288287
workflow: str | None = None,
289288
properties_path: PathLike | None = None,
290289
**override: Any,

monai/handlers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from .earlystop_handler import EarlyStopHandler
2121
from .garbage_collector import GarbageCollector
2222
from .hausdorff_distance import HausdorffDistance
23-
from .ignite_metric import IgniteMetric, IgniteMetricHandler
23+
from .ignite_metric import IgniteMetricHandler
2424
from .logfile_handler import LogfileHandler
2525
from .lr_schedule_handler import LrScheduleHandler
2626
from .mean_dice import MeanDice

monai/handlers/ignite_metric.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from monai.config import IgniteInfo
2222
from monai.metrics import CumulativeIterationMetric, LossMetric
23-
from monai.utils import MetricReduction, deprecated, min_version, optional_import
23+
from monai.utils import MetricReduction, min_version, optional_import
2424

2525
idist, _ = optional_import("ignite", IgniteInfo.OPT_IMPORT_VERSION, min_version, "distributed")
2626

@@ -153,25 +153,3 @@ def attach(self, engine: Engine, name: str) -> None: # type: ignore[override]
153153
self._name = name
154154
if self.save_details and not hasattr(engine.state, "metric_details"):
155155
engine.state.metric_details = {} # type: ignore
156-
157-
158-
@deprecated(since="1.2", removed="1.4", msg_suffix="Use IgniteMetricHandler instead of IgniteMetric.")
159-
class IgniteMetric(IgniteMetricHandler):
160-
161-
def __init__(
162-
self,
163-
metric_fn: CumulativeIterationMetric | None = None,
164-
loss_fn: _Loss | None = None,
165-
output_transform: Callable = lambda x: x,
166-
save_details: bool = True,
167-
reduction: MetricReduction | str = MetricReduction.MEAN,
168-
get_not_nans: bool = False,
169-
) -> None:
170-
super().__init__(
171-
metric_fn=metric_fn,
172-
loss_fn=loss_fn,
173-
output_transform=output_transform,
174-
save_details=save_details,
175-
reduction=reduction,
176-
get_not_nans=get_not_nans,
177-
)

monai/losses/dice.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from monai.losses.focal_loss import FocalLoss
2525
from monai.losses.spatial_mask import MaskedLoss
2626
from monai.networks import one_hot
27-
from monai.utils import DiceCEReduction, LossReduction, Weight, deprecated_arg, look_up_option, pytorch_after
27+
from monai.utils import DiceCEReduction, LossReduction, Weight, look_up_option, pytorch_after
2828

2929

3030
class DiceLoss(_Loss):
@@ -646,9 +646,6 @@ class DiceCELoss(_Loss):
646646
647647
"""
648648

649-
@deprecated_arg(
650-
"ce_weight", since="1.2", removed="1.4", new_name="weight", msg_suffix="please use `weight` instead."
651-
)
652649
def __init__(
653650
self,
654651
include_background: bool = True,
@@ -662,7 +659,6 @@ def __init__(
662659
smooth_nr: float = 1e-5,
663660
smooth_dr: float = 1e-5,
664661
batch: bool = False,
665-
ce_weight: torch.Tensor | None = None,
666662
weight: torch.Tensor | None = None,
667663
lambda_dice: float = 1.0,
668664
lambda_ce: float = 1.0,
@@ -712,7 +708,6 @@ def __init__(
712708
"""
713709
super().__init__()
714710
reduction = look_up_option(reduction, DiceCEReduction).value
715-
weight = ce_weight if ce_weight is not None else weight
716711
dice_weight: torch.Tensor | None
717712
if weight is not None and not include_background:
718713
dice_weight = weight[1:]
@@ -825,9 +820,6 @@ class DiceFocalLoss(_Loss):
825820
826821
"""
827822

828-
@deprecated_arg(
829-
"focal_weight", since="1.2", removed="1.4", new_name="weight", msg_suffix="please use `weight` instead."
830-
)
831823
def __init__(
832824
self,
833825
include_background: bool = True,
@@ -842,7 +834,6 @@ def __init__(
842834
smooth_dr: float = 1e-5,
843835
batch: bool = False,
844836
gamma: float = 2.0,
845-
focal_weight: Sequence[float] | float | int | torch.Tensor | None = None,
846837
weight: Sequence[float] | float | int | torch.Tensor | None = None,
847838
lambda_dice: float = 1.0,
848839
lambda_focal: float = 1.0,
@@ -885,7 +876,6 @@ def __init__(
885876
[0, 1]. Defaults to None.
886877
"""
887878
super().__init__()
888-
weight = focal_weight if focal_weight is not None else weight
889879
self.dice = DiceLoss(
890880
include_background=include_background,
891881
to_onehot_y=False,
@@ -994,9 +984,6 @@ class GeneralizedDiceFocalLoss(_Loss):
994984
ValueError: if either `lambda_gdl` or `lambda_focal` is less than 0.
995985
"""
996986

997-
@deprecated_arg(
998-
"focal_weight", since="1.2", removed="1.4", new_name="weight", msg_suffix="please use `weight` instead."
999-
)
1000987
def __init__(
1001988
self,
1002989
include_background: bool = True,
@@ -1010,7 +997,6 @@ def __init__(
1010997
smooth_dr: float = 1e-5,
1011998
batch: bool = False,
1012999
gamma: float = 2.0,
1013-
focal_weight: Sequence[float] | float | int | torch.Tensor | None = None,
10141000
weight: Sequence[float] | float | int | torch.Tensor | None = None,
10151001
lambda_gdl: float = 1.0,
10161002
lambda_focal: float = 1.0,
@@ -1028,7 +1014,6 @@ def __init__(
10281014
smooth_dr=smooth_dr,
10291015
batch=batch,
10301016
)
1031-
weight = focal_weight if focal_weight is not None else weight
10321017
self.focal = FocalLoss(
10331018
include_background=include_background,
10341019
to_onehot_y=to_onehot_y,

monai/networks/blocks/patchembedding.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from monai.networks.blocks.pos_embed_utils import build_sincos_position_embedding
2323
from monai.networks.layers import Conv, trunc_normal_
24-
from monai.utils import deprecated_arg, ensure_tuple_rep, optional_import
24+
from monai.utils import ensure_tuple_rep, optional_import
2525
from monai.utils.module import look_up_option
2626

2727
Rearrange, _ = optional_import("einops.layers.torch", name="Rearrange")
@@ -42,17 +42,13 @@ class PatchEmbeddingBlock(nn.Module):
4242
4343
"""
4444

45-
@deprecated_arg(
46-
name="pos_embed", since="1.2", removed="1.4", new_name="proj_type", msg_suffix="please use `proj_type` instead."
47-
)
4845
def __init__(
4946
self,
5047
in_channels: int,
5148
img_size: Sequence[int] | int,
5249
patch_size: Sequence[int] | int,
5350
hidden_size: int,
5451
num_heads: int,
55-
pos_embed: str = "conv",
5652
proj_type: str = "conv",
5753
pos_embed_type: str = "learnable",
5854
dropout_rate: float = 0.0,
@@ -69,8 +65,6 @@ def __init__(
6965
pos_embed_type: position embedding layer type.
7066
dropout_rate: fraction of the input units to drop.
7167
spatial_dims: number of spatial dimensions.
72-
.. deprecated:: 1.4
73-
``pos_embed`` is deprecated in favor of ``proj_type``.
7468
"""
7569

7670
super().__init__()

monai/networks/nets/unetr.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from monai.networks.blocks.dynunet_block import UnetOutBlock
1919
from monai.networks.blocks.unetr_block import UnetrBasicBlock, UnetrPrUpBlock, UnetrUpBlock
2020
from monai.networks.nets.vit import ViT
21-
from monai.utils import deprecated_arg, ensure_tuple_rep
21+
from monai.utils import ensure_tuple_rep
2222

2323

2424
class UNETR(nn.Module):
@@ -27,9 +27,6 @@ class UNETR(nn.Module):
2727
UNETR: Transformers for 3D Medical Image Segmentation <https://arxiv.org/abs/2103.10504>"
2828
"""
2929

30-
@deprecated_arg(
31-
name="pos_embed", since="1.2", removed="1.4", new_name="proj_type", msg_suffix="please use `proj_type` instead."
32-
)
3330
def __init__(
3431
self,
3532
in_channels: int,
@@ -39,7 +36,6 @@ def __init__(
3936
hidden_size: int = 768,
4037
mlp_dim: int = 3072,
4138
num_heads: int = 12,
42-
pos_embed: str = "conv",
4339
proj_type: str = "conv",
4440
norm_name: tuple | str = "instance",
4541
conv_block: bool = True,
@@ -67,9 +63,6 @@ def __init__(
6763
qkv_bias: apply the bias term for the qkv linear layer in self attention block. Defaults to False.
6864
save_attn: to make accessible the attention in self attention block. Defaults to False.
6965
70-
.. deprecated:: 1.4
71-
``pos_embed`` is deprecated in favor of ``proj_type``.
72-
7366
Examples::
7467
7568
# for single channel input 4-channel output with image size of (96,96,96), feature size of 32 and batch norm

monai/networks/nets/vit.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from monai.networks.blocks.patchembedding import PatchEmbeddingBlock
2020
from monai.networks.blocks.transformerblock import TransformerBlock
21-
from monai.utils import deprecated_arg
2221

2322
__all__ = ["ViT"]
2423

@@ -31,9 +30,6 @@ class ViT(nn.Module):
3130
ViT supports Torchscript but only works for Pytorch after 1.8.
3231
"""
3332

34-
@deprecated_arg(
35-
name="pos_embed", since="1.2", removed="1.4", new_name="proj_type", msg_suffix="please use `proj_type` instead."
36-
)
3733
def __init__(
3834
self,
3935
in_channels: int,
@@ -43,7 +39,6 @@ def __init__(
4339
mlp_dim: int = 3072,
4440
num_layers: int = 12,
4541
num_heads: int = 12,
46-
pos_embed: str = "conv",
4742
proj_type: str = "conv",
4843
pos_embed_type: str = "learnable",
4944
classification: bool = False,
@@ -75,9 +70,6 @@ def __init__(
7570
qkv_bias (bool, optional): apply bias to the qkv linear layer in self attention block. Defaults to False.
7671
save_attn (bool, optional): to make accessible the attention in self attention block. Defaults to False.
7772
78-
.. deprecated:: 1.4
79-
``pos_embed`` is deprecated in favor of ``proj_type``.
80-
8173
Examples::
8274
8375
# for single channel input with image size of (96,96,96), conv position embedding and segmentation backbone

monai/networks/nets/vitautoenc.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from monai.networks.blocks.patchembedding import PatchEmbeddingBlock
2121
from monai.networks.blocks.transformerblock import TransformerBlock
2222
from monai.networks.layers import Conv
23-
from monai.utils import deprecated_arg, ensure_tuple_rep, is_sqrt
23+
from monai.utils import ensure_tuple_rep, is_sqrt
2424

2525
__all__ = ["ViTAutoEnc"]
2626

@@ -33,9 +33,6 @@ class ViTAutoEnc(nn.Module):
3333
Modified to also give same dimension outputs as the input size of the image
3434
"""
3535

36-
@deprecated_arg(
37-
name="pos_embed", since="1.2", removed="1.4", new_name="proj_type", msg_suffix="please use `proj_type` instead."
38-
)
3936
def __init__(
4037
self,
4138
in_channels: int,
@@ -47,7 +44,6 @@ def __init__(
4744
mlp_dim: int = 3072,
4845
num_layers: int = 12,
4946
num_heads: int = 12,
50-
pos_embed: str = "conv",
5147
proj_type: str = "conv",
5248
dropout_rate: float = 0.0,
5349
spatial_dims: int = 3,
@@ -71,9 +67,6 @@ def __init__(
7167
qkv_bias: apply bias to the qkv linear layer in self attention block. Defaults to False.
7268
save_attn: to make accessible the attention in self attention block. Defaults to False. Defaults to False.
7369
74-
.. deprecated:: 1.4
75-
``pos_embed`` is deprecated in favor of ``proj_type``.
76-
7770
Examples::
7871
7972
# for single channel input with image size of (96,96,96), conv position embedding and segmentation backbone

monai/utils/enums.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from typing import TYPE_CHECKING
1717

1818
from monai.config import IgniteInfo
19-
from monai.utils import deprecated
2019
from monai.utils.module import min_version, optional_import
2120

2221
__all__ = [
@@ -56,7 +55,6 @@
5655
"DataStatsKeys",
5756
"ImageStatsKeys",
5857
"LabelStatsKeys",
59-
"AlgoEnsembleKeys",
6058
"HoVerNetMode",
6159
"HoVerNetBranch",
6260
"LazyAttr",
@@ -615,17 +613,6 @@ class LabelStatsKeys(StrEnum):
615613
LABEL_NCOMP = "ncomponents"
616614

617615

618-
@deprecated(since="1.2", removed="1.4", msg_suffix="please use `AlgoKeys` instead.")
619-
class AlgoEnsembleKeys(StrEnum):
620-
"""
621-
Default keys for Mixed Ensemble
622-
"""
623-
624-
ID = "identifier"
625-
ALGO = "infer_algo"
626-
SCORE = "best_metric"
627-
628-
629616
class HoVerNetMode(StrEnum):
630617
"""
631618
Modes for HoVerNet model:

monai/utils/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ def run_cmd(cmd_list: list[str], **kwargs: Any) -> subprocess.CompletedProcess:
887887
if kwargs.pop("run_cmd_verbose", False):
888888
import monai
889889

890-
monai.apps.utils.get_logger("run_cmd").info(f"{cmd_list}")
890+
monai.apps.utils.get_logger("run_cmd").info(f"{cmd_list}") # type: ignore[attr-defined]
891891
try:
892892
return subprocess.run(cmd_list, **kwargs)
893893
except subprocess.CalledProcessError as e:

0 commit comments

Comments
 (0)