環境:
- tensorflow >=1.14
錯誤:
WARNING:tensorflow:From /Users/yuki//tf_test/test1.py:4: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.
錯誤分析:
爲了使TensorFlow在2.0版中更具簡便性,TF 2.0設計上沒有tf.Session。
TensorFlow 1.X要求用戶通過調用tf。* API手動將抽象語法樹(圖形)拼接在一起。然後,它要求用戶通過將一組輸出張量和輸入張量傳遞給session.run()調用來手動編譯抽象語法樹。
TensorFlow 2.0急切地執行(就像Python通常那樣),在2.0中,圖形和會話應該感覺像實現細節。
解決方式:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
或者
tf.compat.v1.Session() as session