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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ARG PYTORCH_IMAGE=nvcr.io/nvidia/pytorch:20.10-py3

FROM ${PYTORCH_IMAGE}

MAINTAINER MONAI Consortium <monai.miccai2019@gmail.com>
LABEL maintainer="monai.miccai2019@gmail.com"

WORKDIR /opt/monai

Expand Down
6 changes: 3 additions & 3 deletions monai/networks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ def train_mode(*nets: nn.Module):
"""

# Get original state of network(s)
eval = [n for n in nets if not n.training]
eval_list = [n for n in nets if not n.training]

try:
# set to train mode
with torch.set_grad_enabled(True):
yield [n.train() for n in nets]
finally:
# Return required networks to eval
for n in eval:
# Return required networks to eval_list
for n in eval_list:
n.eval()
94 changes: 93 additions & 1 deletion monai/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,21 @@
ThresholdIntensityDict,
)
from .io.array import LoadImage, LoadNifti, LoadNumpy, LoadPNG
from .io.dictionary import LoadDatad, LoadImaged, LoadNiftid, LoadNumpyd, LoadPNGd
from .io.dictionary import (
LoadDatad,
LoadImaged,
LoadImageD,
LoadImageDict,
LoadNiftid,
LoadNiftiD,
LoadNiftiDict,
LoadNumpyd,
LoadNumpyD,
LoadNumpyDict,
LoadPNGd,
LoadPNGD,
LoadPNGDict,
)
from .post.array import (
Activations,
AsDiscrete,
Expand All @@ -149,12 +163,24 @@
)
from .post.dictionary import (
Activationsd,
ActivationsD,
ActivationsDict,
AsDiscreted,
AsDiscreteD,
AsDiscreteDict,
Ensembled,
KeepLargestConnectedComponentd,
KeepLargestConnectedComponentD,
KeepLargestConnectedComponentDict,
LabelToContourd,
LabelToContourD,
LabelToContourDict,
MeanEnsembled,
MeanEnsembleD,
MeanEnsembleDict,
VoteEnsembled,
VoteEnsembleD,
VoteEnsembleDict,
)
from .spatial.array import (
Affine,
Expand All @@ -179,19 +205,47 @@
)
from .spatial.dictionary import (
Flipd,
FlipD,
FlipDict,
Orientationd,
OrientationD,
OrientationDict,
Rand2DElasticd,
Rand2DElasticD,
Rand2DElasticDict,
Rand3DElasticd,
Rand3DElasticD,
Rand3DElasticDict,
RandAffined,
RandAffineD,
RandAffineDict,
RandFlipd,
RandFlipD,
RandFlipDict,
RandRotate90d,
RandRotate90D,
RandRotate90Dict,
RandRotated,
RandRotateD,
RandRotateDict,
RandZoomd,
RandZoomD,
RandZoomDict,
Resized,
ResizeD,
ResizeDict,
Rotate90d,
Rotate90D,
Rotate90Dict,
Rotated,
RotateD,
RotateDict,
Spacingd,
SpacingD,
SpacingDict,
Zoomd,
ZoomD,
ZoomDict,
)
from .utility.array import (
AddChannel,
Expand All @@ -216,27 +270,65 @@
)
from .utility.dictionary import (
AddChanneld,
AddChannelD,
AddChannelDict,
AddExtremePointsChanneld,
AddExtremePointsChannelD,
AddExtremePointsChannelDict,
AsChannelFirstd,
AsChannelFirstD,
AsChannelFirstDict,
AsChannelLastd,
AsChannelLastD,
AsChannelLastDict,
CastToTyped,
CastToTypeD,
CastToTypeDict,
ConcatItemsd,
ConcatItemsD,
ConcatItemsDict,
ConvertToMultiChannelBasedOnBratsClassesd,
ConvertToMultiChannelBasedOnBratsClassesD,
ConvertToMultiChannelBasedOnBratsClassesDict,
CopyItemsd,
CopyItemsD,
CopyItemsDict,
DataStatsd,
DataStatsD,
DataStatsDict,
DeleteItemsd,
DeleteItemsD,
DeleteItemsDict,
FgBgToIndicesd,
FgBgToIndicesD,
FgBgToIndicesDict,
Identityd,
IdentityD,
IdentityDict,
LabelToMaskd,
LabelToMaskD,
LabelToMaskDict,
Lambdad,
LambdaD,
LambdaDict,
RepeatChanneld,
RepeatChannelD,
RepeatChannelDict,
SelectItemsd,
SimulateDelayd,
SimulateDelayD,
SimulateDelayDict,
SplitChanneld,
SplitChannelD,
SplitChannelDict,
SqueezeDimd,
SqueezeDimD,
SqueezeDimDict,
ToNumpyd,
TorchVisiond,
ToTensord,
ToTensorD,
ToTensorDict,
)
from .utils import (
apply_transform,
Expand Down
16 changes: 15 additions & 1 deletion monai/transforms/io/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,21 @@
from monai.transforms.compose import MapTransform
from monai.transforms.io.array import LoadImage, LoadNifti, LoadNumpy, LoadPNG

__all__ = ["LoadImaged", "LoadDatad", "LoadNiftid", "LoadPNGd", "LoadNumpyd"]
__all__ = [
"LoadImaged",
"LoadDatad",
"LoadNiftid",
"LoadPNGd",
"LoadNumpyd",
"LoadImageD",
"LoadImageDict",
"LoadNiftiD",
"LoadNiftiDict",
"LoadPNGD",
"LoadPNGDict",
"LoadNumpyD",
"LoadNumpyDict",
]


class LoadImaged(MapTransform):
Expand Down
12 changes: 12 additions & 0 deletions monai/transforms/post/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
"Ensembled",
"MeanEnsembled",
"VoteEnsembled",
"ActivationsD",
"ActivationsDict",
"AsDiscreteD",
"AsDiscreteDict",
"KeepLargestConnectedComponentD",
"KeepLargestConnectedComponentDict",
"LabelToContourD",
"LabelToContourDict",
"MeanEnsembleD",
"MeanEnsembleDict",
"VoteEnsembleD",
"VoteEnsembleDict",
]


Expand Down
28 changes: 28 additions & 0 deletions monai/transforms/spatial/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@
"RandRotated",
"Zoomd",
"RandZoomd",
"SpacingD",
"SpacingDict",
"OrientationD",
"OrientationDict",
"Rotate90D",
"Rotate90Dict",
"RandRotate90D",
"RandRotate90Dict",
"ResizeD",
"ResizeDict",
"RandAffineD",
"RandAffineDict",
"Rand2DElasticD",
"Rand2DElasticDict",
"Rand3DElasticD",
"Rand3DElasticDict",
"FlipD",
"FlipDict",
"RandFlipD",
"RandFlipDict",
"RotateD",
"RotateDict",
"RandRotateD",
"RandRotateDict",
"ZoomD",
"ZoomDict",
"RandZoomD",
"RandZoomDict",
]

GridSampleModeSequence = Union[Sequence[Union[GridSampleMode, str]], GridSampleMode, str]
Expand Down
40 changes: 40 additions & 0 deletions monai/transforms/utility/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,47 @@
"FgBgToIndicesd",
"ConvertToMultiChannelBasedOnBratsClassesd",
"AddExtremePointsChanneld",
"IdentityD",
"IdentityDict",
"AsChannelFirstD",
"AsChannelFirstDict",
"AsChannelLastD",
"AsChannelLastDict",
"AddChannelD",
"AddChannelDict",
"RepeatChannelD",
"RepeatChannelDict",
"SplitChannelD",
"SplitChannelDict",
"CastToTypeD",
"CastToTypeDict",
"ToTensorD",
"ToTensorDict",
"DeleteItemsD",
"DeleteItemsDict",
"SqueezeDimD",
"SqueezeDimDict",
"DataStatsD",
"DataStatsDict",
"SimulateDelayD",
"SimulateDelayDict",
"CopyItemsD",
"CopyItemsDict",
"ConcatItemsD",
"ConcatItemsDict",
"LambdaD",
"LambdaDict",
"LabelToMaskD",
"LabelToMaskDict",
"FgBgToIndicesD",
"FgBgToIndicesDict",
"ConvertToMultiChannelBasedOnBratsClassesD",
"ConvertToMultiChannelBasedOnBratsClassesDict",
"AddExtremePointsChannelD",
"AddExtremePointsChannelDict",
"TorchVisiond",
"TorchVisionD",
"TorchVisionDict",
]


Expand Down
2 changes: 1 addition & 1 deletion monai/utils/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
alias_lock = threading.RLock()
GlobalAliases = {}

all = ["alias", "resolve_name"]
__all__ = ["alias", "resolve_name"]


def alias(*names):
Expand Down
2 changes: 1 addition & 1 deletion monai/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from functools import wraps

all = ["RestartGenerator", "MethodReplacer"]
__all__ = ["RestartGenerator", "MethodReplacer"]


class RestartGenerator:
Expand Down
2 changes: 1 addition & 1 deletion monai/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from enum import Enum

all = [
__all__ = [
"NumpyPadMode",
"GridSampleMode",
"InterpolateMode",
Expand Down
2 changes: 1 addition & 1 deletion monai/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import numpy as np
import torch

all = [
__all__ = [
"zip_with",
"star_zip_with",
"first",
Expand Down
2 changes: 1 addition & 1 deletion tests/min_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ def run_testsuit():
# testing all modules
test_runner = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
result = test_runner.run(run_testsuit())
exit(int(not result.wasSuccessful()))
sys.exit(int(not result.wasSuccessful()))
2 changes: 1 addition & 1 deletion tests/test_load_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_itk_dicom_series_reader(self, input_param, filenames, expected_shape):
[0.0, 0.0, 0.0, 1.0],
]
),
),
)
self.assertTupleEqual(result.shape, expected_shape)
self.assertTupleEqual(tuple(header["spatial_shape"]), expected_shape)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_occlusion_sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class TestComputeOcclusionSensitivity(unittest.TestCase):
@parameterized.expand([TEST_CASE_0, TEST_CASE_1])
def test_shape(self, init_data, call_data, map_expected_shape, most_prob_expected_shape):
occ_sens = OcclusionSensitivity(**init_data)
map, most_prob = occ_sens(**call_data)
self.assertTupleEqual(map.shape, map_expected_shape)
m, most_prob = occ_sens(**call_data)
self.assertTupleEqual(m.shape, map_expected_shape)
self.assertTupleEqual(most_prob.shape, most_prob_expected_shape)
# most probable class should be of type int, and should have min>=0, max<num_classes
self.assertEqual(most_prob.dtype, torch.int64)
self.assertGreaterEqual(most_prob.min(), 0)
self.assertLess(most_prob.max(), map.shape[-1])
self.assertLess(most_prob.max(), m.shape[-1])

@parameterized.expand([TEST_CASE_FAIL_0, TEST_CASE_FAIL_1])
def test_fail(self, init_data, call_data):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_reg_loss_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def forward(self, x):
optimizer = optim.Adam(net.parameters(), lr=learning_rate)

# train the network
for iter in range(max_iter):
for it in range(max_iter):
# set the gradient to zero
optimizer.zero_grad()

Expand All @@ -98,7 +98,7 @@ def forward(self, x):
loss_input = {"pred": output, "target": target}

loss_val = loss(**{k: loss_input[k] for k in forward_args})
if iter == 0:
if it == 0:
init_loss = loss_val

# backward pass
Expand Down