Skip to content

Instantly share code, notes, and snippets.

@zaidalyafeai
Created September 6, 2018 21:55
Show Gist options
  • Save zaidalyafeai/6ce0c87cf86138f1457790dbd27914b0 to your computer and use it in GitHub Desktop.
Save zaidalyafeai/6ce0c87cf86138f1457790dbd27914b0 to your computer and use it in GitHub Desktop.
def transform(image, scale):
r = image
if a.flip:
r = tf.image.random_flip_left_right(r, seed=seed)
# area produces a nice downscaling, but does nearest neighbor for upscaling
# assume we're going to be doing downscaling here
r = tf.image.resize_images(r, [scale[0], scale[0]], method=tf.image.ResizeMethod.AREA)
offset = tf.cast(tf.floor(tf.random_uniform([2], 0, tf.cast(scale[0], dtype=tf.float32) - CROP_SIZE + 1, seed=seed)), dtype=tf.int32)
if a.scale_size > CROP_SIZE:
r = tf.image.crop_to_bounding_box(r, offset[0], offset[1], CROP_SIZE, CROP_SIZE)
elif a.scale_size < CROP_SIZE:
raise Exception("scale size cannot be less than crop size")
return r
scale = tf.random_uniform([1], minval=286, maxval=300, dtype=tf.int32)
with tf.name_scope("input_images"):
input_images = transform(inputs, scale)
with tf.name_scope("target_images"):
target_images = transform(targets, scale)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment