Skip to content

Commit

Permalink
Merge branch 'master' into 1155-savitzky-golay-kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbaker authored Jan 13, 2021
2 parents db07bb3 + 3cb82cf commit 759daf5
Show file tree
Hide file tree
Showing 18 changed files with 290 additions and 25 deletions.
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
24 changes: 24 additions & 0 deletions docs/source/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,18 @@ Utility
:members:
:special-members: __call__

`ConvertToMultiChannelBasedOnBratsClasses`
""""""""""""""""""""""""""""""""""""""""""
.. autoclass:: ConvertToMultiChannelBasedOnBratsClasses
:members:
:special-members: __call__

`AddExtremePointsChannel`
"""""""""""""""""""""""""
.. autoclass:: AddExtremePointsChannel
:members:
:special-members: __call__

`TorchVision`
"""""""""""""
.. autoclass:: TorchVision
Expand Down Expand Up @@ -981,6 +993,18 @@ Utility (Dict)
:members:
:special-members: __call__

`ConvertToMultiChannelBasedOnBratsClassesd`
"""""""""""""""""""""""""""""""""""""""""""
.. autoclass:: ConvertToMultiChannelBasedOnBratsClassesd
:members:
:special-members: __call__

`AddExtremePointsChanneld`
""""""""""""""""""""""""""
.. autoclass:: AddExtremePointsChanneld
:members:
:special-members: __call__

`TorchVisiond`
""""""""""""""
.. autoclass:: TorchVisiond
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()
95 changes: 94 additions & 1 deletion monai/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,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 @@ -150,12 +164,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 @@ -180,26 +206,55 @@
)
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,
AddExtremePointsChannel,
AsChannelFirst,
AsChannelLast,
CastToType,
ConvertToMultiChannelBasedOnBratsClasses,
DataStats,
FgBgToIndices,
Identity,
Expand All @@ -216,27 +271,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
22 changes: 22 additions & 0 deletions monai/transforms/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Lambda",
"LabelToMask",
"FgBgToIndices",
"ConvertToMultiChannelBasedOnBratsClasses",
"AddExtremePointsChannel",
"TorchVision",
]
Expand Down Expand Up @@ -556,6 +557,27 @@ def __call__(
return fg_indices, bg_indices


class ConvertToMultiChannelBasedOnBratsClasses(Transform):
"""
Convert labels to multi channels based on brats18 classes:
label 1 is the necrotic and non-enhancing tumor core
label 2 is the the peritumoral edema
label 4 is the GD-enhancing tumor
The possible classes are TC (Tumor core), WT (Whole tumor)
and ET (Enhancing tumor).
"""

def __call__(self, img: np.ndarray) -> np.ndarray:
result = []
# merge labels 1 (tumor non-enh) and 4 (tumor enh) to TC
result.append(np.logical_or(img == 1, img == 4))
# merge labels 1 (tumor non-enh) and 4 (tumor enh) and 2 (large edema) to WT
result.append(np.logical_or(np.logical_or(img == 1, img == 4), img == 2))
# label 4 is ET
result.append(img == 4)
return np.stack(result, axis=0).astype(np.float32)


class AddExtremePointsChannel(Transform, Randomizable):
"""
Add extreme points of label to the image as a new channel. This transform generates extreme
Expand Down
Loading

0 comments on commit 759daf5

Please sign in to comment.