Face Detection & Age Gender & Expression & Recognition

Overview

FaceLib:

  • use for Detection, Facial Expression, Age & Gender Estimation and Recognition with PyTorch
  • this repository works with CPU and GPU(Cuda)

Installation

  • Clone and install with this command:
    • with pip and automatic installs everything all you need

      • pip install git+https://github.com/sajjjadayobi/FaceLib.git
    • or with cloning the repo and install required packages

      • git clone https://github.com/sajjjadayobi/FaceLib.git
  • you can see the required packages in requirements.txt

How to use:

  • the simplest way is at example_notebook.ipynb
  • for low-level usage check out the following sections
  • if you have an NVIDIA GPU don't change the device param if not use cpu

1. Face Detection: RetinaFace

  • you can use these backbone networks: Resnet50, mobilenet
    • default weights and model is mobilenet and it will be automatically download
  • for more details, you can see the documentation
  • The following example illustrates the ease of use of this package:
 from facelib import FaceDetector
 detector = FaceDetector()
 boxes, scores, landmarks = detector.detect_faces(image)
  • FaceDetection live on your webcam
   from facelib import WebcamFaceDetector
   detector = WebcamFaceDetector()
   detector.run()

WiderFace Validation Performance on a single scale When using Mobilenet for backbone

Style easy medium hard
Pytorch (same parameter with Mxnet) 88.67% 87.09% 80.99%
Pytorch (original image scale) 90.70% 88.16% 73.82%
Mxnet(original image scale) 89.58% 87.11% 69.12%

2. Face Alignment: Similar Transformation

  • always use detect_align it gives you better performance
  • you can use this module like this:
    • detect_align instead of detect_faces
 from facelib import FaceDetector
 detector = FaceDetector()
 faces, boxes, scores, landmarks = detector.detect_align(image)
  • for more details read detect_image function documentation
  • let's see a few examples
Original Aligned & Resized Original Aligned & Resized
image image image image

3. Age & Gender Estimation:

  • I used UTKFace DataSet for Age & Gender Estimation
    • default weights and model is ShufflenetFull and it will be automatically download
  • you can use this module like this:
   from facelib import FaceDetector, AgeGenderEstimator

   face_detector = FaceDetector()
   age_gender_detector = AgeGenderEstimator()

   faces, boxes, scores, landmarks = face_detector.detect_align(image)
   genders, ages = age_gender_detector.detect(faces)
   print(genders, ages)
  • AgeGenderEstimation live on your webcam
   from facelib import WebcamAgeGenderEstimator
   estimator = WebcamAgeGenderEstimator()
   estimator.run()

4. Facial Expression Recognition:

  • Facial Expression Recognition using Residual Masking Network
    • default weights and model is densnet121 and it will be automatically download
  • face size must be (224, 224), you can fix it in FaceDetector init function with face_size=(224, 224)
  from facelib import FaceDetector, EmotionDetector
 
  face_detector = FaceDetector(face_size=(224, 224))
  emotion_detector = EmotionDetector()

  faces, boxes, scores, landmarks = face_detector.detect_align(image)
  list_of_emotions, probab = emotion_detector.detect_emotion(faces)
  print(list_of_emotions)
  • EmotionDetector live on your webcam
   from facelib import WebcamEmotionDetector
   detector = WebcamEmotionDetector()
   detector.run()
  • on my Webcam ๐Ÿ™‚

Alt Text

5. Face Recognition: InsightFace

  • This module is a reimplementation of Arcface(paper), or Insightface(Github)

Pretrained Models & Performance

  • IR-SE50
LFW(%) CFP-FF(%) CFP-FP(%) AgeDB-30(%) calfw(%) cplfw(%) vgg2_fp(%)
0.9952 0.9962 0.9504 0.9622 0.9557 0.9107 0.9386
  • Mobilefacenet
LFW(%) CFP-FF(%) CFP-FP(%) AgeDB-30(%) calfw(%) cplfw(%) vgg2_fp(%)
0.9918 0.9891 0.8986 0.9347 0.9402 0.866 0.9100

Prepare the Facebank (For testing over camera, video or image)

  • the faces images you want to detect it save them in this folder:

    Insightface/models/data/facebank/
              ---> person_1/
                  ---> img_1.jpg
                  ---> img_2.jpg
              ---> person_2/
                  ---> img_1.jpg
                  ---> img_2.jpg
    
  • you can save a new preson in facebank with 3 ways:

    • use add_from_webcam: it takes 4 images and saves them on facebank
       from facelib import add_from_webcam
       add_from_webcam(person_name='sajjad')
    • use add_from_folder: it takes a path with some images from just a person
       from facelib import add_from_folder
       add_from_folder(folder_path='./', person_name='sajjad')
    • or add faces manually (just face of a person not image of a person)
      • I don't suggest this

Using

  • default weights and model is mobilenet and it will be automatically download
    import cv2
    from facelib import FaceRecognizer, FaceDetector
    from facelib import update_facebank, load_facebank, special_draw, get_config
 
    conf = get_config()
    detector = FaceDetector()
    face_rec = FaceRecognizer(conf)
    face_rec.model.eval()
    
    # set True when you add someone new 
    update_facebank_for_add_new_person = False
    if update_facebank_for_add_new_person:
        targets, names = update_facebank(conf, face_rec.model, detector)
    else:
        targets, names = load_facebank(conf)

    image = cv2.imread(your_path)
    faces, boxes, scores, landmarks = detector.detect_align(image)
    results, score = face_rec.infer(conf, faces, targets)
    print(names[results.cpu()])
    for idx, bbox in enumerate(boxes):
        special_draw(image, bbox, landmarks[idx], names[results[idx]+1], score[idx])
  • Face Recognition live on your webcam
   from facelib import WebcamVerify
   verifier = WebcamVerify(update=True)
   verifier.run()
  • example of run this code:

image

Reference:

Owner
Sajjad Ayobi
Data Science Lover, a Little Geek
Sajjad Ayobi
Package to compute Mauve, a similarity score between neural text and human text. Install with `pip install mauve-text`.

MAUVE MAUVE is a library built on PyTorch and HuggingFace Transformers to measure the gap between neural text and human text with the eponymous MAUVE

Krishna Pillutla 182 Jan 02, 2023
Neural implicit reconstruction experiments for the Vector Neuron paper

Neural Implicit Reconstruction with Vector Neurons This repository contains code for the neural implicit reconstruction experiments in the paper Vecto

Congyue Deng 35 Jan 02, 2023
PyTorch-centric library for evaluating and enhancing the robustness of AI technologies

Responsible AI Toolbox A library that provides high-quality, PyTorch-centric tools for evaluating and enhancing both the robustness and the explainabi

24 Dec 22, 2022
Two-stage CenterNet

Probabilistic two-stage detection Two-stage object detectors that use class-agnostic one-stage detectors as the proposal network. Probabilistic two-st

Xingyi Zhou 1.1k Jan 03, 2023
Simple reimplemetation experiments about FcaNet

FcaNet-CIFAR An implementation of the paper FcaNet: Frequency Channel Attention Networks on CIFAR10/CIFAR100 dataset. how to run Code: python Cifar.py

76 Feb 04, 2021
An open source implementation of CLIP.

OpenCLIP Welcome to an open source implementation of OpenAI's CLIP (Contrastive Language-Image Pre-training). The goal of this repository is to enable

2.7k Dec 31, 2022
Rethinking the Importance of Implementation Tricks in Multi-Agent Reinforcement Learning

RIIT Our open-source code for RIIT: Rethinking the Importance of Implementation Tricks in Multi-AgentReinforcement Learning. We implement and standard

405 Jan 06, 2023
My implementation of Image Inpainting - A deep learning Inpainting model

Image Inpainting What is Image Inpainting Image inpainting is a restorative process that allows for the fixing or removal of unwanted parts within ima

Joshua V Evans 1 Dec 12, 2021
BoxInst: High-Performance Instance Segmentation with Box Annotations

Introduction This repository is the code that needs to be submitted for OpenMMLab Algorithm Ecological Challenge, the paper is BoxInst: High-Performan

88 Dec 21, 2022
The Official PyTorch Implementation of "LSGM: Score-based Generative Modeling in Latent Space" (NeurIPS 2021)

The Official PyTorch Implementation of "LSGM: Score-based Generative Modeling in Latent Space" (NeurIPS 2021) Arash Vahdat* โ€ƒ ยท โ€ƒ Karsten Kreis* โ€ƒ ยท โ€ƒ

NVIDIA Research Projects 238 Jan 02, 2023
FeTaQA: Free-form Table Question Answering

FeTaQA: Free-form Table Question Answering FeTaQA is a Free-form Table Question Answering dataset with 10K Wikipedia-based {table, question, free-form

Language, Information, and Learning at Yale 40 Dec 13, 2022
Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition

Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition

107 Dec 02, 2022
A PyTorch-based open-source framework that provides methods for improving the weakly annotated data and allows researchers to efficiently develop and compare their own methods.

Knodle (Knowledge-supervised Deep Learning Framework) - a new framework for weak supervision with neural networks. It provides a modularization for se

93 Nov 06, 2022
Jingju baseline - A baseline model of our project of Beijing opera script generation

Jingju Baseline It is a baseline of our project about Beijing opera script gener

midon 1 Jan 14, 2022
A simple and lightweight genetic algorithm for optimization of any machine learning model

geneticml This package contains a simple and lightweight genetic algorithm for optimization of any machine learning model. Installation Use pip to ins

Allan Barcelos 8 Aug 10, 2022
An NVDA add-on to split screen reader and audio from other programs to different sound channels

An NVDA add-on to split screen reader and audio from other programs to different sound channels (add-on idea credit: Tony Malykh)

Joseph Lee 7 Dec 25, 2022
The codes for the work "Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation"

Swin-Unet The codes for the work "Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation"(https://arxiv.org/abs/2105.05537). A validatio

869 Jan 07, 2023
Learnable Boundary Guided Adversarial Training (ICCV2021)

Learnable Boundary Guided Adversarial Training This repository contains the implementation code for the ICCV2021 paper: Learnable Boundary Guided Adve

DV Lab 27 Sep 25, 2022
Implementation of the ivis algorithm as described in the paper Structure-preserving visualisation of high dimensional single-cell datasets.

Implementation of the ivis algorithm as described in the paper Structure-preserving visualisation of high dimensional single-cell datasets.

beringresearch 285 Jan 04, 2023
Customizable RecSys Simulator for OpenAI Gym

gym-recsys: Customizable RecSys Simulator for OpenAI Gym Installation | How to use | Examples | Citation This package describes an OpenAI Gym interfac

Xingdong Zuo 14 Dec 08, 2022