我一直在尝试将 keras 图像暗淡顺序从 tensorflow 顺序更改为 theano 顺序。我修改了 ~/.keras/keras.json 文件,行 "image_dim_ordering": "th" 不起作用,但是行 "backend": "theano" 配置正在运行。
{
"floatx": "float32",
"epsilon": 1e-07,
"backend": "theano",
"image_dim_ordering": "th"
}
当我在程序开头添加 backend.image_dim_ordering('th') 时,权重加载出现了新问题。我确定权重使用的是 theano 后端,并且是按“th”顺序。
ValueError: Layer weight shape (3,3,3,64) not compatible with provided weight shape(64,3,3,3)
程序开头没有 backend.image_dim_ordering('th') 的原始错误:
Exception: Layer weight shape (3, 3, 640, 64) not compatible with provided weight shape (64, 3, 3, 3)
我用的是python 2.7.12,win7和Ubuntu 16.04系统都会出现这个问题。
请您参考如下方法:
使用 set_image_dim_ordering 而不是 image_dim_ordering。后者只获取数据排序格式,不设置:
import keras.backend as K
K.set_image_dim_ordering('th')
