def _aug_occl(self): from imgaug.augmenters import Sequential,SomeOf,OneOf,Sometimes,WithColorspace,WithChannels, \ Noop,Lambda,AssertLambda,AssertShape,Scale,CropAndPad, \ Pad,Crop,Fliplr,Flipud,Superpixels,ChangeColorspace, PerspectiveTransform, \ Grayscale,GaussianBlur,AverageBlur,MedianBlur,Convolve, \ Sharpen,Emboss,EdgeDetect,DirectedEdgeDetect,Add,AddElementwise, \ AdditiveGaussianNoise,Multiply,MultiplyElementwise,Dropout, \ CoarseDropout,Invert,ContrastNormalization,Affine,PiecewiseAffine, \ ElasticTransformation return Sequential( [Sometimes(0.7, CoarseDropout(p=0.4, size_percent=0.01))])
Sometimes(0.5, ContrastNormalization((0.5, 2.2), per_channel=0.3)) ], random_order=False) affine = iaa.Affine( scale=(0.5, 1.5), translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, rotate=(-180, 180), #shear=(-8, 8) ) occlude = iaa.Sequential([ #Sometimes(0.5, PerspectiveTransform(0.05)), #Sometimes(0.5, CropAndPad(percent=(-0.05, 0.1))), #Sometimes(0.5, Affine(scale=(1.0, 1.2))), #Sometimes(0.5, Affine(rotate=(-180, 180))), Sometimes(0.5, CoarseDropout( p=0.1, size_percent=0.02) ), #Sometimes(0.5, GaussianBlur(1.2*np.random.rand())), Sometimes(0.5, Add((-100, 100), per_channel=0.3)), #Sometimes(0.3, Invert(0.2, per_channel=True)), #Sometimes(0.5, Multiply((0.6, 1.4), per_channel=0.5)), #Sometimes(0.5, Multiply((0.6, 1.4))), Sometimes(0.5, ContrastNormalization((0.5, 2.2), per_channel=0.3)) ], random_order=False) def remove_pixels_outside_bbox(img, bbox_info_short): # RECREATE BBOX PIXEL DIMENSIONS FROM RELATIVE FLOATS ================== x_center_p = int(float(bbox_info_short[0]) * img.shape[1]) y_center_p = int(float(bbox_info_short[1]) * img.shape[0]) width = int(float(bbox_info_short[2]) * img.shape[1]) height = int(float(bbox_info_short[3]) * img.shape[0])
class dropout(object): def __init__(self, rate, size=None): self.trans = CoarseDropout(rate, size_percent=size) def __call__(self, image, label=None): return self.trans.augment_image(image), label
def __init__(self, rate, size=None): self.trans = CoarseDropout(rate, size_percent=size)
# Validation dataset # 2017 valset dataset_val = CocoDataset() dataset_val.load_coco(args.dataset, "val2007") dataset_val.prepare() # Image Augmentation # Right/Left flip 50% of the time, IOU50=0.029(VALIDATION SET) # augmentation = imgaug.augmenters.Fliplr(0.5) # Flip and rotate augmentation = Sequential([ Fliplr(0.5), GaussianBlur((0, 1.5)), CoarseDropout((0.03, 0.15), size_percent=(0.02, 0.05)), Affine(scale=(0.3, 2), rotate=(-20, 20)), Multiply((0.5, 1.5)), AddToHueAndSaturation((-20, 20)) ]) #augmentation = Sequential([Flipud(0.2), Fliplr(0.5), Affine(scale=(0.2, 2), rotate=(-60,60)), GaussianBlur((0, 2)), AddToHueAndSaturation((-30,30)), GammaContrast((0.5, 1.5)), AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05 * 255), per_channel=0.5)]) #augmentation = Sequential([Fliplr(0.5), Affine(scale=(0.3, 3), rotate=(-60,60)), GaussianBlur((0, 3)), AddToHueAndSaturation((-30,30)), GammaContrast((0.5, 1.5)), AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05 * 255), per_channel=0.5) ]) ''' iaa.Sequential([ # apply the following augmenters to most images iaa.Fliplr(0.5), # horizontally flip 50% of all images iaa.Flipud(0.1), # vertically flip 20% of all images # crop images by -5% to 10% of their height/width sometimes(iaa.Affine( scale={"x": (0.8, 1.2), "y": (0.8, 1.2)},