Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RandSpatialCrop(random_size=False) does not crop in lazy mode #6752

Closed
PaulJehanno opened this issue Jul 21, 2023 · 1 comment
Closed

RandSpatialCrop(random_size=False) does not crop in lazy mode #6752

PaulJehanno opened this issue Jul 21, 2023 · 1 comment

Comments

@PaulJehanno
Copy link

Describe the bug
As title says : RandSpatialCropd transform does not seem to crop when in lazy mode.

To Reproduce

import torch
from torchvision.transforms import Compose
import monai.transforms

x = torch.rand((1, 10, 10, 10))
t = monai.transforms.RandSpatialCrop((5, 5, 5), random_size=False, lazy=True)
t(x).size()
# returns 10,10,10 for all

Expected behavior
should return 5,5,5

Environment

================================
Printing MONAI config...
================================
MONAI version: 1.3.dev2329
Numpy version: 1.24.2
Pytorch version: 1.13.1+cu117
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: c82c65a288e396f8f7d059e82373edb1814b20be
MONAI __file__: /home/ec2-user/.pyenv/versions/3.9.2/lib/python3.9/site-packages/monai/__init__.py

Optional dependencies:
Pytorch Ignite version: NOT INSTALLED or UNKNOWN VERSION.
ITK version: NOT INSTALLED or UNKNOWN VERSION.
Nibabel version: 5.0.1
scikit-image version: 0.20.0
Pillow version: 9.4.0
Tensorboard version: NOT INSTALLED or UNKNOWN VERSION.
gdown version: NOT INSTALLED or UNKNOWN VERSION.
TorchVision version: 0.14.1+cu117
tqdm version: 4.64.1
lmdb version: NOT INSTALLED or UNKNOWN VERSION.
psutil version: NOT INSTALLED or UNKNOWN VERSION.
pandas version: 1.5.3
einops version: NOT INSTALLED or UNKNOWN VERSION.
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: NOT INSTALLED or UNKNOWN VERSION.
pynrrd version: NOT INSTALLED or UNKNOWN VERSION.

For details about installing the optional dependencies, please visit:
    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies


================================
Printing system config...
================================
`psutil` required for `print_system_info`

================================
Printing GPU config...
================================
Num GPUs: 0
Has CUDA: False
cuDNN enabled: True
cuDNN version: 8500
@PaulJehanno PaulJehanno changed the title RandSpatialCropd(random_size=False) does not crop in lazy mode RandSpatialCrop(random_size=False) does not crop in lazy mode Jul 21, 2023
@wyli
Copy link
Contributor

wyli commented Jul 21, 2023

thanks, this is mainly a usage question, the pending operations could be applied with:

import torch
from torchvision.transforms import Compose
import monai.transforms
from monai.transforms.lazy.functional import apply_pending_transforms

x = torch.rand((1, 10, 10, 10))
t = monai.transforms.RandSpatialCrop((5, 5, 5), random_size=False, lazy=True)
out = t(x)
print(apply_pending_transforms(out, None, logger_name=True).size())

please see https://github.com/Project-MONAI/tutorials/blob/main/modules/lazy_resampling_functional.ipynb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants