解決TensorFlow2.0與1.0版本不兼容的問題,如slim庫,contrib,placeholder等。

報錯

 

AttributeError: module 'tensorflow' has no attribute 'assign'

AttributeError: module 'tensorflow' has no attribute 'variable_scope'

等等..

 

 

走的彎路

 

很多說2.0版本棄用contrib,叫重裝低版本tf.


slim包不能用還下載了tf-slim 包,鏈接如下:

https://github.com/google-research/tf-slim

還有的說在tf2.0棄用的包整合到一個叫module的擴展包裏了...

 

 

解決辦法


使用如下兩句


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

​

替換原有的

import tensorflow as tf


————————————————
參考

https://blog.csdn.net/flowingfog/java/article/details/93597697

 

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