Choosing a face classification model
Module inaFaceAnalyzer.face_classifier
define classes providing
pretrained DNN face classification models allowing to predict gender and/or age from faces.
Four classes are currently proposed :
Resnet50FairFaceGRA
predicts age and gender from faces, and is associated to the best classification performances. It should be used by default.Resnet50FairFace
,Vggface_LSVM_YTF
andVggface_LSVM_FairFace
are provided for reproducibility reasons and predict gender only.
Face classification classes share a common interface defined in abstracty class FaceClassifier
.
They can be used with methods :
FaceClassifier.preprocessed_img_list()
for processing image lists stored on diskFaceClassifier.__call__()
for processing list of image frames.
Warning
Face classifiers assume input images contain a single detected, centered, eye-aligned, scaled and preprocessed face of dimensions 224*224 pixels
>>> from inaFaceAnalyzer.face_classifier import Resnet50FairFaceGRA
>>> classif = Resnet50FairFaceGRA()
>>> classif.preprocessed_img_list(['./media/diallo224.jpg', './media/knuth224.jpg'])
filename sex_decfunc age_decfunc sex_label age_label
0 ./media/diallo224.jpg -5.632371 3.072337 f 25.723367
1 ./media/knuth224.jpg 7.255364 6.689072 m 61.890717
- class inaFaceAnalyzer.face_classifier.FaceClassifier[source]
Bases:
ABC
Abstract class to be implemented by face classifiers
- __call__(limg, verbose=False)[source]
Classify a list of images images are supposed to be preprocessed faces: aligned, cropped :param limg: :type limg: list of images, a single image can also be used
- Returns:
feats – face features used as input to the final classifier
label (str) – f for female, m for male
decision_value (float) – decision function value (negative for female, positive for male)
- bbox2square = True
implemented face classifiers may require a preprocessing step consisting to extend the face bounding box such as the resulting box is the smallest square containing the detected face
- bbox_scale = 1.1
implemented classifiers are optimized for a given scale factor to be applied on face bounding boxes to be defined here
- input_shape = (224, 224, 3)
input image dimensions required by the classifier (height, width, depth)
- preprocessed_img_list(lfiles, batch_len=32)[source]
Performs classification on a list of preprocessed face images Preprocessed face images are assumed to contain a single face which is already detected, cropped, aligned and scaled to classifier’s input dimensions (for now: 224*224 pixels)
- Parameters:
lfiles (list) – list of image paths: [‘/path/to/img1’, ‘/path/to/img2’]
batch_len (int, optional) – DNN batch size. Larger batch_len results in faster processing times. Batch lenght is dependent on available GPU memory. Defaults to 32 (suitable for a laptop GPU).
- Returns:
pandas.DataFrame. a DataFrame with one record for each input image
- class inaFaceAnalyzer.face_classifier.Resnet50FairFace[source]
Bases:
FaceClassifier
Resnet50FairFace uses Resnet50 architecture trained to predict gender on FairFace.
- bbox2square = True
implemented face classifiers may require a preprocessing step consisting to extend the face bounding box such as the resulting box is the smallest square containing the detected face
- bbox_scale = 1.1
implemented classifiers are optimized for a given scale factor to be applied on face bounding boxes to be defined here
- input_shape = (224, 224, 3)
input image dimensions required by the classifier (height, width, depth)
- preprocessed_img_list(lfiles, batch_len=32)
Performs classification on a list of preprocessed face images Preprocessed face images are assumed to contain a single face which is already detected, cropped, aligned and scaled to classifier’s input dimensions (for now: 224*224 pixels)
- Parameters:
lfiles (list) – list of image paths: [‘/path/to/img1’, ‘/path/to/img2’]
batch_len (int, optional) – DNN batch size. Larger batch_len results in faster processing times. Batch lenght is dependent on available GPU memory. Defaults to 32 (suitable for a laptop GPU).
- Returns:
pandas.DataFrame. a DataFrame with one record for each input image
- class inaFaceAnalyzer.face_classifier.Resnet50FairFaceGRA[source]
Bases:
Resnet50FairFace
Resnet50FairFaceGRA predicts age and gender and is the most accurate proposed. It uses Resnet50 architecture and is trained to predict gender, age and race on FairFace. After consultation of French CNIL (French data protection authority) and DDD (French Rights Defender), racial classification layers were erased from this public distribution in order to prevent their use for non ethical purposes. These models can however be provided for free after examination of each demand.
- class inaFaceAnalyzer.face_classifier.OxfordVggFace(hdf5_svm=None)[source]
Bases:
FaceClassifier
OxfordVggFace instances are based on VGG16 architectures pretrained using a triplet loss paradigm allowing to obtain face neural representation, that we use to train linear SVM classification systems.
This class takes advantage of Refik Can Malli’s keras-vggface module, providing pretrained VGG16 models https://github.com/rcmalli/keras-vggface
- class inaFaceAnalyzer.face_classifier.Vggface_LSVM_YTF[source]
Bases:
OxfordVggFace
Vggface_LSVM_FairFace predict gender from face using pretrained Oxford VGG16 facial embedings used to train a Linear SVM on Youtube Faces DB.
This method is fully described in Zohra Rezgui’s internship report at INA: Détection et classification de visages pour la description de l’égalité femme-homme dans les archives télévisuelles, Higher School of Statistics and Information Analysis, University of Carthage, 2019
- class inaFaceAnalyzer.face_classifier.Vggface_LSVM_FairFace[source]
Bases:
OxfordVggFace
Vggface_LSVM_FairFace predict gender from face using pretrained Oxford VGG16 facial embedings used to train a Linear SVM on FairFace.