Skip to content
3 changes: 2 additions & 1 deletion monai/handlers/segmentation_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from monai.config import DtypeLike, IgniteInfo
from monai.data import decollate_batch
from monai.transforms import SaveImage
from monai.utils import GridSampleMode, GridSamplePadMode, InterpolateMode, min_version, optional_import
from monai.utils import GridSampleMode, GridSamplePadMode, InterpolateMode, deprecated, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand All @@ -26,6 +26,7 @@
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")


@deprecated(since="0.6.0", removed="0.7.0", msg_suffix="Please consider using `SaveImage[d]` transform instead.")
class SegmentationSaver:
"""
Event handler triggered on completing every iteration to save the segmentation predictions into files.
Expand Down
3 changes: 2 additions & 1 deletion monai/handlers/transform_inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from monai.config import IgniteInfo, KeysCollection
from monai.engines.utils import CommonKeys, IterationEvents
from monai.transforms import Invertd, InvertibleTransform
from monai.utils import ensure_tuple, ensure_tuple_rep, min_version, optional_import
from monai.utils import deprecated, ensure_tuple, ensure_tuple_rep, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand All @@ -26,6 +26,7 @@
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")


@deprecated(since="0.6.0", removed="0.7.0", msg_suffix="Please consider using `Invertd` transform instead.")
class TransformInverter:
"""
Ignite handler to automatically invert `transforms`.
Expand Down
13 changes: 3 additions & 10 deletions monai/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
# limitations under the License.

import os
import warnings
from collections import OrderedDict
from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Union

import numpy as np
import torch

from monai.config import IgniteInfo, KeysCollection
from monai.utils import ensure_tuple, get_torch_version_tuple, min_version, optional_import
from monai.utils import deprecated, ensure_tuple, get_torch_version_tuple, min_version, optional_import

idist, _ = optional_import("ignite", IgniteInfo.OPT_IMPORT_VERSION, min_version, "distributed")
if TYPE_CHECKING:
Expand Down Expand Up @@ -58,6 +57,7 @@ def stopping_fn(engine: Engine):
return stopping_fn


@deprecated(since="0.6.0", removed="0.7.0", msg_suffix="The API had been moved to monai.utils module.")
def evenly_divisible_all_gather(data: torch.Tensor) -> torch.Tensor:
"""
Utility function for distributed data parallel to pad at first dim to make it evenly divisible and all_gather.
Expand All @@ -69,10 +69,6 @@ def evenly_divisible_all_gather(data: torch.Tensor) -> torch.Tensor:
The input data on different ranks must have exactly same `dtype`.

"""
warnings.warn(
"evenly_divisible_all_gather had been moved to monai.utils module, will deprecate this API in MONAI v0.7.",
DeprecationWarning,
)
if not isinstance(data, torch.Tensor):
raise ValueError("input data must be PyTorch Tensor.")

Expand All @@ -92,6 +88,7 @@ def evenly_divisible_all_gather(data: torch.Tensor) -> torch.Tensor:
return torch.cat([data[i * max_len : i * max_len + l, ...] for i, l in enumerate(all_lens)], dim=0)


@deprecated(since="0.6.0", removed="0.7.0", msg_suffix="The API had been moved to monai.utils module.")
def string_list_all_gather(strings: List[str]) -> List[str]:
"""
Utility function for distributed data parallel to all gather a list of strings.
Expand All @@ -102,10 +99,6 @@ def string_list_all_gather(strings: List[str]) -> List[str]:
strings: a list of strings to all gather.

"""
warnings.warn(
"string_list_all_gather had been moved to monai.utils module, will deprecate this API in MONAI v0.7.",
DeprecationWarning,
)
world_size = idist.get_world_size()
if world_size <= 1:
return strings
Expand Down
2 changes: 1 addition & 1 deletion monai/networks/nets/torchvision_fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(
)


@deprecated(since="0.6.0", version_val="0.7.0", msg_suffix="please consider using `TorchVisionFCModel` instead.")
@deprecated(since="0.6.0", removed="0.7.0", msg_suffix="Please consider using `TorchVisionFCModel` instead.")
class TorchVisionFullyConvModel(TorchVisionFCModel):
"""
Customize TorchVision models to replace fully connected layer by convolutional layer.
Expand Down
33 changes: 20 additions & 13 deletions monai/utils/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ def deprecated(
"""
Marks a function or class as deprecated. If `since` is given this should be a version at or earlier than the
current version and states at what version of the definition was marked as deprecated. If `removed` is given
this can be any version and marks when the definition was removed. When the decorated definition is called,
that is when the function is called or the class instantiated, a warning is issued if `since` is given and
the current version is at or later than that given. An exception is instead raised if `removed` is given and
the current version is at or later than that, or if neither `since` nor `removed` is provided.
this can be any version and marks when the definition was removed.

When the decorated definition is called, that is when the function is called or the class instantiated,
a `DeprecationWarning` is issued if `since` is given and the current version is at or later than that given.
a `DeprecatedError` exception is instead raised if `removed` is given and the current version is at or later
than that, or if neither `since` nor `removed` is provided.

Args:
since: version at which the definition was marked deprecated but not removed
removed: version at which the definition was removed and no longer usable
msg_suffix: message appended to warning/exception detailing reasons for deprecation and what to use instead
version_val: (used for testing) version to compare since and removed against, default is MONAI version
since: version at which the definition was marked deprecated but not removed.
removed: version at which the definition was removed and no longer usable.
msg_suffix: message appended to warning/exception detailing reasons for deprecation and what to use instead.
version_val: (used for testing) version to compare since and removed against, default is MONAI version.

Returns:
Decorated definition which warns or raises exception when used
Expand Down Expand Up @@ -116,12 +118,17 @@ def deprecated_arg(
Marks a particular named argument of a callable as deprecated. The same conditions for `since` and `removed` as
described in the `deprecated` decorator.

When the decorated definition is called, that is when the function is called or the class instantiated with args,
a `DeprecationWarning` is issued if `since` is given and the current version is at or later than that given.
a `DeprecatedError` exception is instead raised if `removed` is given and the current version is at or later
than that, or if neither `since` nor `removed` is provided.

Args:
name: name of position or keyword argument to mark as deprecated
since: version at which the argument was marked deprecated but not removed
removed: version at which the argument was removed and no longer usable
msg_suffix: message appended to warning/exception detailing reasons for deprecation and what to use instead
version_val: (used for testing) version to compare since and removed against, default is MONAI version
name: name of position or keyword argument to mark as deprecated.
since: version at which the argument was marked deprecated but not removed.
removed: version at which the argument was removed and no longer usable.
msg_suffix: message appended to warning/exception detailing reasons for deprecation and what to use instead.
version_val: (used for testing) version to compare since and removed against, default is MONAI version.

Returns:
Decorated callable which warns or raises exception when deprecated argument used
Expand Down