AttributeError: module ‘tensorflow.python.keras.backend‘ has no attribute ‘get_graph‘的解决方案

  在使用keras搭建神经网络时,导入相关组件,常常会报错:

AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'


  遇到这样的问题,绝大多数时候是因为tensorflow和keras版本存在冲突,一种解决方案是导入keras的时候,使用tensorflow.keras,但是这样的办法不一定能每一次都成功,为了一次性解决问题,可以通过下面的网站查看不同tensorflow兼容的keras版本号,通过兼容版本解决问题:

https://docs.floydhub.com/guides/environments/

AttributeError: module ‘tensorflow.python.keras.backend‘ has no attribute ‘get_graph‘的解决方案_第1张图片

 

  小编在使用时遇到这样的问题,查看当前环境下安装的keras和tensorflow版本如下:

 

AttributeError: module ‘tensorflow.python.keras.backend‘ has no attribute ‘get_graph‘的解决方案_第2张图片

 

和网站上的版本信息对照发现,当前环境下使用的版本不能互相兼容,所以决定重新安装keras和tensorflow,为了提高下载的速率,采用镜像源进行安装:

AttributeError: module ‘tensorflow.python.keras.backend‘ has no attribute ‘get_graph‘的解决方案_第3张图片

  重新下载后,问题得到有效解决。

 

 

 

你可能感兴趣的:(AttributeError,keras,tensorflow)