def _pre_process_image(self, img: PIL): img = img.resize((self.run_parameters.get('input_shape')[0], self.run_parameters.get('input_shape')[1]), Image.ANTIALIAS) if self.run_parameters.get('greyscale'): img = img.convert.convert('LA') else: img = img.convert('RGB') img = np.array(img) img = img / 255 # casts list to tuple img_shape = (1, ) + tuple(self.run_parameters.get('input_shape')) img = img.reshape(img_shape) return img
def augment(self, img: PIL): augmented_images = [] img = img.convert('RGB') augmented_images.append(img) # append original images if self.augmentation_params.get('flip_left_right'): augmented_images.append(self.flip_left_right(img)) if self.augmentation_params.get('flip_up_down'): augmented_images.append(self.flip_up_down(img)) if self.augmentation_params.get('rotate_random_25'): augmented_images = augmented_images + self.rotate_random_25(img) if self.augmentation_params.get('blur'): augmented_images = augmented_images + self.blur(img) assert len( augmented_images ) == self.total_augmented_images + 1, "Augment error returning wrong values" return augmented_images