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

Tensorflow has many transformations that can be applied to 3D tensors representing images (height, width, depth), for example, tf.image.rot90() or tf.image.random_flip_left_right() .

I know that they are intended for use with queues, therefore, the fact that they work with only one image.

But would there be a way to vectorize ops to convert a 4D tensor ([batch_size, height, width, depth]) to a tensor of the same size with op applied in the first size pattern without explicitly passing through them with tf.while_loop() ?

( EDIT: Regarding rot90() , the smart hack taken from numpy rot90 should have done:

 rot90=tf.reverse(x,tf.convert_to_tensor((False,False,True,False))) rot90=tf.transpose(rot90,([0,2,1,3]) 

EDIT 2: It turns out this question has already been asked quite a few times ( one example ), it seems that map_fn is the way to go if you want an optimized version. I already saw this, but I forgot. I think this makes this question a duplicate ...

However, for a random op or a more complex op, it would be nice to have a common method for vectorizing existing functions ...)

+5
source share
1 answer

Try tf.map_fn .

 processed_images = tf.map_fn(process_fn, images) 
+5
source

Source: https://habr.com/ru/post/1259393/


All Articles