serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://www.youtube.com/watch?v=WnUVYQP4h44&list=PLsS_1RYmYQQFdWqxQggXHynP1rqaYXv_E&index=1
MIT License
11.82k stars 2.02k forks source link

Alternative emotion model support #357

Closed janlampe closed 2 years ago

janlampe commented 2 years ago

As a user of deepface I want to use alternative emotion models So that I can use state-of-the-art models with higher accuracy

Background For many applications of emotion recognition, accuracy/F1 is of crucial importance. The facial expression model built-in to deepface is from 2018 (see https://sefiks.com/2018/01/01/facial-expression-recognition-with-keras/) and has an accuracy of 57,4% - that's good, but not great (anymore). The auto-keras model (described in https://sefiks.com/2019/04/08/a-gentle-introduction-to-auto-keras/) is at 66%, which is a substantial improvement. Other, more current models, also perform better than the built-in model.

Issue However, currently I do not see a simple way to use the auto-keras model or any other alternative models (e.g. https://github.com/phamquiluan/ResidualMaskingNetwork as implemented in py-feat comes to mind). I have seen several references to (re)training existing models in Issues #114 and #93 but it is unclear to me what the requirements are (same exact features, just different weights? If this is the case, how could one use a model with a different number of features?).

Desired Solution It would be great to have some guidance/documentation as to how to do this within the deepface framework. If this is not possible, this functionality may be a useful enhancement. I would intuitively prefer to pass a new model to deepface and take advantage of the speed and usability of the package. A similar argument applies to face recognition models.

Additional Info I figured one could just overwrite the model weight file (and maybe this is the hackiest solution), but this did not work for me:

serengil commented 2 years ago

You should change the emotion model first here: https://github.com/serengil/deepface/blob/master/deepface/extendedmodels/Emotion.py

You just changed the pre-trained weights and missed the model structure. That is the reason of incompatible-ability.

janlampe commented 2 years ago

Thanks, I will try this.