

The easiest way to deploy facial analysis framework on your own server.
AWS Rekognition is an excellent service that can get various object information, including facial analysis of humans from images and videos. But let’s say if you want to deploy something similar even with the limited functionality where you need the facial attribute analysis and have a minimal budget for your computer vision startup, I think this open-source library could be your suitable solution.
Deepface is a lightweight hybrid framework developed in python for facial attribute analysis, which can predict the age, gender, emotion, and race of the humans using the image. Further, it can also do face verification to verify the face pairs as the same person or different persons along with face recognition. Deepface framework use wrapping state-of-the-art models: VGG-Face, Google FaceNet, OpenFace, Facebook DeepFace, DeepID, ArcFace, and Dlib, and it is hybrid because you can shift between these different face recognition models. The library is mainly based on Keras and TensorFlow.
Following operations you can do using Deepface –
- Face Verification — The verification function in deepface can take single or multiple images pair to verify the face in all the images are same or different.
from deepface import DeepFaceresult = DeepFace.verify("img1.jpg", "img2.jpg")
2. Face Recognition — You can also call it the find method of the Deepface library where its first parameter is the path to single or multiple images as an array and the second parameter to the database from where you want to find out a particular or numerous faces. After running this function for the first time, it creates a .pkl file where it stores the face model’s representation and because of the same when you will run the method the second time, it will take less time than the first run.
from deepface import DeepFaceimport pandas as pddf = DeepFace.find(img_path = "img1.jpg", db_path = "C:/workspace/database")df2 = DeepFace.find(img_path = ["img1.jpg", “img2.jpg”], db_path = "C:/workspace/database")
3. Facial Attribute Analysis
This method offers these attributes after analysis including age, gender, facial expression and race to find the demography of the face.
From deepface import deepface
Obj = deepface.analyze(img_path = "img1.jpg", actions = ['age', 'gender', 'race', 'emotion'])#objs = deepface.analyze(["img1.jpg", "img2.jpg", "img3.jpg"]) #analyzing multiple faces same timeprint(obj["age"]," years old ",obj["dominant_race"]," ",obj["dominant_emotion"]," ", obj["gender"])
- Pull the docker image from the Docker repository. You can also skip this step and head to step 2.
docker pull sanjeetpal/deepface
2. Deploy the container in the detached mode using the following command while binding the host port with the container port.
docker run –-name container-name -p 5000:5000 -dit sanjeetpal/deepface
And you are done with the making it online, now lets start testing it using the Postman application using some images.
- To verify the endpoint is online.
http://server-ip:5000/
2. To get facial analysis attribute results from the image.
http://server-ip:5000/analyze
Note 1: Currently only age and emotion attribute is available in the docker version of the Deepface framework API endpoint results.
Note 2: All images in the POST request method need to be sent in the base64 encoded string form.
Image used to demonstrate the “analyze” endpoint of the framework.
3. To verify the face in the single or multiple pair of the images are the same or not.
http://server:5000/verify//modelName can be “VGG-Face”, “Facenet”, “OpenFace”, “DeepFace”, “”{
"model_name": “modelName”,
"img": [
"img1": "base64 encoded image",
"img2": "base64 encoded image",
...
..
]}
Images being used for the verify endpoint demo
It’s a great framework to start with instead of working from scratch. You can deploy your face recognition server endpoint within just a few seconds using docker.
For more information about this framework, follow the official GitHub repository link.