jean jean - 1 year ago 93
Python Question

Is there a way to efficiently vectorize Tensorflow ops on images?

Tensorflow has a great deal of transformations that can be applied to 3D-tensors representing images ([height, width, depth]) like

for example.

I know that they are meant to be used with queues hence the fact that they operate on only one image.

But would there be a way to vectorize the ops to transform 4D-tensor ([batch_size,height,width,depth]) to same size tensor with op applied image-wise along the first dimension without explicitely looping through them with

(EDIT : Regarding
a clever hack taken from numpy rot90 would be to do:


EDIT 2: It turns out this question has already been answered quite a few times it seems
is the way to go: same question. I had already seen it but I forgot I guess this makes this question a duplicate I will close it then.

However for random op or more complex op it would be nice to have a generic method to vectorize existing functions...)

Answer Source

Try tf.map_fn.

processed_images = tf.map_fn(process_fn, images)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download