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
Medical image analysis framework merging ANTsPy and deep learning

ANTsPyNet A collection of deep learning architectures and applications ported to the python language and tools for basic medical image processing. Bas

Advanced Normalization Tools Ecosystem 118 Dec 24, 2022
OpenFed: A Comprehensive and Versatile Open-Source Federated Learning Framework

OpenFed: A Comprehensive and Versatile Open-Source Federated Learning Framework Introduction OpenFed is a foundational library for federated learning

25 Dec 12, 2022
Video2x - A lossless video/GIF/image upscaler achieved with waifu2x, Anime4K, SRMD and RealSR.

Official Discussion Group (Telegram): https://t.me/video2x A Discord server is also available. Please note that most developers are only on Telegram.

K4YT3X 5.9k Dec 31, 2022
Active Offline Policy Selection With Python

Active Offline Policy Selection This is supporting example code for NeurIPS 2021 paper Active Offline Policy Selection by Ksenia Konyushkova*, Yutian

DeepMind 27 Oct 15, 2022
FAIR's research platform for object detection research, implementing popular algorithms like Mask R-CNN and RetinaNet.

Detectron is deprecated. Please see detectron2, a ground-up rewrite of Detectron in PyTorch. Detectron Detectron is Facebook AI Research's software sy

Facebook Research 25.5k Jan 07, 2023
HMLLDB is a collection of LLDB commands to assist in the debugging of iOS apps.

HMLLDB is a collection of LLDB commands to assist in the debugging of iOS apps. 中文介绍 Features Non-intrusive. Your iOS project does not need to be modi

mao2020 47 Oct 22, 2022
Bayesian optimization in PyTorch

BoTorch is a library for Bayesian Optimization built on PyTorch. BoTorch is currently in beta and under active development! Why BoTorch ? BoTorch Prov

2.5k Dec 31, 2022
Beyond Image to Depth: Improving Depth Prediction using Echoes (CVPR 2021)

Beyond Image to Depth: Improving Depth Prediction using Echoes (CVPR 2021) Kranti Kumar Parida, Siddharth Srivastava, Gaurav Sharma. We address the pr

Kranti Kumar Parida 33 Jun 27, 2022
Official PyTorch implementation of "Synthesis of Screentone Patterns of Manga Characters"

Manga Character Screentone Synthesis Official PyTorch implementation of "Synthesis of Screentone Patterns of Manga Characters" presented in IEEE ISM 2

Tsubota 2 Nov 20, 2021
SLIDE : In Defense of Smart Algorithms over Hardware Acceleration for Large-Scale Deep Learning Systems

The SLIDE package contains the source code for reproducing the main experiments in this paper. Dataset The Datasets can be downloaded in Amazon-

Intel Labs 72 Dec 16, 2022
FL-WBC: Enhancing Robustness against Model Poisoning Attacks in Federated Learning from a Client Perspective

FL-WBC: Enhancing Robustness against Model Poisoning Attacks in Federated Learning from a Client Perspective Official implementation of "FL-WBC: Enhan

Jingwei Sun 26 Nov 28, 2022
BOVText: A Large-Scale, Multidimensional Multilingual Dataset for Video Text Spotting

BOVText: A Large-Scale, Bilingual Open World Dataset for Video Text Spotting Updated on December 10, 2021 (Release all dataset(2021 videos)) Updated o

weijiawu 47 Dec 26, 2022
Keras implementation of Real-Time Semantic Segmentation on High-Resolution Images

Keras-ICNet [paper] Keras implementation of Real-Time Semantic Segmentation on High-Resolution Images. Training in progress! Requisites Python 3.6.3 K

Aitor Ruano 87 Dec 16, 2022
Winning solution of the Indoor Location & Navigation Kaggle competition

This repository contains the code to generate the winning solution of the Kaggle competition on indoor location and navigation organized by Microsoft

Tom Van de Wiele 62 Dec 28, 2022
Vector Quantization, in Pytorch

Vector Quantization - Pytorch A vector quantization library originally transcribed from Deepmind's tensorflow implementation, made conveniently into a

Phil Wang 665 Jan 08, 2023
Code for ACL2021 long paper: Knowledgeable or Educated Guess? Revisiting Language Models as Knowledge Bases

LANKA This is the source code for paper: Knowledgeable or Educated Guess? Revisiting Language Models as Knowledge Bases (ACL 2021, long paper) Referen

Boxi Cao 30 Oct 24, 2022
Fully Convolutional DenseNets for semantic segmentation.

Introduction This repo contains the code to train and evaluate FC-DenseNets as described in The One Hundred Layers Tiramisu: Fully Convolutional Dense

485 Nov 26, 2022
Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening

Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening Introduction This is an implementation of the model used for breast

757 Dec 30, 2022
Implementation of light baking system for ray tracing based on Activision's UberBake

Vulkan Light Bakary MSU Graphics Group Student's Diploma Project Treefonov Andrey [GitHub] [LinkedIn] Project Goal The goal of the project is to imple

Andrey Treefonov 7 Dec 27, 2022
Repo for the paper Extrapolating from a Single Image to a Thousand Classes using Distillation

Extrapolating from a Single Image to a Thousand Classes using Distillation by Yuki M. Asano* and Aaqib Saeed* (*Equal Contribution) Extrapolating from

Yuki M. Asano 16 Nov 04, 2022