3

I am aware that that after training a Neural Network model already, I could save it and in the future load the model to train again. However, what if I would like to incorporate new targets into the model to train?

For instance, I am building a face recognition model for the employees in my company. When new employees join my company, am I able to load and train the existing model with new targets without having to train the whole data set again?

I thought of initializing a keras.utils.to_categorical vector which extends another numpy.zeroes vector element-wise for future target training. May I know if this approach is correct?

  • 1
    You will have to avoid catastrophic forgetting somehow. See [this answer on the AI stack exchange site](https://ai.stackexchange.com/a/13293) for more info. – jakub Dec 29 '20 at 03:22
  • You are right. I have tested this paradigm, and I couldn't train the loaded model purely on new targets again without encountering catastrophic forgetting. The only way to go around is to train the loaded model on all the targets. Do you any way to circumvent catastrophic forgetting? Are there any active research on it? – Tan Pengshi Alvin Jan 02 '21 at 14:42

1 Answers1

1

Yes, you can. For example, VGG-Face model has 2622 outputs. Those outputs are using for finding facial embeddings. We can drop its some final layers and change the number of outputs. For example, I added 101 layers but the base model has 2622 outputs. Those are the new targets and I can start the training.

#!pip install deepface
from deepface import DeepFace
base_model = DeepFace.build_model("VGG-Face")

second_model = Convolution2D(101, (1, 1), name='predictions')(base_model.layers[-4].output)
second_model = Flatten()(second_model)
second_model = Activation('softmax')(second_model)

from tensorflow.keras.models import Model
new_model = Model(inputs=base_model.input, outputs=second_model)

new_model.fit(train_x, train_y, epochs=5000, validation_data=(test_x, test_y))
johncasey
  • 808
  • 5
  • 12
  • Would you be able to use the newly trained model on the original 2622 targets _and_ the 101 new targets? – jakub Dec 30 '20 at 01:58
  • Newly trained model has 101 targets now. You cannot run it for 2622 targets anymore. – johncasey Dec 30 '20 at 17:10
  • 1
    OK that's what I thought. My impression of OP's question what that they wanted to update the model with new data without having to train on all of the previous data. Not sure if my interpretation is correct. – jakub Dec 30 '20 at 17:32
  • Actually, you can freeze / lock the early layer weights and retrain the new model with your new data. In this way, you can have the outcomes and learning of the previous model as well. In this way, you should re-train the new model with a smaller size of data. – johncasey Jan 01 '21 at 09:52