首页 > 解决方案 > 使用顶层分类层对 Inception V3 层进行预训练

问题描述

我是 DL 新手,需要一些有关 Inception V3 模型的帮助。正如我们所知,默认情况下,Inception v3 模型的预训练 Keras 模型使用来自 imagenet 的权重并提供 1000 个类的输出。现在我想为 COIL 数据集添加 100 个类的输出层,据我所知,这对 Keras 不可用。那么如何添加新的权重,或者如果可能的话,如何将 imagenet 的类从 1000 更改为 100?

还有可能将 mnist 数据集添加到 inceptionV3 网络吗?

标签: pythontensorflowkeras

解决方案


要为 100 个类设置 InceptionV4,请执行以下代码。Setinclude_top=False移除模型的顶层。设置pooling='max'提供了一个全局最大池层作为模型输出。这可以直接馈送到密集层进行分类。

img_shape=(height, width) # specify the desired image dimension to use
model=tf.keras.applications.InceptionV3( include_top=False,  weights="imagenet",
     input_shape=img_shape, pooling='max')
x=model.layers[-1].output
predictions=Dense (100, activation='softmax')(x)
model = Model(inputs=model.input, outputs=predictions)    
model.compile(Adam(lr=.001), loss='categorical_crossentropy', metrics=['accuracy'])

推荐阅读