python - 转置卷积(反卷积)算法

标签 python machine-learning tensorflow conv-neural-network deconvolution

我正在使用 tensorflow 构建卷积神经网络。给定形状 (none, 16, 16, 4, 192) 的张量,我想执行转置卷积,得到形状 (none, 32, 32, 7, 192)。

过滤器大小为 [2,2,4,192,192] 和步长为 [2,2,1,1,1] 会产生我想要的输出形状吗?

最佳答案

是的,你几乎是对的。

一个小的更正是 tf.nn.conv3d_transpose 需要 NCDHWNDHWC 输入格式(您的似乎是 NHWDC),滤波器形状预计为[深度、高度、宽度、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)

关于python - 转置卷积(反卷积)算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46735034/

相关文章:

machine-learning - 模糊逻辑运算符

python - TPOT:多类数据分类失败

tensorflow - 如何在 tensorflow 中实现像 keras 这样的子样本?

tensorflow :ValueError:用序列设置数组元素

python - 从数据框中散点绘制多列

python - OpenCV 3.1 重映射函数类型值错误

machine-learning - 二元组和一元组文本特征提取有什么区别

tensorflow - 用 tensorflow custom_gradient 定义 jacobian

python - 带有 djorm-ext-pgfulltext 的 Django Postgres pg_trgm 模块用于全文搜索

python - 如果整个字符串包含 Pandas 中的子字符串,则替换整个字符串