在tensorflow2运行代码出现此问题。

module ‘tensorflow’ has no attribute 'XXX’一般是tensorflow2和tensorflow1 不兼容问题。

问题解决办法:在tf后面加.compat.v1

事例1(module ‘tensorflow’ has no attribute ‘GraphDef’):

tensorflow1下:

tf.GraphDef()

tensorflow2下:

tf.compat.v1.GraphDef()

事例2(module ‘tensorflow’ has no attribute ‘Session’):

tensorflow1下:

tf.Session(graph=detection_graph) 

tensorflow2下:

tf.compat.v1.Session(graph=detection_graph) 
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐