path = '/content/drive/MyDrive/Data/dataset'
train_images = sorted(glob.glob(os.path.join(path, "images", "*.tif")))
train_labels = sorted(glob.glob(os.path.join(path, "masks", "*.tif")))
data_dicts = [{"image": image_name, "label": label_name} for image_name, label_name in zip(train_images, train_labels)]
train_data_dicts, val_data_dicts = data_dicts[:-9], data_dicts[-9:]
from torch.utils.data import DataLoader
data_loader = DataLoader(train_data_dicts)
for training_sample in data_loader:
# run the deep learning training with training_sample
image = training_sample['image']
label = training_sample['label']
print(image)
print(label)
break
loader = LoadImaged(keys=("image", "label"), image_only=False)
data_dict = loader(train_data_dicts[0])
# print(f"input:, {train_data_dicts[0]}")
print(f"image shape: {data_dict['image'].shape}")
print(f"label shape: {data_dict['label'].shape}")
I'm following a Monai tutorial for 3D data augmentation for segmentation which I have 3D greyscale images and masks in TIFF format
Monai tutorial i'm following:
https://github.com/Project-MONAI/tutorials/blob/main/modules/3d_image_transforms.ipynb