def __call__(self, collection: dr.Collection = None) -> dr.Collection: assert collection, "collection cannot be None" if self.objects: if isinstance(self.objects, int): self.objects = dict( w = self.objects, h = self.objects, ) elif isinstance(self.objects, (list, tuple)): self.objects = dict( w = self.objects[0], h = self.objects[1], ) for obj in collection.components_of(components.Object): obj: components.Object w = self.objects.get("w", obj.image.shape[1]) h = self.objects.get("h", obj.image.shape[0]) if hasattr(h, "__iter__"): h = np.random.randint(low = h[0], high = h[1]) if hasattr(w, "__iter__"): w = np.random.randint(low = w[0], high = w[1]) obj.image = cv2.resize(obj.image, (w, h)) if self.background: if isinstance(self.background, int): self.background = dict( w = self.background, h = self.background, ) elif isinstance(self.background, (list, tuple)): self.background = dict( w = self.background[0], h = self.background[1], ) background = collection.first_component_of(components.Background) w = self.background.get("w", background.image.shape[1]) h = self.background.get("h", background.image.shape[0]) if hasattr(h, "__iter__"): h = np.random.randint(low = h[0], high = h[1]) if hasattr(w, "__iter__"): w = np.random.randint(low = w[0], high = w[1]) background.image = cv2.resize(background.image, (w, h)) return collection
def __call__(self, collection: dr.Collection = None) -> dr.Collection: assert collection, "collection cannot be None" pv = components.PascalVoc( background = collection.first_component_of(components.Background), objects = list(collection.components_of(components.Object)), ) return collection.add( dr.Entity([pv] ))
def __call__(self, collection: dr.Collection = None) -> dr.Collection: assert collection, "collection cannot be None" if self.objects: for obj in collection.components_of(components.Object): obj: components.Object angle = np.random.choice(self.angles) obj.image = dr.utils.rotate_bound(obj.image, angle) if self.background: background = collection.first_component_of(components.Background) angle = np.random.choice(self.angles) background.image = dr.utils.rotate_bound(background.image, angle) return collection
def __call__(self, collection: dr.Collection = None) -> dr.Collection: assert collection, "collection cannot be None" augmenter: iaa.Augmenter = iaa.Multiply(mul = (0.075, 1.0), per_channel=True) if self.objects: for obj in collection.components_of(components.Object): obj: components.Object obj.image[..., :3] = augmenter.augment_image(obj.image[..., :3]) if self.background: background = collection.first_component_of(components.Background) background.image[..., :3] = augmenter.augment_image(background.image[..., :3]) return collection