Skip to content
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

Remove deprecated args and class for v1.4 #8079

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions monai/bundle/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from monai.bundle.properties import InferProperties, MetaProperties, TrainProperties
from monai.bundle.utils import DEFAULT_EXP_MGMT_SETTINGS, EXPR_KEY, ID_REF_KEY, ID_SEP_KEY
from monai.config import PathLike
from monai.utils import BundleProperty, BundlePropertyConfig, deprecated_arg, deprecated_arg_default, ensure_tuple
from monai.utils import BundleProperty, BundlePropertyConfig, deprecated_arg, ensure_tuple

__all__ = ["BundleWorkflow", "ConfigWorkflow"]

Expand All @@ -43,7 +43,7 @@ class BundleWorkflow(ABC):
workflow_type: specifies the workflow type: "train" or "training" for a training workflow,
or "infer", "inference", "eval", "evaluation" for a inference workflow,
other unsupported string will raise a ValueError.
default to `None` for common workflow.
default to `train` for train workflow.
workflow: specifies the workflow type: "train" or "training" for a training workflow,
or "infer", "inference", "eval", "evaluation" for a inference workflow,
other unsupported string will raise a ValueError.
Expand Down Expand Up @@ -274,7 +274,6 @@ class ConfigWorkflow(BundleWorkflow):
new_name="workflow_type",
msg_suffix="please use `workflow_type` instead.",
)
@deprecated_arg_default("workflow_type", None, "train", since="1.2", replaced="1.4")
def __init__(
self,
config_file: str | Sequence[str],
Expand All @@ -284,7 +283,7 @@ def __init__(
run_id: str = "run",
final_id: str = "finalize",
tracking: str | dict | None = None,
workflow_type: str | None = None,
workflow_type: str | None = "train",
workflow: str | None = None,
properties_path: PathLike | None = None,
**override: Any,
Expand Down
2 changes: 1 addition & 1 deletion monai/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .earlystop_handler import EarlyStopHandler
from .garbage_collector import GarbageCollector
from .hausdorff_distance import HausdorffDistance
from .ignite_metric import IgniteMetric, IgniteMetricHandler
from .ignite_metric import IgniteMetricHandler
from .logfile_handler import LogfileHandler
from .lr_schedule_handler import LrScheduleHandler
from .mean_dice import MeanDice
Expand Down
24 changes: 1 addition & 23 deletions monai/handlers/ignite_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from monai.config import IgniteInfo
from monai.metrics import CumulativeIterationMetric, LossMetric
from monai.utils import MetricReduction, deprecated, min_version, optional_import
from monai.utils import MetricReduction, min_version, optional_import

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

Expand Down Expand Up @@ -153,25 +153,3 @@ def attach(self, engine: Engine, name: str) -> None: # type: ignore[override]
self._name = name
if self.save_details and not hasattr(engine.state, "metric_details"):
engine.state.metric_details = {} # type: ignore


@deprecated(since="1.2", removed="1.4", msg_suffix="Use IgniteMetricHandler instead of IgniteMetric.")
class IgniteMetric(IgniteMetricHandler):

def __init__(
self,
metric_fn: CumulativeIterationMetric | None = None,
loss_fn: _Loss | None = None,
output_transform: Callable = lambda x: x,
save_details: bool = True,
reduction: MetricReduction | str = MetricReduction.MEAN,
get_not_nans: bool = False,
) -> None:
super().__init__(
metric_fn=metric_fn,
loss_fn=loss_fn,
output_transform=output_transform,
save_details=save_details,
reduction=reduction,
get_not_nans=get_not_nans,
)
17 changes: 1 addition & 16 deletions monai/losses/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from monai.losses.focal_loss import FocalLoss
from monai.losses.spatial_mask import MaskedLoss
from monai.networks import one_hot
from monai.utils import DiceCEReduction, LossReduction, Weight, deprecated_arg, look_up_option, pytorch_after
from monai.utils import DiceCEReduction, LossReduction, Weight, look_up_option, pytorch_after


class DiceLoss(_Loss):
Expand Down Expand Up @@ -646,9 +646,6 @@ class DiceCELoss(_Loss):
"""

@deprecated_arg(
"ce_weight", since="1.2", removed="1.4", new_name="weight", msg_suffix="please use `weight` instead."
)
def __init__(
self,
include_background: bool = True,
Expand All @@ -662,7 +659,6 @@ def __init__(
smooth_nr: float = 1e-5,
smooth_dr: float = 1e-5,
batch: bool = False,
ce_weight: torch.Tensor | None = None,
weight: torch.Tensor | None = None,
lambda_dice: float = 1.0,
lambda_ce: float = 1.0,
Expand Down Expand Up @@ -712,7 +708,6 @@ def __init__(
"""
super().__init__()
reduction = look_up_option(reduction, DiceCEReduction).value
weight = ce_weight if ce_weight is not None else weight
dice_weight: torch.Tensor | None
if weight is not None and not include_background:
dice_weight = weight[1:]
Expand Down Expand Up @@ -825,9 +820,6 @@ class DiceFocalLoss(_Loss):
"""

@deprecated_arg(
"focal_weight", since="1.2", removed="1.4", new_name="weight", msg_suffix="please use `weight` instead."
)
def __init__(
self,
include_background: bool = True,
Expand All @@ -842,7 +834,6 @@ def __init__(
smooth_dr: float = 1e-5,
batch: bool = False,
gamma: float = 2.0,
focal_weight: Sequence[float] | float | int | torch.Tensor | None = None,
weight: Sequence[float] | float | int | torch.Tensor | None = None,
lambda_dice: float = 1.0,
lambda_focal: float = 1.0,
Expand Down Expand Up @@ -885,7 +876,6 @@ def __init__(
[0, 1]. Defaults to None.
"""
super().__init__()
weight = focal_weight if focal_weight is not None else weight
self.dice = DiceLoss(
include_background=include_background,
to_onehot_y=False,
Expand Down Expand Up @@ -994,9 +984,6 @@ class GeneralizedDiceFocalLoss(_Loss):
ValueError: if either `lambda_gdl` or `lambda_focal` is less than 0.
"""

@deprecated_arg(
"focal_weight", since="1.2", removed="1.4", new_name="weight", msg_suffix="please use `weight` instead."
)
def __init__(
self,
include_background: bool = True,
Expand All @@ -1010,7 +997,6 @@ def __init__(
smooth_dr: float = 1e-5,
batch: bool = False,
gamma: float = 2.0,
focal_weight: Sequence[float] | float | int | torch.Tensor | None = None,
weight: Sequence[float] | float | int | torch.Tensor | None = None,
lambda_gdl: float = 1.0,
lambda_focal: float = 1.0,
Expand All @@ -1028,7 +1014,6 @@ def __init__(
smooth_dr=smooth_dr,
batch=batch,
)
weight = focal_weight if focal_weight is not None else weight
self.focal = FocalLoss(
include_background=include_background,
to_onehot_y=to_onehot_y,
Expand Down
8 changes: 1 addition & 7 deletions monai/networks/blocks/patchembedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from monai.networks.blocks.pos_embed_utils import build_sincos_position_embedding
from monai.networks.layers import Conv, trunc_normal_
from monai.utils import deprecated_arg, ensure_tuple_rep, optional_import
from monai.utils import ensure_tuple_rep, optional_import
from monai.utils.module import look_up_option

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

@deprecated_arg(
name="pos_embed", since="1.2", removed="1.4", new_name="proj_type", msg_suffix="please use `proj_type` instead."
)
def __init__(
self,
in_channels: int,
img_size: Sequence[int] | int,
patch_size: Sequence[int] | int,
hidden_size: int,
num_heads: int,
pos_embed: str = "conv",
proj_type: str = "conv",
pos_embed_type: str = "learnable",
dropout_rate: float = 0.0,
Expand All @@ -69,8 +65,6 @@ def __init__(
pos_embed_type: position embedding layer type.
dropout_rate: fraction of the input units to drop.
spatial_dims: number of spatial dimensions.
.. deprecated:: 1.4
``pos_embed`` is deprecated in favor of ``proj_type``.
"""

super().__init__()
Expand Down
9 changes: 1 addition & 8 deletions monai/networks/nets/unetr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from monai.networks.blocks.dynunet_block import UnetOutBlock
from monai.networks.blocks.unetr_block import UnetrBasicBlock, UnetrPrUpBlock, UnetrUpBlock
from monai.networks.nets.vit import ViT
from monai.utils import deprecated_arg, ensure_tuple_rep
from monai.utils import ensure_tuple_rep


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

@deprecated_arg(
name="pos_embed", since="1.2", removed="1.4", new_name="proj_type", msg_suffix="please use `proj_type` instead."
)
def __init__(
self,
in_channels: int,
Expand All @@ -39,7 +36,6 @@ def __init__(
hidden_size: int = 768,
mlp_dim: int = 3072,
num_heads: int = 12,
pos_embed: str = "conv",
proj_type: str = "conv",
norm_name: tuple | str = "instance",
conv_block: bool = True,
Expand Down Expand Up @@ -67,9 +63,6 @@ def __init__(
qkv_bias: apply the bias term for the qkv linear layer in self attention block. Defaults to False.
save_attn: to make accessible the attention in self attention block. Defaults to False.
.. deprecated:: 1.4
``pos_embed`` is deprecated in favor of ``proj_type``.
Examples::
# for single channel input 4-channel output with image size of (96,96,96), feature size of 32 and batch norm
Expand Down
8 changes: 0 additions & 8 deletions monai/networks/nets/vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from monai.networks.blocks.patchembedding import PatchEmbeddingBlock
from monai.networks.blocks.transformerblock import TransformerBlock
from monai.utils import deprecated_arg

__all__ = ["ViT"]

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

@deprecated_arg(
name="pos_embed", since="1.2", removed="1.4", new_name="proj_type", msg_suffix="please use `proj_type` instead."
)
def __init__(
self,
in_channels: int,
Expand All @@ -43,7 +39,6 @@ def __init__(
mlp_dim: int = 3072,
num_layers: int = 12,
num_heads: int = 12,
pos_embed: str = "conv",
proj_type: str = "conv",
pos_embed_type: str = "learnable",
classification: bool = False,
Expand Down Expand Up @@ -75,9 +70,6 @@ def __init__(
qkv_bias (bool, optional): apply bias to the qkv linear layer in self attention block. Defaults to False.
save_attn (bool, optional): to make accessible the attention in self attention block. Defaults to False.
.. deprecated:: 1.4
``pos_embed`` is deprecated in favor of ``proj_type``.
Examples::
# for single channel input with image size of (96,96,96), conv position embedding and segmentation backbone
Expand Down
9 changes: 1 addition & 8 deletions monai/networks/nets/vitautoenc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from monai.networks.blocks.patchembedding import PatchEmbeddingBlock
from monai.networks.blocks.transformerblock import TransformerBlock
from monai.networks.layers import Conv
from monai.utils import deprecated_arg, ensure_tuple_rep, is_sqrt
from monai.utils import ensure_tuple_rep, is_sqrt

__all__ = ["ViTAutoEnc"]

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

@deprecated_arg(
name="pos_embed", since="1.2", removed="1.4", new_name="proj_type", msg_suffix="please use `proj_type` instead."
)
def __init__(
self,
in_channels: int,
Expand All @@ -47,7 +44,6 @@ def __init__(
mlp_dim: int = 3072,
num_layers: int = 12,
num_heads: int = 12,
pos_embed: str = "conv",
proj_type: str = "conv",
dropout_rate: float = 0.0,
spatial_dims: int = 3,
Expand All @@ -71,9 +67,6 @@ def __init__(
qkv_bias: apply bias to the qkv linear layer in self attention block. Defaults to False.
save_attn: to make accessible the attention in self attention block. Defaults to False. Defaults to False.
.. deprecated:: 1.4
``pos_embed`` is deprecated in favor of ``proj_type``.
Examples::
# for single channel input with image size of (96,96,96), conv position embedding and segmentation backbone
Expand Down
13 changes: 0 additions & 13 deletions monai/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.utils import deprecated
from monai.utils.module import min_version, optional_import

__all__ = [
Expand Down Expand Up @@ -56,7 +55,6 @@
"DataStatsKeys",
"ImageStatsKeys",
"LabelStatsKeys",
"AlgoEnsembleKeys",
"HoVerNetMode",
"HoVerNetBranch",
"LazyAttr",
Expand Down Expand Up @@ -615,17 +613,6 @@ class LabelStatsKeys(StrEnum):
LABEL_NCOMP = "ncomponents"


@deprecated(since="1.2", removed="1.4", msg_suffix="please use `AlgoKeys` instead.")
class AlgoEnsembleKeys(StrEnum):
"""
Default keys for Mixed Ensemble
"""

ID = "identifier"
ALGO = "infer_algo"
SCORE = "best_metric"


class HoVerNetMode(StrEnum):
"""
Modes for HoVerNet model:
Expand Down
2 changes: 1 addition & 1 deletion monai/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ def run_cmd(cmd_list: list[str], **kwargs: Any) -> subprocess.CompletedProcess:
if kwargs.pop("run_cmd_verbose", False):
import monai

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