Skip to content

Commit 8084394

Browse files
authored
909 Drop deprecated APIs in IO transforms (#1448)
* [DLMED] remove deprecated APIs in IO transforms Signed-off-by: Nic Ma <[email protected]>
1 parent 6003c36 commit 8084394

17 files changed

+54
-830
lines changed

docs/source/highlights.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ There is a rich set of transforms in six categories: Crop & Pad, Intensity, IO,
3939
### 2. Medical specific transforms
4040
MONAI aims at providing a comprehensive medical image specific
4141
transformations. These currently include, for example:
42-
- `LoadNifti`: Load Nifti format file from provided path
42+
- `LoadImage`: Load medical specific formats file from provided path
4343
- `Spacing`: Resample input image into the specified `pixdim`
4444
- `Orientation`: Change the image's orientation into the specified `axcodes`
4545
- `RandGaussianNoise`: Perturb image intensities by adding statistical noises

docs/source/transforms.rst

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -231,24 +231,6 @@ IO
231231
:members:
232232
:special-members: __call__
233233

234-
`LoadNifti`
235-
"""""""""""
236-
.. autoclass:: LoadNifti
237-
:members:
238-
:special-members: __call__
239-
240-
`LoadPNG`
241-
"""""""""
242-
.. autoclass:: LoadPNG
243-
:members:
244-
:special-members: __call__
245-
246-
`LoadNumpy`
247-
"""""""""""
248-
.. autoclass:: LoadNumpy
249-
:members:
250-
:special-members: __call__
251-
252234
Post-processing
253235
^^^^^^^^^^^^^^^
254236

@@ -708,36 +690,12 @@ Instensity (Dict)
708690
IO (Dict)
709691
^^^^^^^^^
710692

711-
`LoadDatad`
712-
"""""""""""
713-
.. autoclass:: LoadDatad
714-
:members:
715-
:special-members: __call__
716-
717693
`LoadImaged`
718694
""""""""""""
719695
.. autoclass:: LoadImaged
720696
:members:
721697
:special-members: __call__
722698

723-
`LoadNiftid`
724-
""""""""""""
725-
.. autoclass:: LoadNiftid
726-
:members:
727-
:special-members: __call__
728-
729-
`LoadPNGd`
730-
""""""""""
731-
.. autoclass:: LoadPNGd
732-
:members:
733-
:special-members: __call__
734-
735-
`LoadNumpyd`
736-
""""""""""""
737-
.. autoclass:: LoadNumpyd
738-
:members:
739-
:special-members: __call__
740-
741699
Post-processing (Dict)
742700
^^^^^^^^^^^^^^^^^^^^^^
743701

monai/apps/datasets.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ class MedNISTDataset(Randomizable, CacheDataset):
3737
Args:
3838
root_dir: target directory to download and load MedNIST dataset.
3939
section: expected data section, can be: `training`, `validation` or `test`.
40-
transform: transforms to execute operations on input data. the default transform is `LoadPNGd`,
41-
which can load data into numpy array with [H, W] shape. for further usage, use `AddChanneld`
42-
to convert the shape to [C, H, W, D].
40+
transform: transforms to execute operations on input data.
4341
download: whether to download and extract the MedNIST from resource link, default is False.
4442
if expected file already exists, skip downloading even set it to True.
4543
user can manually copy `MedNIST.tar.gz` file or `MedNIST` folder to root directory.
@@ -158,8 +156,7 @@ class DecathlonDataset(Randomizable, CacheDataset):
158156
"Task03_Liver", "Task04_Hippocampus", "Task05_Prostate", "Task06_Lung", "Task07_Pancreas",
159157
"Task08_HepaticVessel", "Task09_Spleen", "Task10_Colon").
160158
section: expected data section, can be: `training`, `validation` or `test`.
161-
transform: transforms to execute operations on input data. the default transform is `LoadNiftid`,
162-
which can load Nifti format data into numpy array with [H, W, D] or [H, W, D, C] shape.
159+
transform: transforms to execute operations on input data.
163160
for further usage, use `AddChanneld` or `AsChannelFirstd` to convert the shape to [C, H, W, D].
164161
download: whether to download and extract the Decathlon from resource link, default is False.
165162
if expected file already exists, skip downloading even set it to True.
@@ -185,7 +182,7 @@ class DecathlonDataset(Randomizable, CacheDataset):
185182
186183
transform = Compose(
187184
[
188-
LoadNiftid(keys=["image", "label"]),
185+
LoadImaged(keys=["image", "label"]),
189186
AddChanneld(keys=["image", "label"]),
190187
ScaleIntensityd(keys="image"),
191188
ToTensord(keys=["image", "label"]),

monai/data/dataset.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ class PersistentDataset(Dataset):
8989
9090
.. code-block:: python
9191
92-
[ LoadNiftid(keys=['image', 'label']),
92+
[ LoadImaged(keys=['image', 'label']),
9393
Orientationd(keys=['image', 'label'], axcodes='RAS'),
9494
ScaleIntensityRanged(keys=['image'], a_min=-57, a_max=164, b_min=0.0, b_max=1.0, clip=True),
9595
RandCropByPosNegLabeld(keys=['image', 'label'], label_key='label', spatial_size=(96, 96, 96),
9696
pos=1, neg=1, num_samples=4, image_key='image', image_threshold=0),
9797
ToTensord(keys=['image', 'label'])]
9898
9999
Upon first use a filename based dataset will be processed by the transform for the
100-
[LoadNiftid, Orientationd, ScaleIntensityRanged] and the resulting tensor written to
100+
[LoadImaged, Orientationd, ScaleIntensityRanged] and the resulting tensor written to
101101
the `cache_dir` before applying the remaining random dependant transforms
102102
[RandCropByPosNegLabeld, ToTensord] elements for use in the analysis.
103103
@@ -446,7 +446,7 @@ class CacheDataset(Dataset):
446446
For example, if the transform is a `Compose` of::
447447
448448
transforms = Compose([
449-
LoadNiftid(),
449+
LoadImaged(),
450450
AddChanneld(),
451451
Spacingd(),
452452
Orientationd(),
@@ -457,7 +457,7 @@ class CacheDataset(Dataset):
457457
458458
when `transforms` is used in a multi-epoch training pipeline, before the first training epoch,
459459
this dataset will cache the results up to ``ScaleIntensityRanged``, as
460-
all non-random transforms `LoadNiftid`, `AddChanneld`, `Spacingd`, `Orientationd`, `ScaleIntensityRanged`
460+
all non-random transforms `LoadImaged`, `AddChanneld`, `Spacingd`, `Orientationd`, `ScaleIntensityRanged`
461461
can be cached. During training, the dataset will load the cached results and run
462462
``RandCropByPosNegLabeld`` and ``ToTensord``, as ``RandCropByPosNegLabeld`` is a randomized transform
463463
and the outcome not cached.
@@ -825,7 +825,7 @@ class ArrayDataset(Randomizable, _TorchDataset):
825825
826826
img_transform = Compose(
827827
[
828-
LoadNifti(image_only=True),
828+
LoadImage(image_only=True),
829829
AddChannel(),
830830
RandAdjustContrast()
831831
]
@@ -834,7 +834,7 @@ class ArrayDataset(Randomizable, _TorchDataset):
834834
835835
If training based on images and the metadata, the array transforms can not be composed
836836
because several transforms receives multiple parameters or return multiple values. Then Users need
837-
to define their own callable method to parse metadata from `LoadNifti` or set `affine` matrix
837+
to define their own callable method to parse metadata from `LoadImage` or set `affine` matrix
838838
to `Spacing` transform::
839839
840840
class TestCompose(Compose):
@@ -845,7 +845,7 @@ def __call__(self, input_):
845845
return self.transforms[3](img), metadata
846846
img_transform = TestCompose(
847847
[
848-
LoadNifti(image_only=False),
848+
LoadImage(image_only=False),
849849
AddChannel(),
850850
Spacing(pixdim=(1.5, 1.5, 3.0)),
851851
RandAdjustContrast()

monai/data/nifti_reader.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import numpy as np
1515
from torch.utils.data import Dataset
1616

17-
from monai.transforms import LoadNifti, Randomizable, apply_transform
17+
from monai.transforms import LoadImage, Randomizable, apply_transform
1818
from monai.utils import MAX_SEED, get_seed
1919

2020

@@ -81,16 +81,19 @@ def randomize(self, data: Optional[Any] = None) -> None:
8181
def __getitem__(self, index: int):
8282
self.randomize()
8383
meta_data = None
84-
img_loader = LoadNifti(
85-
as_closest_canonical=self.as_closest_canonical, image_only=self.image_only, dtype=self.dtype
84+
img_loader = LoadImage(
85+
reader="NibabelReader",
86+
image_only=self.image_only,
87+
dtype=self.dtype,
88+
as_closest_canonical=self.as_closest_canonical,
8689
)
8790
if self.image_only:
8891
img = img_loader(self.image_files[index])
8992
else:
9093
img, meta_data = img_loader(self.image_files[index])
9194
seg = None
9295
if self.seg_files is not None:
93-
seg_loader = LoadNifti(image_only=True)
96+
seg_loader = LoadImage(image_only=True)
9497
seg = seg_loader(self.seg_files[index])
9598
label = None
9699
if self.labels is not None:

monai/transforms/__init__.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,8 @@
137137
ThresholdIntensityD,
138138
ThresholdIntensityDict,
139139
)
140-
from .io.array import LoadImage, LoadNifti, LoadNumpy, LoadPNG
141-
from .io.dictionary import (
142-
LoadDatad,
143-
LoadImaged,
144-
LoadImageD,
145-
LoadImageDict,
146-
LoadNiftid,
147-
LoadNiftiD,
148-
LoadNiftiDict,
149-
LoadNumpyd,
150-
LoadNumpyD,
151-
LoadNumpyDict,
152-
LoadPNGd,
153-
LoadPNGD,
154-
LoadPNGDict,
155-
)
140+
from .io.array import LoadImage
141+
from .io.dictionary import LoadImaged, LoadImageD, LoadImageDict
156142
from .post.array import (
157143
Activations,
158144
AsDiscrete,

monai/transforms/compose.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __call__(self, data: Any):
5555
- ``data`` is a Numpy ndarray, PyTorch Tensor or string
5656
- the data shape can be:
5757
58-
#. string data without shape, `LoadNifti` and `LoadPNG` transforms expect file paths
58+
#. string data without shape, `LoadImage` transform expects file paths
5959
#. most of the pre-processing transforms expect: ``(num_channels, spatial_dim_1[, spatial_dim_2, ...])``,
6060
except that `AddChannel` expects (spatial_dim_1[, spatial_dim_2, ...]) and
6161
`AsChannelFirst` expects (spatial_dim_1[, spatial_dim_2, ...], num_channels)
@@ -282,7 +282,7 @@ def __call__(self, data):
282282
- ``data[key]`` is a Numpy ndarray, PyTorch Tensor or string, where ``key`` is an element
283283
of ``self.keys``, the data shape can be:
284284
285-
#. string data without shape, `LoadNiftid` and `LoadPNGd` transforms expect file paths
285+
#. string data without shape, `LoadImaged` transform expects file paths
286286
#. most of the pre-processing transforms expect: ``(num_channels, spatial_dim_1[, spatial_dim_2, ...])``,
287287
except that `AddChanneld` expects (spatial_dim_1[, spatial_dim_2, ...]) and
288288
`AsChannelFirstd` expects (spatial_dim_1[, spatial_dim_2, ...], num_channels)

0 commit comments

Comments
 (0)