[英]Does the tf.nn.conv2d_transpose transpose the filter?
I have a trained feedforward CNN.我有一个训练有素的前馈 CNN。 The shape of filter is [height, width, in_channels, out_channels].过滤器的形状是 [height, width, in_channels, out_channels]。 And i want to use those filter to do deconv, we know that the deconv process needs the transpose of the filter.Do i need to transpose the filter mannuly, or the TF
will do it inside the tf.nn.conv2d_transpose
and all we need to do is pass the trained filter to tf.nn.conv2d_transpose
?我想利用这些过滤器做deconv,我们知道deconv过程需要filter.Do的转置我需要mannuly置过滤器,或TF
会做内部tf.nn.conv2d_transpose
和我们所需要的要做的是将经过训练的过滤器传递给tf.nn.conv2d_transpose
?
We needn't to transpose the filter manually.In general, wo organize our code in the following way.我们不需要手动转置过滤器。一般来说,我们按照以下方式组织我们的代码。
stride = [1,1,1,1]
conv1W = tf.Variable(tf.random.normal[4,4,3,20])
conv1 = tf.nn.conv2d(input, conv1W, strides=stride, padding='SAME')
conv1 = tf.nn.relu(conv1)
Then, do the deconv process然后,做 deconv 过程
deconv1 = tf.nn.conv2d_transpose(conv1, conv1W, output_shape=[batch_size,output_height, output_width, output_channels],strides=stride)
res = tf.nn.relu(deconv1)
The res
is the result of deconv process. res
是 deconv 过程的结果。
In a word, the filter
and stride
using in deconv process is the same as the filter
and stride
using in conv process.总之,所述filter
和stride
使用deconv过程是一样的filter
和stride
使用CONV过程。
According to tensorflow documentation, you have to change the filter shape.根据 tensorflow 文档,您必须更改过滤器形状。 Here I will put how this fact has described in latest TF documentation 1.9.在这里,我将在最新的 TF 文档 1.9 中介绍这一事实。
For the tf.nn.conv_2d the filter variable should be - A 4-D tensor of shape [filter_height, filter_width, in_channels, out_channels ]对于 tf.nn.conv_2d,过滤器变量应该是 -形状为 [filter_height, filter_width, in_channels, out_channels ] 的4-D 张量
For the tf.nn.conv_2d_transpose the filter variable should be - A 4-D tensor of shape [filter_height, filter_width, out_channels,in_channels ]对于 tf.nn.conv_2d_transpose,过滤器变量应该是 -形状为 [filter_height, filter_width, out_channels,in_channels ] 的4-D 张量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.