2016-02-11 189 views
2

我試圖在可變大小的批量數據上使用​​op。然而,看來我需要設置output_shape參數如下:如何在tensorflow中爲deconv2d的output_shape參數提供變量batch_dim?

tf.nn.deconv2d(x, filter, output_shape=[12, 24, 24, 5], strides=[1, 2, 2, 1], 
       padding="SAME") 

爲什麼​​採取固定output_shape?有沒有辦法指定一個變量批量維度?如果輸入批量大小變化會發生什麼?

回答

4

N.B.​​將在下一個版本的TensorFlow(0.7.0)中被稱爲tf.nn.conv2d_transpose()

output_shape參數​​接受計算Tensor作爲其值,該參數使您可以指定動態形狀。例如,假設您輸入的定義如下:

# N.B. Other dimensions are chosen arbitrarily. 
input = tf.placeholder(tf.float32, [None, 24, 24, 5]) 

...那麼對於一個特定步驟批量大小可以在運行時計算:

batch_size = tf.shape(input)[0] 

有了這個值,你就可以使用tf.pack()構建output_shape參數​​:

output_shape = tf.pack([batch_size, 24, 24, 5]) 

result = tf.nn.deconv2d(..., filter, output_shape=output_shape, 
         strides=[1, 2, 2, 1], padding='SAME') 
+1

在r0.12 tf.pack()已被棄用,tf.stack()是正確用法按照文檔:https://開頭WW w.tensorflow.org/versions/master/api_docs/python/array_ops/slicing_and_joining#pack –

相關問題