简体   繁体   English

Tensorflow Shape必须为1级但为2级

[英]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.

相关问题 TensorFlow 推荐者 - ValueError:形状必须为 2 级,但为 3 级 - TensorFlow Recommenders - ValueError: Shape must be rank 2 but is rank 3 Tensorflow:ValueError:Shape必须是等级2,但是等级3 - Tensorflow : ValueError: Shape must be rank 2 but is rank 3 Tensorflow: ValueError: Shape must be rank 4 but is rank 5 - Tensorflow: ValueError: Shape must be rank 4 but is rank 5 Tensorflow:optimizer.minimize()-“ ValueError:形状必须为0级,但为1级 - Tensorflow: optimizer.minimize() - "ValueError: Shape must be rank 0 but is rank 1 Tensorflow - ValueError:Shape必须为1,但对于'ParseExample / ParseExample'为0 - Tensorflow - ValueError: Shape must be rank 1 but is rank 0 for 'ParseExample/ParseExample' Tensorflow错误:形状必须为0级,但对于'cond_1 / Switch'为1级 - Tensorflow error: Shape must be rank 0 but is rank 1 for 'cond_1/Switch' Tensorflow:形状必须为5级,但'conv3D'为1级 - Tensorflow: shape must be rank 5 but is rank 1 for 'conv3D' Tensorflow错误“形状Tensorshape()必须具有等级1” - Tensorflow error “shape Tensorshape() must have rank 1” 形状必须是 2 级,但它是 1 级 - Shape must have rank 2 but it is rank 1 TensorFlow: Value Error Shape and Rank Do Not Match: ValueError: Shape (?, 128, 128, 2) must have rank 2 - TensorFlow: Value Error Shape and Rank Do Not Match: ValueError: Shape (?, 128, 128, 2) must have rank 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM