Reputation: 125
I am getting the following error while running my tensorflow code:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/tensor_shape.py", line 579, in merge_with
new_dims.append(dim.merge_with(other[i]))
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/tensor_shape.py", line 138, in merge_with
self.assert_is_compatible_with(other)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/tensor_shape.py", line 111, in assert_is_compatible_with
other))
ValueError: Dimensions 5 and 4 are not compatible
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gradients_impl.py", line 602, in gradients
in_grad.set_shape(t_in.get_shape())
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 407, in set_shape
self._shape = self._shape.merge_with(shape)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/tensor_shape.py", line 582, in merge_with
raise ValueError("Shapes %s and %s are not compatible" % (self, other))
ValueError: Shapes (?, 5, 15, 1) and (?, 4, 15, 1) are not compatible
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "experiment.py", line 65, in <module>
batches_per_lot=batches_per_lot, sigma=dp_sigma, dp=dp)
File "/home/srikrishna/Research/RGAN_kinect/RGAN_forecasting/model.py", line 247, in GAN_solvers
G_solver = tf.train.AdamOptimizer().minimize(G_loss_mean_over_batch, var_list=generator_vars)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/optimizer.py", line 343, in minimize
grad_loss=grad_loss)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/optimizer.py", line 414, in compute_gradients
colocate_gradients_with_ops=colocate_gradients_with_ops)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gradients_impl.py", line 609, in gradients
% (op.name, i, t_in.shape, in_grad.shape))
ValueError: Incompatible shapes between op input and calculated input gradient. Forward operation: generator/conv2d_transpose_1. Input index: 2. Original input shape: (?, 4, 15, 1). Calculated input gradient shape: (?, 5, 15, 1)
I am trying to use some convolution and conv2d_transpose. The error is coming from the conv2d_transpose layer during the minimize operation. Unsure as to why it is occurring. Here is how I built the network:
deconv1 = tf.nn.conv2d_transpose(output_3d, tf.get_variable('dw1', shape=[4, 4, 1, 1], initializer=tf.random_normal_initializer()),
strides=[1, 2, 3, 1], output_shape=[-1, 4, 15, 1])
de_relu1 = tf.nn.relu(deconv1, 'de_relu1')
deconv2 = tf.nn.conv2d_transpose(de_relu1, tf.get_variable('dw2', shape=[5, 5, 1, 1], initializer=tf.random_normal_initializer()),
strides=[1, 4, 5, 1], output_shape=[-1, 20, 75, 1])
de_relu2 = tf.nn.relu(deconv2, 'de_relu2')
I am using tensorflow 1.4.1
Upvotes: 3
Views: 3945
Reputation: 125
Okay, so it turns out that I was interpreting the error the wrong way. The problem was that the output shape I was giving for deconv2 was incorrect. Turns out the shape validation for conv2d_transpose is done during the forward propagation step due to the way conv2d_transpose is implemented in tensorflow.
Changing strides = [1, 4, 5, 1]
to strides=[1, 5, 5, 1]
made it work fine.
Upvotes: 6