Giter Club home page Giter Club logo

face-recognition's Introduction

Measure Similarity-Based Facial Recognition

Introduction

This repository contains the implementation of a facial recognition system based on similarity measurement. We focuses on measuring the similarity between facial features and uses a similarity-based approach to recognize faces.

Implementation

Face Detection Model

In this repository, we utilize the YOLOv5 model that has been pre-trained specifically for the task of face detection. YOLOv5 is a state-of-the-art object detection algorithm known for its accuracy and efficiency. I already put the yolov5s.pt inside.

Siamese Model and Similarity Measure

The Siamese Model is responsible for embedding facial images into feature vectors. It takes an input image and converts it into a feature vector A. The system then matches this feature vector with a pre-embedded database of facial feature vectors to find the feature vector B with the smallest angular difference from A. The output of this recognition process is the corresponding identity label for the feature vector B.

To measure the similarity between feature vectors, we employ the cosine similarity. The cosine similarity can be calculated using the formula:

Cosine similarity

In this equation, A and B are the feature vectors being compared. The cosine similarity value ranges from -1 to 1, where 1 indicates perfect similarity and -1 indicates complete dissimilarity.

Loss Function

We utilize the MagFace loss function, which is based on angular-margin-based classification. The MagFace loss function is described in the following paper:

Usage

Prepare enviroment and image-data

To get started, follow these steps:

  1. Clone this repository by running the following command:
git clone https://github.com/htuannn/face-recognition
cd face-recognition
  1. Install all the necessary packages by running:
pip install -r requirements.txt
  1. Ensuring your image-database is set up according to the following structure:
face-recognition/
│
├── data_recognition/
│   ├── raw
│   │   ├── PersonA
|   │   │     ├img1.jpg 
|   │   │     └...
│   │   ├── PersonB
|   │   │     ├img1.jpg  
|   │   │     └...
|   │   └...     
|   │ 
│   ├──preprocessed
│   │   ├── PersonA
|   │   │     ├img1_cropped.jpg
|   │   │     └...
|   │   └...    

Note-1:face-recognition/data_recognition/raw is the place to store the entire database of each person's raw images. Each sub-folder here corresponds to one identity, with the name of the sub-folder being the person's name.

Note-2: face-recognition/data_recognition/preprocessed is the place to store the entire database of each person's facial cropped images. The storage rules here are the same as above.

Data preprocessing to crop face from original image

With the images that you have collected, which maybe a photo of the whole person, now we will cut out the face separately. To do this, run the following command:

python align_data.py

The processed images will be stored in the following path: data_recognition/preprocessed

Convert image to embedding vector

To convert the preprocessed face images into embedding vectors, run the following command:

python face_embedding/embedding_feat.py --backbone iresnet50 --resume weights\models\magface_iresnet50_MS1MV2_dp.pth --folderdataset_dir data_recognition/preprocessed --feat_list  data_recognition/preprocessed/face_embdding.txt

Real-time recognition inference

For real-time face recognition inference using a webcam input, run the following command:

python rec_cam.py --backbone iresnet50 --resume weights\models\magface_iresnet50_MS1MV2_dp.pth --view-img

Citation

  1. MagFace: A universal representation for face recognition and quality assessment
  2. yolov5

face-recognition's People

Contributors

htuannn avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.