# We construct a data augmentation pipeline using the built-in PAZ processors: augment = SequentialProcessor() augment.add(pr.RandomContrast()) augment.add(pr.RandomBrightness()) augment.add(pr.RandomSaturation()) # We can now apply our pipeline as a normal function: for _ in range(5): image = load_image(image_fullpath) # use it as a normal function image = augment(image) show_image(image) # We can add to our sequential pipeline other function anywhere i.e. arg 0: augment.insert(0, pr.LoadImage()) for _ in range(5): # now we don't load the image every time. image = augment(image_fullpath) show_image(image) # Adding new processor at the end to have a single function. augment.add(pr.ShowImage()) for _ in range(5): # everything compressed into a single function image = augment(image_fullpath) # We can also pop the last processor added. augment.pop() # We now create another processor for geometric augmentation.
if split == pr.TRAIN: self.add(pr.ControlMap(self.augment_image, [0], [0])) self.add(pr.ControlMap(self.augment_boxes, [0, 1], [0, 1])) self.add(pr.ControlMap(self.preprocess_image, [0], [0])) self.add(pr.ControlMap(self.preprocess_boxes, [1], [1])) self.add( pr.SequenceWrapper({0: { 'image': [size, size, 3] }}, {1: { 'boxes': [len(prior_boxes), 4 + num_classes] }})) prior_boxes = create_prior_boxes() draw_boxes.processors[0].processor.one_hot_encoded = True draw_boxes.insert(0, pr.ControlMap(pr.DecodeBoxes(prior_boxes), [1], [1])) draw_boxes.insert( 2, pr.ControlMap(pr.FilterClassBoxes2D(class_names[1:]), [1], [1])) def deprocess_image(image): image = (image + pr.BGR_IMAGENET_MEAN).astype('uint8') return P.image.convert_color_space(image, pr.BGR2RGB) augmentator = AugmentDetection(prior_boxes, num_classes=len(class_names)) print('Image and boxes augmentations') for _ in range(10): sample = {'image': image_fullpath, 'boxes': box_data.copy()} data = augmentator(sample) image, boxes = data['inputs']['image'], data['labels']['boxes']