I have a 3D image and I want to select a number of random patches with a shape (96,96,96). So I decided to use RandSpatialCropSamples. Here you can see my piece of code:
patch_size = 96
train_imtrans = Compose(
[
LoadImage(image_only=True),
ScaleIntensity(),
AddChannel(),
RandSpatialCropSamples((96, 96, 96),10, random_size=False),
ToTensor(),
]
)
train_segtrans = Compose(
[
LoadImage(image_only=True),
AddChannel(),
RandSpatialCropSamples((96, 96, 96),10, random_size=False),
ToTensor(),
]
)
val_imtrans = Compose([LoadImage(image_only=True), RandSpatialCropSamples((96, 96, 96),10, random_size=False), ScaleIntensity(), ToTensor()])
val_segtrans = Compose([LoadImage(image_only=True),RandSpatialCropSamples((96, 96, 96),10, random_size=False), ToTensor()])
# create a training data loader
train_ds = ArrayDataset(train_img_list[0], train_imtrans, train_img_list[1], train_segtrans)
train_loader = DataLoader(train_ds, batch_size=2, num_workers=8, pin_memory=torch.cuda.is_available())
# create a validation data loader
val_ds = ArrayDataset(val_img_list[0], val_imtrans, val_img_list[1], val_segtrans)
val_loader = DataLoader(val_ds, batch_size=1, num_workers=4, pin_memory=torch.cuda.is_available())
for batch_data in train_loader:
inputs, labels = batch_data[0], batch_data[1]
NOTE: train_image_list and val_img_list are lists of lists of strings. with size (2,56)
Hello,
I have a 3D image and I want to select a number of random patches with a shape (96,96,96). So I decided to use RandSpatialCropSamples. Here you can see my piece of code:
My problem is in the inputs and labels parameters. both have a size of (2,1,96,96,96), but when I plot them, both inputs and labels are pieces of the original image and labels should be the correspondent piece of GT image but it is not. I realized that batch_data has an output size of (num_samples*2). Am I doing something wrong or is there an error in the function?
NOTE: train_image_list and val_img_list are lists of lists of strings. with size (2,56)
Thank you in advance for your help