gpt4 book ai didi

python - Tensorflow Shape 必须为 1 级,但为 2 级

转载 作者:行者123 更新时间:2023-12-01 02:51:32 25 4
gpt4 key购买 nike

当我像这样声明变量时:

x = tf.Variable([len(_ELEMENT_LIST), 4], dtype=tf.float32)

我收到以下错误:

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):

当我这样做时:

x = tf.get_variable("x", [len(_ELEMENT_LIST), 4])

有效

我正在尝试使用 concat 计算张量。

tf.concat([
x, features["y"],
features["z"]
], 1)

最佳答案

x = tf.Variable([len(_ELEMENT_LIST), 4], dtype=tf.float32)

tf.Variable的第一个参数是变量的初始值,所以上面的语句中x是一个值为 [len(_ELEMENT_LIST), 4] 的变量,其形状等级为1。

x = tf.get_variable("x", [len(_ELEMENT_LIST), 4])

tf.get_variable的第二个参数是Variable的形状,所以Variable X的形状的等级是2。

关于python - Tensorflow Shape 必须为 1 级,但为 2 级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44711166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com