I am using Imgaug for image augmentation along with Custom data generator for my CNN model for the classification 23 classes of X-ray body parts. I am not sure how would I pass my augmentation function to my def getitem function, in order to to see the augmentation on my training set. The code is as follows:
train_augment = iaa.Sequential([iaa.Fliplr(1.0)])
training_generator = CustomGenerator(training_set augmentation = train_augment)
class CustomGenerator(Sequence):
def __init__(self, folder_path, class_names, images, label_index, batch_size, shuffle, augmentation):
images_path = []
for a_class in class_names:
image_folder = os.path.join(folder_path, a_class)
a_class_num = class_names.index(a_class)
for imgs in os.listdir(image_folder):
images.append(imgs)
images_path += [os.path.join(image_folder, imgs)]
label_index.append(a_class_num)
self.images_path = images_path
self.images = images
self.labels = label_index
self.num_classes = len(np.unique(self.labels))
self.batch_size = batch_size
self.shuffle = shuffle
self.augmentation = augmentation
self.on_epoch_end()
def on_epoch_end(self):
if self.shuffle == True:
rand_int = np.random.permutation(np.arange(0,len(self.images))).astype(int)
self.images_path = [self.images_path[i] for i in rand_int]
self.images = [self.images[i] for i in rand_int]
self.labels = [self.labels[i] for i in rand_int]
self.indexes = np.arange(len(self.images_path))
def __len__(self):
return int(np.ceil(len(self.images_path) / self.batch_size))
def __getitem__(self, index):
indexes = self.indexes[index * self.batch_size: (index + 1) * self.batch_size]
labels_batch = np.array([self.labels[k] for k in indexes])
image_batch = np.array([imread(self.images_path[f]) for f in indexes])
# images = self.augmentation(image_batch)
return image_batch[..., np.newaxis], tf.keras.utils.to_categorical(np.array(labels_batch), num_classes=self.num_classes)
Am fairly new to this, so any open suggestions would be appreciated. Thank You