2016-11-19 33 views
0

我正在處理涉及刪除列的圖像集羣問題。我能想到的唯一方法是使用tf.concat來連接兩張原始張量和一些空白。我必須多次這樣做,我擔心這可能會很慢。有一個更好的方法嗎?有沒有更好的方法去除張量中的張量?

new_tensor = tf.concat(1, [tf.slice(data, [0, 0, 0], [to_remove - 1, image_size, 1]), tf.slice(data, [to_remove, 0, 0], [image_size - to_remove - 1, image_size, 1]), tf.zeros([image_size, 1], tf.float32)])

+0

你可以粘貼你的代碼,讓其他人可以理解你的意圖嗎? – yuefengz

回答

0

您可以使用tf.gather,哪個更好對應於你正在嘗試做的,但說實話我不知道這是否是任何更快:

ind = tf.concat(0, [tf.range(0, to_remove), tf.range(to_remove + 1, data.get_shape()[0])]) 
removed = tf.gather(ind, data) 
zero_filled = tf.concat(0, [removed, tf.zeros([image_size, 1], tf.float32)]) 

順便說一下,在slice您可以使用-1來表示「直到此維度結束」。

相關問題