Giter Site home page Giter Site logo

kc611 / face-verify-api Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 3.0 14.8 MB

A Face Verification API consisting of a FaceNet Model integrated into a Django REST framework to build a complete face verification system.

Python 1.67% HTML 0.03% Jupyter Notebook 98.31%

face-verify-api's Introduction

Face Verification API

This is a Django API(Built with Django REST Framework) that stores and verifies faces of the users. Can be used as backend API for any Website or App accordingly. Let's See How It Works

Problem Statement

Face recognition problems commonly fall into two categories:

  • Face Verification :- "is this the claimed person?". For example, you can pass through by letting a system scan your passport and then verifying that you (the person carrying the passport) are the correct person. A mobile phone that unlocks using your face is also using face verification. This is a 1:1 matching problem.

  • Face Recognition :- "who is this person?". For example, employees entering the office without needing to otherwise identify themselves. This is a 1:K matching problem.

The aim of this framework is to detect and recognize face from images in database. It Employs a Siamese Network with Triplet Loss function(FaceNet Model) to perform the task of face recognition. Frontal Face Detection and cropping of image is done with help of OpenCV Haar Feature-based Cascade Classifiers.

FaceNet learns a neural network that encodes a face image into a vector of 128 numbers. By comparing two such vectors, you can then determine if two pictures are of the same person.

This Entire Model is henceforth built and is rolled into an Django API for cross-platform accessiblity.

Setup

For setting up this API in a local machine:-

  1. Install requirements (Run following command in CMD)
   pip install -r requirements.txt
  1. Navigate to the base folder in CMD (Namely the folder containing manage.py of this webapp)

  2. Setup the API Migrations(run both commands)

   python manage.py makemigrations
   python manage.py migrate
  1. Run the app
   python manage.py runserver

Note: This entire framework was built and tested with Cuda 10.1(Nvidia) and cuDNN compatible with 10.1 for GPU support, Using other version of these software in hosting environment may cause problems.

API Structure Overview

   BASE URL
   |
   |-- /admin
   |
   |-- /api
       |
       |-- /person
       |   |
       |   |-- /listall
       |   |-- /create
       |   |-- /update/<str:id>
       |   |-- /delete/<str:id>
       |
       |-- /face
       |   |
       |   |-- /listall
       |   |-- /create
       |   |-- /listbyperson/<str:id>
       |   |-- /update/<str:id>
       |   |-- /delete/<str:id>
       |
       |-- /verify
       |   |
       |   |-- /linear
       |   
       |-- /dev
       |   |
       |   |-- /embeddings/<str:id>
       |
       |-- /help/<str:url>

If hosted on local machine base URL would be similar to http: //localhost:xxxx.

For additional information on any of these urls pass those urls to /help with a get request in form of '/help/api/.......'. This will return a JSON Response containing the information on that URLs working.

Overview of ML Model

This Model uses an Inception Model to create embeddings from a 96x96 dimensional RGB image as its input.And henceforth, outputs a matrix that encodes each input face image into a 128-dimensional vector.
Sample Then these encodings are used to compare two images as follows: Sample The cost function layer(distance in above image) uses Triplet Loss. A general equation of triplet loss is as follows Sample During Training triplets of images (A,P,N) are used namely: A is an "Anchor" image--a picture of a person. P is a "Positive" image--a picture of the same person as the Anchor image. N is a "Negative" image--a picture of a different person than the Anchor image.

The triplet loss function tries to "push" the encodings of two images of the same person (Anchor and Positive) closer together, while "pulling" the encodings of two images of different persons (Anchor, Negative) further apart. Specifically minimize the l2 norm betwwen encoding vectors of (Anchor,Positive) and maximize the l2 norm between encoding vectors of (Anchor,Negative)

The Model is trained by minimizing the triplet loss.Following are some examples of distances between the encodings between three individuals:

Sample

Useful Links:

face-verify-api's People

Contributors

kastub611 avatar kc611 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

face-verify-api's Issues

i'm getting this error

Watching for file changes with StatReloader
Performing system checks...

/usr/local/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
/usr/local/anaconda3/envs/tensorflow/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.6 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5
return f(*args, **kwds)

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.