0
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
  • I'm using Python3.6 with TensorFlow 1.5.1 and my issue is [Report Error]ValueError: Incompatible shapes between op input and calculated input gradient. conv2d_transpose any idea how to solve it? – Maryam Shah Sep 15 '20 at 16:08

1 Answers1

0

The error has been resolved. The problem was with the strides. Someone here already reported this issue and it really helped me to solve this problem Detail description of this problem