Replies: 1 comment 1 reply
-
Hi @Fredf10, your question looks similar to this one #6242. Hope it can help you, thanks! |
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
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am using monai and monai transforms together with pytorch_lightning, and have an issue when generating the training data using transforms.RandCropByPosNegLabeld with more than one samples. This results in a dataset where each item (i.e. sample) is a list with length equal to num_samples specified in transforms.RandCropByPosNegLabeld. I wonder if anyone knows how I can reshape the generated dataset such that eached cropped image becomes and individual sample? i.e. in the example below I would like that len(dataset) = len(data_list)*num_samples, rather than len(dataset) = len(data_list) and where each item in the dataset is a list with n=num_samples.
############################################################################################################
from monai import data, transforms
from torch.utils.data import DataLoader
data_list = [{'image': './data/training_sample_1/imaging.nii.gz',
'label': './data/training_sample_1/segmentation.nii.gz'}]
transform_dict = transforms.Compose([transforms.LoadImaged(keys=["image", "label"], ensure_channel_first=True),
transforms.RandCropByPosNegLabeld(keys=["image", "label"],
label_key="label", spatial_size=(160, 160, 160),
pos=3, neg=1, num_samples=2, image_key="image",
image_threshold=0),
transforms.ToTensord(keys=["image", "label"], track_meta=False)])
dataset = data.CacheDataset(data=data_list,
transform=transform_dict,
cache_rate=1.0,
num_workers=1)
training_sample = dataset[0]
print(type(training_sample), len(training_sample))
training_data = DataLoader(dataset)
Beta Was this translation helpful? Give feedback.
All reactions