我想做图像增强,例如,在 tensorflow 中旋转随机角度。在每个批处理中,我想为每个图像旋转不同的随机角度。我可以通过使用 tf.contrib.image.rotate
到 image_batch
并随机生成角度张量来实现:
radian = tf.random_uniform(
(batch_size),
minval=-ROT_TH,
maxval=ROT_TH,
dtype=tf.float32,
seed=None,
name=None
)
rotated_batch = tf.contrib.image.rotate(image_batch, radian)
但是,如果我使用 allow_smaller_final_batch=True
构建批处理,则 batch_size
毫无用处,因为 image_batch
将没有固定的批处理大小。并且旋转会失败,因为弧度和image_batch的N维不一样。
如何修复它?
最佳答案
我没有批量旋转图像,而是对 image_queue.deque()
中的图像应用相同的旋转:
images = load_images(filenames, options)
radian = tf.random_uniform([len(images)], ...)
images = tf.contrib.image.rotate(images, radian)
image_batch = tf.train.batch_join([images, filenames],
enqueue_many=True, allow_smaller_final_batch=True,
batch_size=WHATEVER)
关于python - tensorflow 中的批量图像增强,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52575674/