1

我正在使用張量流來構建卷積神經網絡。給定形狀的張量(無,16,16,4,192),我想要執行轉置卷積,導致形狀(無,32,32,7,192)。轉置卷積(反捲積)算法

[2,2,4,192,192]的篩選器大小和[2,2,1,1,1]的步幅會產生我想要的輸出形狀嗎?

+0

會發生什麼事,如果你嘗試了嗎? – mrry

回答

1

是的,你幾乎是正確的。

一個次要校正是tf.nn.conv3d_transpose預計NCDHWNDHWC或輸入格式(你看上去是NHWDC)和所述過濾器的形狀預期爲[depth, height, width, output_channels, in_channels]。這會影響尺寸在filterstride順序:

# Original format: NHWDC. 
original = tf.placeholder(dtype=tf.float32, shape=[None, 16, 16, 4, 192]) 
print original.shape 

# Convert to NDHWC format. 
input = tf.reshape(original, shape=[-1, 4, 16, 16, 192]) 
print input.shape 

# input shape: [batch, depth, height, width, in_channels]. 
# filter shape: [depth, height, width, output_channels, in_channels]. 
# output shape: [batch, depth, height, width, output_channels]. 
filter = tf.get_variable('filter', shape=[4, 2, 2, 192, 192], dtype=tf.float32) 
conv = tf.nn.conv3d_transpose(input, 
           filter=filter, 
           output_shape=[-1, 7, 32, 32, 192], 
           strides=[1, 1, 2, 2, 1], 
           padding='SAME') 
print conv.shape 

final = tf.reshape(conv, shape=[-1, 32, 32, 7, 192]) 
print final.shape 

,輸出:

(?, 16, 16, 4, 192) 
(?, 4, 16, 16, 192) 
(?, 7, 32, 32, 192) 
(?, 32, 32, 7, 192)