导入 keras.backend 引起的 image_dim_ordering 问题解决办法
1.AttributeError: module ‘keras.backend’ has no attribute ‘image_dim_ordering’产生的原因是:导入backend 是从tf导入进来的,比如import tensorflow.keras.backend as K而且 tensorflow 与 keras 版本也不一致,会引起上述问题解决方案1:import tensorfl
·
1.AttributeError: module ‘keras.backend’ has no attribute ‘image_dim_ordering’
产生的原因是:导入backend 是从tf导入进来的,比如
import tensorflow.keras.backend as K
而且 tensorflow 与 keras 版本也不一致,会引起上述问题
- 解决方案1:
import tensorflow.python.keras.backend as K
K.common.image_dim_ordering()
采用这种方式会产生get_graph等其它问题,比如:
module ‘tensorflow.python.keras.backend’ has no attribute ‘get_graph’
- 解决方案2:
backend 导入不从 tensorflow 导入,直接使用 keras 导入,可以避免很多其它的问题
即:import keras.backend as K
含义就是 在keras 与 tensorflow 版本不一致的时候,backend 的导入直接使用 keras 的,而不使用 tensorflow 的。其它的问题就是tf2.0 向下兼容 tf1.0 的部分代码,即所有的问题基本上都可以解决。
更多推荐



所有评论(0)