Skip to content
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
5 changes: 0 additions & 5 deletions docs/source/handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ GarbageCollector handler
.. autoclass:: GarbageCollector
:members:

Transform inverter
------------------
.. autoclass:: TransformInverter
:members:

Post processing
---------------
.. autoclass:: PostProcessing
Expand Down
10 changes: 1 addition & 9 deletions monai/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,5 @@
from .stats_handler import StatsHandler
from .surface_distance import SurfaceDistance
from .tensorboard_handlers import TensorBoardHandler, TensorBoardImageHandler, TensorBoardStatsHandler
from .transform_inverter import TransformInverter
from .utils import (
evenly_divisible_all_gather,
from_engine,
stopping_fn_from_loss,
stopping_fn_from_metric,
string_list_all_gather,
write_metrics_reports,
)
from .utils import from_engine, stopping_fn_from_loss, stopping_fn_from_metric, write_metrics_reports
from .validation_handler import ValidationHandler
2 changes: 1 addition & 1 deletion monai/handlers/segmentation_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +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.")
@deprecated(since="0.6.0", removed="0.8.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
144 changes: 0 additions & 144 deletions monai/handlers/transform_inverter.py

This file was deleted.

78 changes: 2 additions & 76 deletions monai/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

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

import numpy as np
import torch

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

idist, _ = optional_import("ignite", IgniteInfo.OPT_IMPORT_VERSION, min_version, "distributed")
if TYPE_CHECKING:
Expand All @@ -28,8 +28,6 @@
__all__ = [
"stopping_fn_from_metric",
"stopping_fn_from_loss",
"evenly_divisible_all_gather",
"string_list_all_gather",
"write_metrics_reports",
"from_engine",
]
Expand Down Expand Up @@ -57,78 +55,6 @@ 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.

Args:
data: source tensor to pad and execute all_gather in distributed data parallel.

Note:
The input data on different ranks must have exactly same `dtype`.

.. versionchanged:: 0.6.0
The API had been moved to `monai.utils`.

"""
if not isinstance(data, torch.Tensor):
raise ValueError("input data must be PyTorch Tensor.")

if idist.get_world_size() <= 1:
return data

# make sure the data is evenly-divisible on multi-GPUs
length = data.shape[0]
all_lens = idist.all_gather(length)
max_len = max(all_lens)
if length < max_len:
size = [max_len - length] + list(data.shape[1:])
data = torch.cat([data, data.new_full(size, 0)], dim=0)
# all gather across all processes
data = idist.all_gather(data)
# delete the padding NaN items
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.
Note that if the item in `strings` is longer than 1024 chars, it will be truncated to 1024:
https://pytorch.org/ignite/v0.4.5/distributed.html#ignite.distributed.utils.all_gather.

Args:
strings: a list of strings to all gather.

.. versionchanged:: 0.6.0
The API had been moved to `monai.utils`.

"""
world_size = idist.get_world_size()
if world_size <= 1:
return strings

result: List[List[str]] = [[] for _ in range(world_size)]
# get length of strings
length = len(strings)
all_lens = idist.all_gather(length)
max_len = max(all_lens)
# pad the item to make sure the same length
if length < max_len:
strings += ["" for _ in range(max_len - length)]

if get_torch_version_tuple() <= (1, 6):
raise RuntimeError("string all_gather can not be supported in PyTorch < 1.7.0.")

for s in strings:
gathered = idist.all_gather(s)
for i, g in enumerate(gathered):
if len(g) > 0:
result[i].append(g)
return [i for k in result for i in k]


def write_metrics_reports(
save_dir: str,
images: Optional[Sequence[str]],
Expand Down
3 changes: 3 additions & 0 deletions monai/networks/nets/netadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class NetAdapter(torch.nn.Module):
bias: the bias value when replacing the last layer. if False, the layer will not learn an additive bias,
default to True.

.. deprecated:: 0.6.0
``n_classes`` is deprecated, use ``num_classes`` instead.

"""

@deprecated_arg("n_classes", since="0.6")
Expand Down
4 changes: 4 additions & 0 deletions monai/networks/nets/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ class ResNet(nn.Module):
- 'B': kernel_size 1 conv + norm.
widen_factor: widen output for each layer.
num_classes: number of output (classifications)

.. deprecated:: 0.6.0
``n_classes`` is deprecated, use ``num_classes`` instead.

"""

@deprecated_arg("n_classes", since="0.6")
Expand Down
6 changes: 6 additions & 0 deletions monai/transforms/post/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class AsDiscrete(Transform):
rounding: if not None, round the data according to the specified option,
available options: ["torchrounding"].

.. deprecated:: 0.6.0
``n_classes`` is deprecated, use ``num_classes`` instead.

"""

@deprecated_arg("n_classes", since="0.6")
Expand Down Expand Up @@ -181,6 +184,9 @@ def __call__(
rounding: if not None, round the data according to the specified option,
available options: ["torchrounding"].

.. deprecated:: 0.6.0
``n_classes`` is deprecated, use ``num_classes`` instead.

"""
# in case the new num_classes is default but you still call deprecated n_classes
if n_classes is not None and num_classes is None:
Expand Down
3 changes: 3 additions & 0 deletions monai/transforms/post/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def __init__(
each element corresponds to a key in ``keys``.
allow_missing_keys: don't raise exception if key is missing.

.. deprecated:: 0.6.0
``n_classes`` is deprecated, use ``num_classes`` instead.

"""
# in case the new num_classes is default but you still call deprecated n_classes
if n_classes is not None and num_classes is None:
Expand Down
Loading