Difficulties using RandZoom transform #2653
LaiaHumbertVidan
started this conversation in
General
Replies: 5 comments 4 replies
-
Hi @LaiaHumbertVidan , Thanks for your interest and experiments with MONAI. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi, sorry. Here is the full error message:
=== Transform input info -- RandZoom ===
Data statistics:
Type: <class 'numpy.ndarray'>
Shape: (1, 64, 64, 53)
Value range: (0.0, 0.8540586233139038)
Default upsampling behavior when mode=linear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.
Traceback (most recent call last):
File "<ipython-input-19-6b5f68107be4>", line 1, in <module>
im = monai.utils.first(train_loader) # get the first item from the iterable
File "C:\Users\lh18\AppData\Local\Continuum\anaconda2\envs\lhv\lib\site-packages\monai\utils\misc.py", line 71, in first
for i in iterable:
File "C:\Users\lh18\AppData\Local\Continuum\anaconda2\envs\lhv\lib\site-packages\torch\utils\data\dataloader.py", line 345, in __next__
data = self._next_data()
File "C:\Users\lh18\AppData\Local\Continuum\anaconda2\envs\lhv\lib\site-packages\torch\utils\data\dataloader.py", line 385, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "C:\Users\lh18\AppData\Local\Continuum\anaconda2\envs\lhv\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "C:\Users\lh18\AppData\Local\Continuum\anaconda2\envs\lhv\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "C:\Users\lh18\AppData\Local\Continuum\anaconda2\envs\lhv\lib\site-packages\monai\data\image_dataset.py", line 111, in __getitem__
img = apply_transform(self.transform, img)
File "C:\Users\lh18\AppData\Local\Continuum\anaconda2\envs\lhv\lib\site-packages\monai\transforms\transform.py", line 71, in apply_transform
raise RuntimeError(f"applying transform {transform}") from e
RuntimeError: applying transform <monai.transforms.compose.Compose object at 0x000002A9DCF5B208>
…________________________________
From: Nic Ma ***@***.***>
Sent: 23 July 2021 14:56
To: Project-MONAI/MONAI ***@***.***>
Cc: Humbert-Vidan, Laia ***@***.***>; Mention ***@***.***>
Subject: Re: [Project-MONAI/MONAI] Difficulties using RandZoom transform (#2653)
You don't often get email from ***@***.*** Learn why this is important<http://aka.ms/LearnAboutSenderIdentification>
Hi @LaiaHumbertVidan<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FLaiaHumbertVidan&data=04%7C01%7Claia.humbert-vidan%40kcl.ac.uk%7Cacd047759d074548b95c08d94dd95219%7C8370cf1416f34c16b83c724071654356%7C0%7C0%7C637626418049935727%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=vWYxmqSE3owDNEkDXl82Am9h3K5833rugsibKZERriA%3D&reserved=0> ,
Thanks for your interest and experiments with MONAI.
Could you please help paste the full error log for debug? The log line you pasted is not the key message.
Thanks in advance.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FProject-MONAI%2FMONAI%2Fdiscussions%2F2653%23discussioncomment-1042205&data=04%7C01%7Claia.humbert-vidan%40kcl.ac.uk%7Cacd047759d074548b95c08d94dd95219%7C8370cf1416f34c16b83c724071654356%7C0%7C0%7C637626418049945721%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=gygOjxYu851DUgC9Rmj1L9z2tTilfupOF06EWoWZklY%3D&reserved=0>, or unsubscribe<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAU3BM3D6O736VY2WPF3H4CTTZFRITANCNFSM5A35PUVA&data=04%7C01%7Claia.humbert-vidan%40kcl.ac.uk%7Cacd047759d074548b95c08d94dd95219%7C8370cf1416f34c16b83c724071654356%7C0%7C0%7C637626418049945721%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=OXhPMg0%2BjdcGtyBeZKqQ%2Bb%2FlZz%2FAHhjcz8LbqnB1au0%3D&reserved=0>.
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Beta Was this translation helpful? Give feedback.
1 reply
-
Beta Was this translation helpful? Give feedback.
1 reply
-
Hi,
It worked! Thank you so much for your help with this, very much appreciated.
…________________________________
From: Nic Ma ***@***.***>
Sent: 28 July 2021 00:39
To: Project-MONAI/MONAI ***@***.***>
Cc: Humbert-Vidan, Laia ***@***.***>; Mention ***@***.***>
Subject: Re: [Project-MONAI/MONAI] Difficulties using RandZoom transform (#2653)
Hi @LaiaHumbertVidan<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FLaiaHumbertVidan&data=04%7C01%7Claia.humbert-vidan%40kcl.ac.uk%7C766e70f64516447208b508d9514f68ec%7C8370cf1416f34c16b83c724071654356%7C0%7C0%7C637630223795955329%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=5cfv08QqMjesYO0kIppgoMZ8BLcCp29tkKyZuaxLD9Y%3D&reserved=0> ,
I tried to develop a program to reproduce your issue with synthetic data:
print(f"generating synthetic data to {tempdir} (this may take a while)")
for i in range(40):
im, seg = create_test_image_3d(128, 128, 128, num_seg_classes=1)
n = nib.Nifti1Image(im, np.eye(4))
nib.save(n, os.path.join(tempdir, f"im{i:d}.nii.gz"))
n = nib.Nifti1Image(seg, np.eye(4))
nib.save(n, os.path.join(tempdir, f"seg{i:d}.nii.gz"))
images = sorted(glob(os.path.join(tempdir, "im*.nii.gz")))
segs = sorted(glob(os.path.join(tempdir, "seg*.nii.gz")))
# define transforms for image and segmentation
train_imtrans = Compose(
[
AddChannel(),
RandRotate(range_x=0.1, range_y=0.1,range_z=0.1, prob=1.0, padding_mode='zeros'),
RandZoom(prob=1.0, min_zoom=0.0, max_zoom=0.0, mode='linear', padding_mode='linear_ramp', keep_size=True),
EnsureType(),
]
)
# define image dataset, data loader
check_ds = ImageDataset(images, segs, transform=train_imtrans, image_only=True)
check_loader = DataLoader(check_ds, batch_size=10, num_workers=2, pin_memory=torch.cuda.is_available())
im, seg = monai.utils.misc.first(check_loader)
print(im.shape, seg.shape)
And it printed out the real error:
File "/workspace/data/medical/MONAI/monai/transforms/spatial/array.py", line 574, in __call__
zoomed = torch.nn.functional.interpolate( # type: ignore
File "/opt/conda/lib/python3.8/site-packages/torch/nn/functional.py", line 3726, in interpolate
raise NotImplementedError("Got 5D input, but linear mode needs 3D input")
Seems you should not use the linear as the interpolation mode in RandZoom transform?
When I changed to mode='trilinear', padding_mode='constant', no issue showed anymore.
Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FProject-MONAI%2FMONAI%2Fdiscussions%2F2653%23discussioncomment-1077131&data=04%7C01%7Claia.humbert-vidan%40kcl.ac.uk%7C766e70f64516447208b508d9514f68ec%7C8370cf1416f34c16b83c724071654356%7C0%7C0%7C637630223795955329%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=u11hNmzfGEsJiX3eFoi8xB2%2F9un0f3iOPGkgBunmUPU%3D&reserved=0>, or unsubscribe<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAU3BM3GCEIGA5DNBFG6VWEDTZ4YSNANCNFSM5A35PUVA&data=04%7C01%7Claia.humbert-vidan%40kcl.ac.uk%7C766e70f64516447208b508d9514f68ec%7C8370cf1416f34c16b83c724071654356%7C0%7C0%7C637630223795965322%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=uPbG3X5un0PT57FAi4g4CuWLW20Yileiko1PmfTh7AY%3D&reserved=0>.
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am able to train my network with RandRotation transform applied to the data. However, when I also want to apply the RandZoom transform, I get the following error:
RuntimeError: applying transform <monai.transforms.compose.Compose object at 0x000001BFB6257128>
Here is how I am coding this:
train_transforms = Compose(
[AddChannel(),
RandRotate(range_x=0.1, range_y=0.1,range_z=0.1, prob=0.6, padding_mode='zeros'),
RandZoom(prob=0.1, min_zoom=0.0, max_zoom=0.0, mode='linear', padding_mode='linear_ramp',
keep_size=True),
ToTensor()
])
train_ds = monai.data.ImageDataset(image_files=ID_train, labels=y_train, transform=train_transforms, image_only=True)
batch_size = 8 # explored 5 to 30 and 20 seems to give best results with densenet121
train_loader = monai.data.DataLoader(train_ds, batch_size=batch_size, pin_memory=torch.cuda.is_available())
im = monai.utils.first(train_loader)
print(im[0].shape)
Many thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions