2017-06-23 99 views
1

當我宣佈這樣我的變量:Tensorflow形狀必須是1級,但是等級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) 

回答

2

x = tf.Variable([len(_ELEMENT_LIST), 4], dtype=tf.float32) tf.Variable的第一個參數是變量的初始值,所以在上聲明x是具有值的變量[長度(_ELEMENT_LIST),4],和形狀的它的秩爲1。

x = tf.get_variable("x", [len(_ELEMENT_LIST), 4]) tf.get_variable第二個參數是可變的形狀,所以變量X的形狀的秩是2。

相關問題