如標題所示,該功能tf.reshape((), (0))在 Eager 模式下運行良好。但是當我在圖形模式下使用它時,它會回傳:
ValueError: Shape must be rank 1 but is rank 0 for '{{node Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](Reshape/tensor, Reshape/shape)' with input shapes: [0], [].
任何人都可以幫助我解決此功能的問題。您可以在此處重現此錯誤。我想在 Tensorflow 的圖形模式下重新創建這段代碼(初始化)。mems提前致謝!!
編輯:因為我想澄清我的用例,所以我想將此 PyTorchtorch.empty(0)函式轉換為 Tensorflow(在急切模式和圖形模式下都可以正常作業)。
uj5u.com熱心網友回復:
可能與此錯誤有關。嘗試這樣的事情:
@tf.function
def test_graph():
x = tf.reshape((), (0, ))
return x
b = test_graph()
b
#<tf.Tensor: shape=(0,), dtype=float32, numpy=array([], dtype=float32)>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/487676.html
