[英]Tensorflow Shape must be rank 1 but is rank 2
When I declare my variable like this: 当我这样声明我的变量时:
x = tf.Variable([len(_ELEMENT_LIST), 4], dtype=tf.float32)
I get the following error: 我收到以下错误:
E0622 20:04:25.241938 21886 app.py:544] Top-level exception: Shape must be rank 1 but is rank 2 for 'input_layer/concat' (op: 'ConcatV2') with input shapes: [5], [5,1], [5,1], [].
E0622 20:04:25.252672 21886 app.py:545] Traceback (most recent call last):
When I do it like this: 当我这样做时:
x = tf.get_variable("x", [len(_ELEMENT_LIST), 4])
It works 有用
I'm trying to compute Tensors using concat. 我正在尝试使用concat计算张量。
tf.concat([
x, features["y"],
features["z"]
], 1)
x = tf.Variable([len(_ELEMENT_LIST), 4], dtype=tf.float32)
the first parameter of tf.Variable
is the initial value of the variable, so in the upper statement x
is a Variable with value [len(_ELEMENT_LIST), 4]
, and it's rank of shape is 1. tf.Variable
的第一个参数是变量的初始值,因此在上面的语句中x
是值[len(_ELEMENT_LIST), 4]
的变量,其形状等级为1。
x = tf.get_variable("x", [len(_ELEMENT_LIST), 4])
the second parameter of tf.get_variable
is the shape of Variable, so the rank of shape of Variable X is 2. tf.get_variable
的第二个参数是变量的形状,因此变量X的形状等级为2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.