簡體   English   中英

Tensorflow Shape必須為1級但為2級

[英]Tensorflow Shape must be rank 1 but is rank 2

當我這樣聲明我的變量時:

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的第二個參數是變量的形狀,因此變量X的形狀等級為2。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM