2017-02-10 178 views

回答

5

您可以使用tf.strided_slicetf.reverse

例如,

import tensorflow as tf 

img = tf.reshape(tf.range(30), [2, 5, 3]) 

# the following two lines produce equivalent result: 
img_channel_swap = img[..., ::-1] 
img_channel_swap_1 = tf.reverse(img, axis=[-1]) 

注意的tf.reverse所述API是從tensorflow R1.0改變。

1

假設通道是最後一個維度。

channels = tf.unstack (image, axis=-1) 
image = tf.stack ([channels[2], channels[1], channels[0]], axis=-1)