解决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

猜你喜欢

转载自blog.csdn.net/Toky_min/article/details/106177087
今日推荐