2016-08-17 35 views
3

我有一個簡單的問題tf.py_func函數。Tensorflow:Py_func返回未知形狀

我有形狀(1,224,224,3)的圖像張量my_img。爲了測試py_func,我將張量輸入一個python函數return_tf,該函數應該返回相同的張量(按照文檔轉換爲numpy數組後)。

下面的代碼:

def return_tf(x): 
    return np.array(x) 

test = tf.py_func(return_tf,[my_img],[tf.float32]) 

但是,當我檢查叫test返回的張量的形狀,我得到:

tf.Tensor 'PyFunc:0' shape=unknown dtype=float32 

我也無法對張量運行eval(),因爲我收到錯誤:

AttributeError: 'list' object has no attribute 'eval'. 

任何人都知道我該如何修復te由tf.py_func返回張量的nsor形狀?

回答

4

剛剛發現一個解決..因爲py_func返回tensorflow名單,我可以做FF:

test = tf.reshape(tf.concat(1, test), [ <<a shape>> ]) 

得到張量所需的形狀

相關問題