问题描述
我正在尝试对可变大小的数据批量使用 tf.nn.deconv2d()
op。但是,看来我需要将 output_shape
参数设置如下:
I am trying to use the tf.nn.deconv2d()
op on a variable-sized batch of data. However, it appears that I need to set the output_shape
argument as follows:
tf.nn.deconv2d(x, filter, output_shape=[12, 24, 24, 5], strides=[1, 2, 2, 1],
padding="SAME")
为什么 tf.nn.deconv2d()
需要固定 output_shape
?有什么方法可以指定可变的批次尺寸吗?如果输入的批次大小不同,会发生什么情况?
Why does tf.nn.deconv2d()
take a fixed output_shape
? Is there any way to specify a variable batch dimension? What happens if the input batch size varies?
推荐答案
NB tf。 nn.deconv2d()
将被称为在下一版TensorFlow(0.7.0)中。
N.B. tf.nn.deconv2d()
will be called tf.nn.conv2d_transpose()
in the next release of TensorFlow (0.7.0).
tf.nn.deconv2d()
的 output_shape
参数接受计算出的 Tensor
作为其值,使您可以指定动态形状。例如,假设您的输入定义如下:
The output_shape
argument to tf.nn.deconv2d()
accepts a computed Tensor
as its value, which enables you specify a dynamic shape. For example, let's say your input is defined as follows:
# N.B. Other dimensions are chosen arbitrarily.
input = tf.placeholder(tf.float32, [None, 24, 24, 5])
...然后可以在运行时计算特定步骤的批处理大小:
...then the batch size for a particular step can be computed at runtime:
batch_size = tf.shape(input)[0]
使用此值,您可以构建 output_shape
使用tf.nn.deconv2d()参数/python/array_ops.html#pack rel = noreferrer> tf.pack()
:
With this value, you can then build the output_shape
argument to tf.nn.deconv2d()
using tf.pack()
:
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')
这篇关于如何在tensorflow的deconv2d的output_shape参数中给出变量batch_dim?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!