Closed kengoto1112 closed 1 year ago
You could try this to reduce memory usage if the machine resources are limited:
Reduce the number of samples:
num_samples = 4
in
RandCropByPosNegLabeld(
keys=["image", "label"],
label_key="label",
spatial_size=(96, 96, 96),
pos=1,
neg=1,
num_samples=num_samples,
image_key="image",
image_threshold=0,
),
This will decrease the actual batch size during training:
Thank you for your response and suggestion. However, we have already reduced num_samples to 1 in the code as follows.
num_samples = 1
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
train_transforms = Compose( [ LoadImaged(keys=["image", "label"], ensure_channel_first=True), ScaleIntensityRanged( keys=["image"], a_min=-175, a_max=250, b_min=0.0, b_max=1.0, clip=True, ), CropForegroundd(keys=["image", "label"], source_key="image"), Orientationd(keys=["image", "label"], axcodes="RAS"), Spacingd( keys=["image", "label"], pixdim=(1.5, 1.5, 2.0), mode=("bilinear", "nearest"), ),
Do you have any other suggestions or recommendations that we could try to further reduce memory usage or address this issue? Thank you for your help.
what's the GPU memory on your side, SwinUNETR is a relative larger model, it probably needs at least 16G for a smooth train/validation/test, but it also depends on the data dimensions.
Thank you for your response and for letting us know about the memory requirements of SwinUNETR. Our GPU memory is on Tesla T4(16GB)from Google Colaboratory(free). However, I am following the tutorial on Google Colab, which is supposed to provide free GPU resources. Therefore, I find it frustrating that the tutorial is not working as expected on a platform that is advertised to support this type of workload. Even if the BTCV dataset is quite large, I can't get the tutorial does not work on free Google Colab.
No worries, thanks again on trying the SwinUNETR model and the tutorial. Can you have a final try of these:
Hope these helps.
I changed 96x96x96 to 64x64x64, and it worked. Thank you so much for your kind support.
I am trying to use swinUNETR with the tutorial on swin_unetr_btcv_segmentation_3d.ipynb. However, I am facing an out-of-memory error on Google Colaboratory's free GPU, and the notebook is not running.
The error occurs at the following lines :
I have tried adjusting PYTORCH_CUDA_ALLOC_CONF by setting it to max_split_size_mb:128, but I still face the same error.
To try and resolve this, I have reduced max_iterations and eval_num to 5. Additionally, I have reduced the num_workers for CacheDataset to 1 and the num_samples in the "Setup transforms for training and validation" part to 1.
I would appreciate any suggestions or solutions to resolve this issue. Thank you.