我正在尝试使用Keras中的Inception V3对1000个类进行多标签图像分类。在我的第一个版本的模型(M1)中,我只是重新训练倒数第二层并且得到了0.0152的验证损失。但是当我训练更多层(倒数第二个和卷积)时,比如模型M2,验证损失将稳定在0.0180。当我训练更多图层时,我预计验证损失会减少。
为了加快训练速度,我增加了从M1到M2的倒数第二层权重。我已经尝试过优化器SGD(lr = 0.0001)和“adam”。 我被困在这里。有人可以帮助我或指出我的代码中的缺陷吗?
base_model = applications.InceptionV3(weights = "imagenet", include_top=False)
#Adding FC layers to base Inception model
x = base_model.output
x = AveragePooling2D((8,8), strides=(8,8))(x)
x = Flatten()(x)
x = Dense(1024, activation="relu")(x)
x = Dropout(0.5)(x)
out = Dense(1000, activation="sigmoid")(x)
model = Model(inputs=base_model.input, outputs=out)
#loading weights of M1 i.e. only penultimate layer trained model and adding to our new model M2 before training
model_temp = load_model("model_ppath_M1")
mwt = model_temp.get_weights()
#defining layers to be trained
for layer in model.layers[:279]:
layer.trainable = False
for layer in model.layers[279:]:
layer.trainable = True
#adding pre trained model M1 weights to this model to speed up training
model.layers[313].set_weights([mwt[0], mwt[1]])
model.layers[315].set_weights([mwt[2], mwt[3]])
model.compile(optimizer="adam", metrics=["accuracy"], loss='binary_crossentropy')
model.fit_generator("added appropriate data generator function here")