from copy import deepcopy import torch import numpy as np from matplotlib import pyplot as plt from detectron2.engine import DefaultTrainer from detectron2.data import build_detection_train_loader from detectron2.data import detection_utils as utils from detectron2.structures import BoxMode from imgaug import augmenters as aug from imgaug.parameters import Normal, TruncatedNormal from imgaug.augmentables.bbs import BoundingBox, BoundingBoxesOnImage AUGMENTER = aug.Sequential([ aug.Add(Normal(0, 20), per_channel=True), aug.Multiply(TruncatedNormal(1, .15, low=.5, high=1.5)), aug.GaussianBlur((0, 2)), aug.Fliplr(.5), aug.Flipud(.5), aug.Affine( scale={ 'x': TruncatedNormal(1, .1, low=.8, high=1.2), 'y': TruncatedNormal(1, .1, low=.8, high=1.2), }, translate_percent={ 'x': TruncatedNormal(0, .1, low=-.2, high=.2), 'y': TruncatedNormal(0, .1, low=-.2, high=.2), }, rotate=(-180, 180), shear={
# ______________________________________________________________________________ # Main Process # #### prep_algo = config['preprocess']['prep_algo'] exec(prep_algo['src']) handler = eval(prep_algo['func_name']) test_df = pd.read_csv(path.join(DATASET_DIR, 'test.csv')) aug = iaa.Sequential( [ iaa.Fliplr(0.5), # horizontally flip 50% of all images # crop images by -5% to 10% of their height/width iaa.Affine( # scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # scale images to 80-120% of their size, individually per axis rotate=Clip(Normal(0, 5), minval=-10, maxval=10), # rotate by -45 to +45 degrees translate_percent={ "x": Clip(Normal(0, 0.025), minval=-0.05, maxval=0.05), "y": Clip(Normal(0, 0.025), minval=-0.05, maxval=0.05) }, # translate by -20 to +20 percent (per axis) # shear=(-16, 16), # shear by -16 to +16 degrees order=3, # use nearest neighbour or bilinear interpolation (fast) cval=0, # if mode is constant, use a cval between 0 and 255 mode= 'constant', # use any of scikit-image's warping modes (see 2nd image from the top for examples) backend='cv2', ), iaa.CropAndPad( percent=Clip(Normal(0, 0.1), minval=-0.2, maxval=0.2), pad_mode='constant',
def main(): params = [ ("Binomial(0.1)", Binomial(0.1)), ("Choice", Choice([0, 1, 2])), ("Choice with p", Choice([0, 1, 2], p=[0.1, 0.2, 0.7])), ("DiscreteUniform(0, 10)", DiscreteUniform(0, 10)), ("Poisson(0)", Poisson(0)), ("Poisson(5)", Poisson(5)), ("Discretize(Poisson(5))", Discretize(Poisson(5))), ("Normal(0, 1)", Normal(0, 1)), ("Normal(1, 1)", Normal(1, 1)), ("Normal(1, 2)", Normal(0, 2)), ("Normal(Choice([-1, 1]), 2)", Normal(Choice([-1, 1]), 2)), ("Discretize(Normal(0, 1.0))", Discretize(Normal(0, 1.0))), ("Positive(Normal(0, 1.0))", Positive(Normal(0, 1.0))), ("Positive(Normal(0, 1.0), mode='reroll')", Positive(Normal(0, 1.0), mode="reroll")), ("Negative(Normal(0, 1.0))", Negative(Normal(0, 1.0))), ("Negative(Normal(0, 1.0), mode='reroll')", Negative(Normal(0, 1.0), mode="reroll")), ("Laplace(0, 1.0)", Laplace(0, 1.0)), ("Laplace(1.0, 3.0)", Laplace(1.0, 3.0)), ("Laplace([-1.0, 1.0], 1.0)", Laplace([-1.0, 1.0], 1.0)), ("ChiSquare(1)", ChiSquare(1)), ("ChiSquare([1, 6])", ChiSquare([1, 6])), ("Weibull(0.5)", Weibull(0.5)), ("Weibull((1.0, 3.0))", Weibull((1.0, 3.0))), ("Uniform(0, 10)", Uniform(0, 10)), ("Beta(0.5, 0.5)", Beta(0.5, 0.5)), ("Deterministic(1)", Deterministic(1)), ("Clip(Normal(0, 1), 0, None)", Clip(Normal(0, 1), minval=0, maxval=None)), ("Multiply(Uniform(0, 10), 2)", Multiply(Uniform(0, 10), 2)), ("Add(Uniform(0, 10), 5)", Add(Uniform(0, 10), 5)), ("Absolute(Normal(0, 1))", Absolute(Normal(0, 1))), ("RandomSign(Poisson(1))", RandomSign(Poisson(1))), ("RandomSign(Poisson(1), 0.9)", RandomSign(Poisson(1), 0.9)) ] params_arithmetic = [ ("Normal(0, 1.0)", Normal(0.0, 1.0)), ("Normal(0, 1.0) + 5", Normal(0.0, 1.0) + 5), ("Normal(0, 1.0) * 10", Normal(0.0, 1.0) * 10), ("Normal(0, 1.0) / 10", Normal(0.0, 1.0) / 10), ("Normal(0, 1.0) ** 2", Normal(0.0, 1.0) ** 2) ] params_noise = [ ("SimplexNoise", SimplexNoise()), ("Sigmoid(SimplexNoise)", Sigmoid(SimplexNoise())), ("SimplexNoise(linear)", SimplexNoise(upscale_method="linear")), ("SimplexNoise(nearest)", SimplexNoise(upscale_method="nearest")), ("FrequencyNoise((-4, 4))", FrequencyNoise(exponent=(-4, 4))), ("FrequencyNoise(-2)", FrequencyNoise(exponent=-2)), ("FrequencyNoise(2)", FrequencyNoise(exponent=2)) ] images_params = [param.draw_distribution_graph() for (title, param) in params] images_arithmetic = [param.draw_distribution_graph() for (title, param) in params_arithmetic] images_noise = [param.draw_distribution_graph(size=(1000, 10, 10)) for (title, param) in params_noise] misc.imshow(np.vstack(images_params)) misc.imshow(np.vstack(images_arithmetic)) misc.imshow(np.vstack(images_noise))
# # plt.figure(figsize=(10, 2)) # df = df.transpose() # df.plot.bar() # plt.show() # ========================= # mu = 1 # variance = 4 # variance2 = 3 # variance3 = 2 # sigma = math.sqrt(variance) # sigma=4 # sigma2=3 # sigma3=2 # x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100) # x2 = np.linspace(mu - 3*sigma2, mu + 3*sigma2, 100) # x3 = np.linspace(mu - 3*sigma3, mu + 3*sigma3, 100) # plt.plot(x, stats.norm.pdf(x, mu, sigma)) # plt.plot(x2, stats.norm.pdf(x, mu, sigma)) # plt.plot(x3, stats.norm.pdf(x, mu, sigma)) # plt.show() from imgaug.parameters import show_distributions_grid, Clip, Normal, Absolute, Add show_distributions_grid( [ Add(Absolute(Normal(1.0, 2.0)), 1), ], graph_sizes=(2048, 2048), )