运算输入和计算的输入梯度之间的形状不兼容。 conv2d_transpose任何想法如何解决呢?

时间:2020-09-15 16:08:03

标签: python-3.x tensorflow

def deconv2d(input_, output_shape,
         k_h=5, k_w=5, d_h=2, d_w=2, stddev=0.02,
         name="deconv2d", with_w=False):
with tf.variable_scope(name):
    # filter : [height, width, output_channels, in_channels]

w = tf.get_variable('w',[k_h,k_w,output_shape [-1],input_.get_shape()[-1]], initializer = tf.random_normal_initializer(stddev = stddev))

    try:
        deconv = tf.nn.conv2d_transpose(input_, w, output_shape=output_shape,
                            strides=[1, d_h, d_w, 1])

    # Support for verisons of TensorFlow before 0.7.0
    except AttributeError:
        deconv = tf.nn.deconv2d(input_, w, output_shape=output_shape,
                            strides=[1, d_h, d_w, 1])

    biases = tf.get_variable('biases', [output_shape[-1]], initializer=tf.constant_initializer(0.0))
    deconv = tf.reshape(tf.nn.bias_add(deconv, biases), deconv.get_shape())

    if with_w:
        return deconv, w, biases
    else:
        return deconv

1 个答案:

答案 0 :(得分:0)

该错误已解决。问题出在大步向前。这里的某人已经报告了此问题,它确实帮助我解决了这个问题Detail description of this problem