AttributeError: module 'tensorflow' has no attribute 'Session'錯誤解決

在使用anaconda在windows先安裝完tensorflow 2.2.4之後,在使用

            import tensorflow as tf

tf.Session()的時候,運行完腳本會報如下錯誤:

                 AttributeError: module 'tensorflow' has no attribute 'Session'錯誤解決

經查看的得知是由於新的Tensorflow 2.0以上版本中已經移除了Session這一模塊,代碼改爲如下形式後錯誤解決:

               tf.compat.v1.Session()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章