1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| def transform_perspective(image): def x_y_1(): x = tf.random_uniform([], minval=-0.3, maxval=-0.15) y = tf.random_uniform([], minval=-0.3, maxval=-0.15) return x, y def x_y_2(): x = tf.random_uniform([], minval=0.15, maxval=0.3) y = tf.random_uniform([], minval=0.15, maxval=0.3) return x, y
def trans(image): ran = tf.random_uniform([]) x = tf.random_uniform([], minval=-0.3, maxval=0.3) x_com = tf.random_uniform([], minval=1-x-0.1, maxval=1-x+0.1)
y = tf.random_uniform([], minval=-0.3, maxval=0.3) y_com = tf.random_uniform([], minval=1-y-0.1, maxval=1-y+0.1)
transforms = [x_com, x,0,y,y_com,0,0.00,0]
ran = tf.random_uniform([]) image = tf.cond(ran<0.5, lambda:tf.contrib.image.transform(image,transforms,interpolation='NEAREST', name=None), lambda:tf.contrib.image.transform(image,transforms,interpolation='BILINEAR', name=None)) return image
ran = tf.random_uniform([]) image = tf.cond(ran<1, lambda: trans(image), lambda:image)
return image
|