用新课程重新训练模型 [英] Re-train model with new classes

本文介绍了用新课程重新训练模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个具有2个类别的图像分类器,例如"A"和"B".我还使用model.save()保存了该模型.

I have built an image classifier with 2 classes, say 'A' and 'B'. I have also saved this model, using model.save().

现在,经过一定时间后,出现了增加一个"C"类的要求.是否可以load_model()然后仅将一个类添加到先前保存的模型中,以便我们最终的模型具有3个类("A","B"和"C"),而不必重新训练整个模型,再次使用"A"和"B"类?

Now, after a certain time, the requirement arose to add one more class 'C'. Is it possible to load_model() and then add only one class to the previously saved model so that we have the final model with 3 classes ('A','B' and 'C'), without having to retrain the whole model, for classes 'A and 'B' again?

任何人都可以帮忙吗?

我已经尝试过了:

我使用vgg16作为基本模型,弹出其最后一层,冻结权重,并添加了一个密集层(DL2),对其进行了训练以预测2类.

I used vgg16 as a base model and pop out its last layer, freeze weights and added one dense layer (DL2), trained it for predicting 2 classes.

然后我在DL2的顶部添加了一个更密集的层,例如DL3,冻结了重量并仅使用C类进行训练,但现在它始终可以预测C类.

Then I added one more dense layer on top of DL2 say DL3, freeze weights and train with class C only but now its always predicting class C.

推荐答案

只需使用转移学习,然后创建一个新模型即可.

Just use a transfer learning, and create a new model.

model = VGG16(weights='imagenet',
                  include_top=False,
                  input_shape=(150, 150, 3))

model.pop()

base_model_layers = model.output
pred = Dense(11, activation='softmax')(base_model_layers)
model = Model(inputs=model.input, outputs=pred)

# Freeze the first layers, before train it
for layer in model.layers[:-2]:
    layer.trainable = False

这篇关于用新课程重新训练模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆