arsfutura / face-recognition

A framework for creating and using a Face Recognition system.
BSD 3-Clause "New" or "Revised" License
146 stars 49 forks source link

Do you have to retrain model after adding new images? #18

Closed yong2khoo-lm closed 3 years ago

yong2khoo-lm commented 4 years ago

First, appreciate your works :) As titled, would like to know if it is necessary to re-train those already trained? (when there is a new person added)

ldulcic commented 4 years ago

Hi @kyygit, tnx! 🙂

Yes you need to retrain model every time you add new face, but there is a way to make this fast.

⚠️ Use code from develop branch for executing following commands, some thing are not merged into master yet.

Training model for the first time

This will generate embeddings folder(slowest part):

python -m util.generate_embeddings --input-path path/to/images --output-path path/to/embeddings

Train your model (should be fast):

python -m training.train -e path/to/embeddings --grid-search

Now you have your trained model saved in model/face_recogniser.pkl. Don't delete path/to/embeddings folder, save it and use it for retraining.

Retraining model

You have new images of faces -> just add them to your folder with images (path/to/images).

Generate new embeddings:

python -m util.generate_embeddings --input-path path/to/images --output-path path/to/new/embeddings --cache-folder path/to/embeddings

Notice the --cache-folder here, this should point to old embeddings folder. If you didn't add too many new images, this should run fairly fast because it skips generating embeddings for old images.

Train your model:

python -m training.train -e path/to/new/embeddings --grid-search

There, you retrained your model. Every time you add new images, just repeat these steps.

yong2khoo-lm commented 4 years ago

Thanks for your quick reply. Shall test it out~

yong2khoo-lm commented 3 years ago

Hi, not sure if i miss anything... I can only provide 2 arguments to util.generate_embeddings:

If i provide "cache-folder", it throws error as below: error: unrecognized arguments: --cache-folder

ldulcic commented 3 years ago

Hi @kyygit, are you sure you are running this from develop branch?

yong2khoo-lm commented 3 years ago

Is alright. I have my question answered. I was thinking, the reason of 're-train', is that the embedding of a person may vary based on the total persons trained. However, since you mention there is a cache, meaning, the embedding value of a person (of an identical photo) should be same. (correct me if i am wrong)

ldulcic commented 3 years ago

@kyygit you are right, embedding value of the same image (person) doesn't change.