Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gaceladri opened this issue May 3, 2018 · 6 comments

Comments

@gaceladri
Copy link

gaceladri commented May 3, 2018

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
Copy link
Owner

biuyq commented May 5, 2018

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
Copy link
Author

gaceladri commented May 9, 2018

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

@biuyq
Copy link
Owner

biuyq commented May 11, 2018

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

@gaceladri
Copy link
Author

@biuyq
It worked. Thanks a lot!

And thanks a lot for your awesome work also.

Regards.

@qinhuangdaoStation
Copy link

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

@aashana94
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants