Reputation: 1179
When I reshape a tensor, tf.reshape
as well as <Tensor>.shape
are unable to infer the shape.
If I understood this Issue correctly: https://github.com/tensorflow/tensorflow/issues/3311 , it should have been fixed.
Can anyone help me where I might be missing something?
import tensorflow as tf
sess = tf.InteractiveSession()
m = 100
n = 300
x = 123
y = 456
a = tf.get_variable(dtype=tf.int32, shape=[m, n, x], name="a")
b = tf.get_variable(dtype=tf.int32, shape=[m, n, y], name="b")
print(a.shape) # => (100, 300, 123)
print(b.shape) # => (100, 300, 456)
print(tf.shape(a)) # => Tensor("Shape_4:0", shape=(3,), dtype=int32)
print(tf.shape(b)) # => Tensor("Shape_5:0", shape=(3,), dtype=int32
c = tf.concat([a, b], axis=-1)
print(c.shape) # => (100, 300, 579)
print(tf.shape(c)) # = >Tensor("Shape:0", shape=(3,), dtype=int32)
s = tf.shape(c)
cc = tf.reshape(c, [s[0]*s[1], -1])
print(cc.shape) # => (?, ?)
print(tf.shape(cc)) # => Tensor("Shape_3:0", shape=(2,), dtype=int32)
Upvotes: 1
Views: 596
Reputation: 9426
I think you want to use:
s = c.get_shape().as_list()
or
s = c.shape.as_list()
I've never really used tf.shape()
myself, but when I use the above I receive the proper shape (30000, 579)
Upvotes: 1