如何将随机图像几何变换同时应用于多个图像? [英] How to apply random image geometric transformation simultaneously to multiple images?

查看:28
本文介绍了如何将随机图像几何变换同时应用于多个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 tensorflow 和完全卷积网络对图像进行回归.我想通过随机翻转/旋转来增加数据,但如何将它们同时应用于输入和输出图像张量?

I use tensorflow and fully convolutional network to do regression on image. I want to augment data by random flip/rotation, but how can I apply them simultaneously to input and output image tensor?

推荐答案

你说得对,像 tf.random_flip_left_right 这样的函数只有在没有协变变量时才能使用.如果有,例如,如果您的输出是标签图像,那么您需要对所有标签应用相同的随机操作.

You're right, functions like tf.random_flip_left_right can be used only if there are no covariant variables. If there are, for example if your output is an image of labels, then you need to apply the same random operation to all of them.

我看到了两种方法:

  1. 您基本上重写了随机操作以使用多个张量.例如,要替换 tf.random_flip_left_right,您可以使用

coin = tf.less(tf.random_uniform((), 0., 1.), 0.5)
im1 = tf.cond(coin, lambda: tf.flip_left_right(im1), lambda: im1)
im2 = tf.cond(coin, lambda: tf.flip_left_right(im2), lambda: im2)
...

  • 在随机操作之前将所有张量堆叠在一起:

  • You stack all your tensors together before the random op:

    all_im = tf.stack([im1, im2,...], axis=2)
    all_im = tf.random_flip_left_right(all_im)
    [im1, im2, ...] = tf.split(all_im, [im1.shape[2], im2.shape[2], ...], axis=2)
    

    仅当所有张量具有相同的空间范围时,第二种解决方案才有效.

    This second solution works only if all of the tensors have the same spatial range.

    这篇关于如何将随机图像几何变换同时应用于多个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆