2017-05-08 75 views

回答

1

沒問題,我們仍然可以使用tf.image.resize_images。我們需要做的是發送數據到tf.image.resize_images它需要的形狀是張量(4D)。

# First reorder your dimensions to place them where tf.image.resize_images needs them 
transposed = tf.transpose(yourData, [0,3,1,2,4]) 

# it is now [5,10,50,50,256] 
# but we need it to be 4 dimensions, not 5 
reshaped = tf.reshape(transposed, [5*10,50,50,256]) 

# and finally we use tf.image.resize_images 
new_size = tf.constant([ 100 , 100 ]) 
resized = tf.image.resize_images(reshaped , new_size) 

# your data is now [5*10,100,100,256] 
undo_reshape = tf.reshape(resized, [5,10,100,100,256]) 

# it is now [5,10,100,100,256] so lastly we need to reorder it 
undo_transpose = tf.transpose(undo_reshape, [0,2,3,1,4]) 

# your output is now [5,100,100,10,256] 
+0

感謝您的回答。它太聰明瞭。請問爲什麼你在第一個地方調整張量?首先我們將[5,50,50,10,256]張量重塑爲[5,50,50,10 * 256]張量,並將其重新調整爲[5,100,100,10 * 256]後再重塑爲[5,100,100 ,10256]所以,我們可以避免額外的轉置。 –

+0

Dooh!你是對的。那會更簡單! – Wontonimo