biuyq / CT-GAN

48 stars 16 forks source link

ValueError: Shape must be rank 2 but is rank 1 for 'MatMul' (op: 'MatMul') with input shapes: [2048], [2048,1008]. #5

Open gaceladri opened 6 years ago

gaceladri commented 6 years ago

Hi,

Excellent work. I am trying to run CT_gan_cifar_resnet.py and I am getting the next error:

Traceback (most recent call last):
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 686, in _call_cpp_shape_fn_impl
    input_tensors_as_shapes, status)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 516, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be rank 2 but is rank 1 for 'MatMul' (op: 'MatMul') with input shapes: [2048], [2048,1008].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "CT_gan_cifar_resnet.py", line 14, in <module>
    import tflib.inception_score
  File "/media/proto/942ea58f-5397-4c08-aa32-b507c86d1c07/IA/GANs/CT-GAN/CT-GANs/tensorflow_generative_model/tflib/inception_score.py", line 94, in <module>
    _init_inception()
  File "/media/proto/942ea58f-5397-4c08-aa32-b507c86d1c07/IA/GANs/CT-GAN/CT-GANs/tensorflow_generative_model/tflib/inception_score.py", line 90, in _init_inception
    logits = tf.matmul(tf.squeeze(pool3), w)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/ops/math_ops.py", line 2108, in matmul
    a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/ops/gen_math_ops.py", line 4209, in mat_mul
    name=name)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 3292, in create_op
    compute_device=compute_device)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 3332, in _create_op_helper
    set_shapes_for_outputs(op)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2496, in set_shapes_for_outputs
    return _set_shapes_for_outputs(op)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2469, in _set_shapes_for_outputs
    shapes = shape_func(op)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2399, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn
    require_shape_fn)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl
    raise ValueError(err.message)
ValueError: Shape must be rank 2 but is rank 1 for 'MatMul' (op: 'MatMul') with input shapes: [2048], [2048,1008].

Before this I had to change the line 88 in inception_score.py:

        o._shape = tf.TensorShape(new_shape)  
        to:
        o.set_shape = tf.TensorShape(new_shape)

to fix this:

Traceback (most recent call last):
  File "CT_gan_cifar_resnet.py", line 14, in <module>
    import tflib.inception_score
  File "/media/proto/942ea58f-5397-4c08-aa32-b507c86d1c07/IA/GANs/CT-GAN/CT-GANs/tensorflow_generative_model/tflib/inception_score.py", line 94, in <module>
    _init_inception()
  File "/media/proto/942ea58f-5397-4c08-aa32-b507c86d1c07/IA/GANs/CT-GAN/CT-GANs/tensorflow_generative_model/tflib/inception_score.py", line 88, in _init_inception
    o._shape = tf.TensorShape(new_shape)
  File "/home/proto/anaconda3/envs/tensor/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 395, in _shape
    "Tensor._shape cannot be assigned, use Tensor.set_shape instead.")
ValueError: Tensor._shape cannot be assigned, use Tensor.set_shape instead.

python 3.5

biuyq commented 6 years ago

Hi, The problem may be caused by the version of your Tensorflow and python are not the version I have. You may replace : score_tensor = tf.matmul(hidden, Ws) by: score_tensor =tf.reduce_sum(tf.mul(tf.cast(hidden,tf.float32),Ws),reduction_indices=1) of the related lines. Or, you may just use environment the same as mine for simplicity.

gaceladri commented 6 years ago

Hi @biuyq, The problem that I have is in logits = tf.matmul(tf.squeeze(pool3), w) I can not see score_tensor

biuyq commented 6 years ago

@gaceladri you may try logits = tf.matmul(tf.squeeze(pool3, [1, 2]), w) to replace logits = tf.matmul(tf.squeeze(pool3), w)

gaceladri commented 6 years ago

@biuyq It worked. Thanks a lot!

And thanks a lot for your awesome work also.

Regards.

qinhuangdaoStation commented 6 years ago

tf.reshape(input, shape=[x,x,x,x]) try to convert the shape

aashana94 commented 4 years ago

@gaceladri you may try logits = tf.matmul(tf.squeeze(pool3, [1, 2]), w) to replace logits = tf.matmul(tf.squeeze(pool3), w)

I am getting out of memory error and the script gets killed