我建立了一个具有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更多推荐
用新课程重新训练模型
发布评论