【发布时间】:2017-12-21 11:39:41
【问题描述】:
我在 Python 3.6 版上使用 Keras 2.0.5 版和 theano 作为后端。
我正在尝试使用ResNet50 模型来实现迁移学习,并使用了以下示例中给出的代码:https://keras.io/applications/
将以下行添加到代码中使 python 停止工作:
model = ResNet50(weights='imagenet')
我已尝试按照其他链接中的建议更改模型定义:
model = ResNet50(include_top=False, weights='imagenet',input_shape=(3,224,224))
但这给了我另一个错误:
ValueError:输入必须有3个通道;得到 `input_shape=(3, 224, 第224章)
代码如下:
from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np
model = ResNet50(include_top=False, weights='imagenet',input_shape=(3,224,224))
我的 theano 配置文件:(theanorc)
[global]
floatX = float32
device = cpu
[nvcc]
compiler_bindir=C:\Program Files (x86)\Microsoft Visual
Studio\Shared\14.0\VC\bin
我的 keras 配置文件:(keras.json):
{
"epsilon": 1e-07,
"image_data_format": "channels_first",
"image_dim_ordering": "th",
"backend": "theano",
"floatx": "float32"
}
【问题讨论】:
-
您使用
gpu还是cpu?你能给我们展示一个完整的模型定义吗?你能打印出model.summary()吗? -
我正在使用 CPU。我已将 keras.json 中的 image_data_format 更改为 channels_first。我无法打印出 model.summary() 因为我的 python 在遇到模型定义行时停止,即我得到一个弹出窗口,指出“python 已停止执行”。
-
@MarcinMożejko 我猜 keras 在其库中提供了深度学习模型,请查看以下链接 keras.io/applications。我猜这是 keras 中的 resnet50 模型代码:github.com/fchollet/keras/blob/master/keras/applications/…
标签: python keras theano resnet