Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 重塑失去了张量的形状_Tensorflow - Fatal编程技术网

Tensorflow 重塑失去了张量的形状

Tensorflow 重塑失去了张量的形状,tensorflow,Tensorflow,当我重塑张量时,tf.reformate和.shape都无法推断形状。 如果我正确理解了这个问题,它应该已经被修复了 有人能帮我找到我可能遗漏的地方吗? 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

当我重塑张量时,
tf.reformate
.shape
都无法推断形状。 如果我正确理解了这个问题,它应该已经被修复了

有人能帮我找到我可能遗漏的地方吗?

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)

我想你应该使用:

s = c.get_shape().as_list()

我自己从来没有真正使用过
tf.shape()
,但是当我使用上面的方法时,我收到了正确的形状
(30000579)

s = c.shape.as_list()