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
7 changes: 4 additions & 3 deletions monai/transforms/spatial/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,12 +1483,13 @@ def __call__(
See also: https://pytorch.org/docs/stable/nn.functional.html#grid-sample
"""
self.randomize()
# if not doing transform and spatial size not defined, nothing to do
# if not doing transform and spatial size doesn't change, nothing to do
# except convert to float and convert numpy/torch
if not self._do_transform and not spatial_size and not self.spatial_size:
sp_size = fall_back_tuple(spatial_size or self.spatial_size, img.shape[1:])
do_resampling = self._do_transform or (sp_size != ensure_tuple(img.shape[1:]))
if not do_resampling:
img = img.float() if isinstance(img, torch.Tensor) else img.astype("float32")
return torch.Tensor(img) if self.resampler.as_tensor_output else np.array(img)
sp_size = fall_back_tuple(spatial_size or self.spatial_size, img.shape[1:])
grid = self.get_identity_grid(sp_size)
if self._do_transform:
grid = self.rand_affine_grid(grid=grid)
Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/spatial/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def __call__(

sp_size = fall_back_tuple(self.rand_affine.spatial_size, data[self.keys[0]].shape[1:])
# change image size or do random transform
do_resampling = self.rand_affine.spatial_size is not None or self._do_transform
do_resampling = self._do_transform or (sp_size != ensure_tuple(data[self.keys[0]].shape[1:]))

# to be consistent with the self._do_transform case (dtype and device)
affine = torch.as_tensor(np.eye(len(sp_size) + 1), device=self.rand_affine.rand_affine_grid.device)
Expand Down