def random_image_scaling(self, image, label):
"""Randomly scales the images between 0.5 to 1.5 times the original size.
Args:
img: Training image to scale.
label: Segmentation mask to scale.
"""
scale = tf.random_uniform(
[1], minval=0.5, maxval=1.5, dtype=tf.float32, seed=None)
h_new = tf.to_int32(tf.multiply(tf.to_float(tf.shape(image)[0]), scale))
w_new = tf.to_int32(tf.multiply(tf.to_float(tf.shape(image)[1]), scale))
new_shape = tf.squeeze(tf.stack([h_new, w_new]), axis=1)
image = tf.image.resize_images(image, new_shape)
label = tf.image.resize_nearest_neighbor(
tf.expand_dims(label, 0), new_shape)
label = tf.squeeze(label, axis=0)
return image, label
评论列表
文章目录