0

我读了这篇关于使用“调整卷积大小”而不是使用神经网络生成图像的“反卷积”(即转置卷积)方法。很明显,这是如何以1的步幅大小工作的,但是如何实现它的步长大于1?您是否只能通过调整卷积大小来获得步幅1?

这是我如何在TensorFlow中实现它。注意:这是自编码器网络的解码器部分中的第二个“解卷积”层。

h_d_upsample2 = tf.image.resize_images(images=h_d_conv3, 
             size=(int(self.c2_size), int(self.c2_size)), 
             method=tf.image.ResizeMethod.NEAREST_NEIGHBOR) 
h_d_conv2 = tf.layers.conv2d(inputs=h_d_upsample2, 
          filters=FLAGS.C2, 
          kernel_size=(FLAGS.c2_kernel, FLAGS.c2_kernel), 
          padding='same', 
          activation=tf.nn.relu) 

回答

0

我们使用transposed convolution的原因是为了增加activation maps的分辨率。现在,如果您想用conv2d with stride代替它,则当您的目标是提高输出分辨率时,您会降低分辨率。

尽管如此,您可以使用strides,但您需要应用更大的缩放因子才能达到所需的分辨率。

0

调整图像大小对于网络中间层来说确实不是一个可行的选项。你可以试试conv2d_transpose

你将如何实现它的步幅大于1?

# best practice is to use the transposed_conv2d function, this function works with stride >1 . 
# output_shape_width_height = stride * input_shape_width_height 
# input_shape = [32, 32, 48], output_shape = [64, 64, 128] 
stride = 2 
filter_size_w =filter_size_h= 2 
shape = [filter_size_w, filter_size_h, output_shape[-1], input_shape[-1]] 
w = tf.get_variable(
    name='W', 
    shape=shape, 
    initializer=tf.contrib.layers.variance_scalling_initializer(), 
    trainable=trainable) 

output = tf.nn.conv2d_transpose(
     input, w, output_shape=output_shape, strides=[1, stride, stride, 1]) 
相关问题