Is it possible to randomize the augmentation in the Dataset
class?
def __init__(self, subdict, num_labels, params=None, isTransform=None, isplot=None):
"""
:param subdict: dictionary of 3D MR images e.g. ['img_sub'] = '/user/318_T1w.nii.gz'
:param num_labels: number of segmentation labels
"""
self.subdict = subdict
self.num_labels = num_labels
self.img_subs = subdict['img_subs']
self.img_files = subdict['img_files']
self.seg_subs = subdict['seg_subs']
self.seg_files = subdict['seg_files']
self.isTransfom = isTransform
self.isplot = isplot
self.params = params
def __getitem__(self, index):
sub_name = self.img_subs[index]
if self.isTransfom:
img, seg = self.imaugment(imgnp, segnp)
def imaugment(self, X, Y):
"""
Preprocess the tuple (image, mask) and then apply if selected:
augmentation techniques adapted from Keras ImageDataGenerator
elastic deformation
"""
if Y is not None and X.shape != Y.shape:
raise ValueError("image and mask should have the same size")
if self.params["augmentation"][0] == True:
X, Y = random_transform(X, Y, **self.params["random_deform"])
if self.params["augmentation"][1] == True:
X, Y = deform_pixel(X, Y, **self.params["e_deform_p"])
if self.params["augmentation"][2] == True:
X, Y = deform_grid(X, Y, **self.params["e_deform_g"])
return X, Y
This way, I can only choose True/False, which entirely turns the augmentation on or off for the whole dataset.
What I want to augment some index/sample and not to others.
Thanks for the help.