TensorFlow "tf.image" functions on an image batch
<p>I would like to use this function in TensorFlow, however it operates on 3D tensors rather than 4D tensors: I have an outer dimension of batch_size. </p>

<pre><code>tf.image.random_flip_left_right(input_image_data)
</code></pre>

<p>That said, this function expects a tensor (image) of shape:</p>

<pre><code>(width, height, channels)
</code></pre>

<p>But I have multiple images such as: </p>

<pre><code>(batch_size, width, height, channels)
</code></pre>

<p>How could I map the random flip function to each image in my batch size and get as an output a tensor with the same 4D shape I already have? </p>

<p>My guess is that it would need a reshape at the entry of the function and a reshape after the function, but I am not sure whether or not this would break the data's structure and blend together images in the batch when applying the mirror. Moreover, this approach would do a single randomization on the whole batch rather than on a per-image basis. </p>

<p>Any suggestion appreciated! </p>

<p>You can use map_fcn as described in this post <a href="http://stackoverflow.com/questions/38920240/tensorflow-image-operations-for-batches">TensorFlow image operations for batches</a></p>

<p>result = tf.map_fn(lambda img: tf.image.random_flip_left_right(img), images)</p>

python image-processing machine-learning computer-vision tensorflow