AttributeError: module 'tensorflow' has no attribute 'reset_default_graph' 解決

問題如下:
在這裏插入圖片描述
AttributeError: module ‘tensorflow’ has no attribute ‘reset_default_graph’

上面是因爲安裝的Tensorflow 2不支持Tensorflow1的API而報的錯
,需要將導入模塊的部分進行更改,操作如下:

1,原本的代碼

import tensorflow as tf %這行代碼改成下面的兩行代碼

2,替換成如下代碼:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

3,可以了,不會報錯
在這裏插入圖片描述

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