コード例 #1
0
ファイル: augment.py プロジェクト: mdfirman/ml_helpers
def full_trans(im):
    rotated = aug.random_rotation(im, sd=10, **newcrop)
    cropped = aug.randn_crop(rotated, sd=10, **newcrop)
    flipped = aug.random_flip(cropped)
    coloured = aug.random_colour_transform(flipped, rgb_eigval, rgb_eigvec)
    return imresize(coloured, (256, 256))
コード例 #2
0
ファイル: augment.py プロジェクト: mdfirman/ml_helpers

############################################
# GAMMA
tic = time()
ims = [aug.randn_crop(im, sd=0, **newcrop) for _ in range(24)]
ims = [gamma_augmentation(im) for im in ims]
ims = [cropped_im] + ims
print "Gamma correction took %fs per image" % ((time()-tic)/24.0)
plot_grid(ims, savepath + 'gamma.png')
sdsd

############################################
# ROTATIONS
tic = time()
rots = [aug.random_rotation(im, sd=10, **newcrop) for _ in range(24)]
rots = [aug.randn_crop(im, sd=0, **newcrop) for im in rots]
ims = [cropped_im] + rots
print "Rotating took %fs per image" % ((time()-tic)/24.0)
plot_grid(ims, savepath + 'rotations.png')

############################################
# COLOUR TRANSFORMS
rgb_vals = cropped_im.transpose((2, 0, 1)).reshape((3, -1))
rgb_eigval, rgb_eigvec = eig(np.cov(rgb_vals - rgb_vals.mean(1)[:, None]))
rgb_eigvec, rgb_eigval, v = np.linalg.svd(
    rgb_vals - rgb_vals.mean(1)[:, None], full_matrices=False)
rgb_eigval = np.real(rgb_eigval)
rgb_eigval /= rgb_eigval.sum()

tic = time()