【发布时间】:2019-05-04 21:55:20
【问题描述】:
我正在尝试使用 inceptionV3 预训练模型(来自 keras 应用程序)提取特征。我的代码有以下块:
base_model = InceptionV3(include_top=include_top, weights=weights, input_tensor=Input(shape=(299,299,3)))
model = Model(input=base_model.input, output=base_model.get_layer('custom').output)
image_size = (299, 299)
当我运行它时,它会出现以下错误:
ValueError Traceback (most recent call last)
<ipython-input-24-fa1f85b62b84> in <module>()
20 elif model_name == "inceptionv3":
21 base_model = InceptionV3(include_top=include_top, weights=weights, input_tensor=Input(shape=(299,299,3)))
---> 22 model = Model(input=base_model.input, output=base_model.get_layer('custom').output)
23 image_size = (299, 299)
24 elif model_name == "inceptionresnetv2":
~\Anaconda3\lib\site-packages\keras\engine\network.py in get_layer(self, name, index)
362 """Retrieves the model's updates.
363
--> 364 Will only include updates that are either
365 unconditional, or conditional on inputs to this model
366 (e.g. will not include updates that depend on tensors
ValueError: No such layer: custom
我已尝试完全卸载并重新安装 Keras。 在我读到的某个地方,在 inceptionV3.py 文件(在 keras 应用程序文件夹中)中包含以下内容:
from ..layers import Flatten
我在导入中添加了这个。仍然没有运气。谁能帮我解决这个问题?我是 Keras 的新手。
【问题讨论】:
-
你想做什么?
-
@DanielMöller ->从 Keras 库的应用模块加载预训练模型,并根据用户在 conf.json 文件中指定的配置构建模型。之后,从使用 ImageNet 数据集预训练的模型中的用户指定层中提取特征。这些特征及其标签使用 HDF5 文件格式存储在本地。此外,保存模型和权重只是为了表明这些也可以在 Keras 中完成。这就是我想要实现的目标。
-
InceptionV2是 Keras 严格构建的预构建模型。没有 conf.json,模型中也没有“自定义”层。 -
@DanielMöller- 如上面 conf.json 评论中指定的,是用户指定的。感谢您提供有关定制的 tte 信息。我很少看到人们在将其用于 InceptionResNetV2、inceptionV3 和 MobileNet 时使用“自定义”代码
标签: python tensorflow keras classification