5

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.

tf.image.random_flip_left_right(input_image_data)

That said, this function expects a tensor (image) of shape:

(width, height, channels)

But I have multiple images such as:

(batch_size, width, height, channels)

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?

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.

Any suggestion appreciated!

Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
Guillaume Chevalier
  • 9,613
  • 8
  • 51
  • 79
  • I guess those methods were originally developed to use with queues as with cifar10 example in Tensorflow website. – jeandut Sep 19 '16 at 14:03
  • [the link](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/cifar10/cifar10_input.py) – jeandut Sep 19 '16 at 14:04
  • Thanks, in fact I already have looked at it, but I would like to use a simpler pipeline for my current project. There should be a way for sure to go from 4D to 3D to then combine again to 4D within the tensor graph/session. – Guillaume Chevalier Sep 19 '16 at 15:29
  • Yes queues can be a pain to manage in big pipelines even though TF made them simple to use. I would be interested if you find something to do without. – jeandut Sep 19 '16 at 19:09

1 Answers1

0

You would have to use something like tf.pack and tf.unpack or tf.gather and tf.concatenate to convert from your 4D array to your 3D array.

Depending upon how your loading your data you can do the processing in numpy. Another alternative is to process each image before you put it into a batch.

Let me know if you need an explanation for how tf.pack or the others work.

Steven
  • 5,134
  • 2
  • 27
  • 38