A minimal implementation of face-detection models using flask, gunicorn, nginx, docker, and docker-compose

Overview

Face-Detection-flask-gunicorn-nginx-docker

This is a simple implementation of dockerized face-detection restful-API implemented with flask, Nginx, and scaled up with Gunicorn. This web service accepts an image as input and returns face-box coordinates.

Notes

  1. For face-detection, I used pytorch version of mtcnn from deep_utils library. For more information check out deep_utils.
  2. The service is scaled up using gunicorn. The gunicorn is a simple library with high throughput for scaling python services.
    1. To increase the number workers, increase number of workers in the docker-compose.yml file.
    2. For more information about gunicorn workers and threads check the following stackoverflow question
    3. gunicorn-workers-and-threads
  3. nginx is used as a reverse proxy

Setup

  1. The face-detection name in docker-compose can be changed to any of the models available by deep-utils library.
  2. For simplicity, I placed the weights of the mtcnn-torch model in app/weights.
  3. To use different face-detection models in deep_utils, apply the following changes:
    1. Change the value of FACE_DETECTION_MODEL in the docker-compose.yml file.
    2. Modify configs of a new model in app/base_app.py file.
    3. It's recommended to run the new model in your local system and acquire the downloaded weights from ~/.deep_utils directory and place it inside app/weights directory. This will save you tons of time while working with models with heavy weights.
    4. If your new model is based on tensorflow, comment the pytorch installation section in app/Dockerfile and uncomment the tensorflow installation lines.

RUN

To run the API, install docker and docker-compose, execute the following command:

windows

docker-compose up --build

Linux

sudo docker-compose up --build

Inference

To send an image and get back the boxes run the following commands: curl --request POST ip:port/endpoint -F image=@img-add

If you run the service on your local system the following request shall work perfectly:

curl --request POST http://127.0.0.1:8000/face -F image=@./sample-images/movie-stars.jpg

The output will be as follows:

{
"face_1":[269,505,571,726],
"face_10":[73,719,186,809],
"face_11":[52,829,172,931],
"face_2":[57,460,187,550],
"face_3":[69,15,291,186],
"face_4":[49,181,185,279],
"face_5":[53,318,205,424],
"face_6":[18,597,144,716],
"face_7":[251,294,474,444],
"face_8":[217,177,403,315],
"face_9":[175,765,373,917]
}

Issues

If you find something missing, please open an issue or kindly create a pull request.

References

1.https://github.com/pooya-mohammadi/deep_utils

Licence

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

You might also like...
Example Of Fine-Tuning BERT For Named-Entity Recognition Task And Preparing For Cloud Deployment Using Flask, React, And Docker
Example Of Fine-Tuning BERT For Named-Entity Recognition Task And Preparing For Cloud Deployment Using Flask, React, And Docker

Example Of Fine-Tuning BERT For Named-Entity Recognition Task And Preparing For Cloud Deployment Using Flask, React, And Docker This repository contai

Pretrained Pytorch face detection (MTCNN) and recognition (InceptionResnet) models
Pretrained Pytorch face detection (MTCNN) and recognition (InceptionResnet) models

Face Recognition Using Pytorch Python 3.7 3.6 3.5 Status This is a repository for Inception Resnet (V1) models in pytorch, pretrained on VGGFace2 and

[TIP 2021] SADRNet: Self-Aligned Dual Face Regression Networks for Robust 3D Dense Face Alignment and Reconstruction
[TIP 2021] SADRNet: Self-Aligned Dual Face Regression Networks for Robust 3D Dense Face Alignment and Reconstruction

SADRNet Paper link: SADRNet: Self-Aligned Dual Face Regression Networks for Robust 3D Dense Face Alignment and Reconstruction Requirements python

A large-scale face dataset for face parsing, recognition, generation and editing.
A large-scale face dataset for face parsing, recognition, generation and editing.

CelebAMask-HQ [Paper] [Demo] CelebAMask-HQ is a large-scale face image dataset that has 30,000 high-resolution face images selected from the CelebA da

DVG-Face: Dual Variational Generation for Heterogeneous Face Recognition, TPAMI 2021

DVG-Face: Dual Variational Generation for HFR This repo is a PyTorch implementation of DVG-Face: Dual Variational Generation for Heterogeneous Face Re

Face Synthetics dataset is a collection of diverse synthetic face images with ground truth labels.
Face Synthetics dataset is a collection of diverse synthetic face images with ground truth labels.

The Face Synthetics dataset Face Synthetics dataset is a collection of diverse synthetic face images with ground truth labels. It was introduced in ou

VGGFace2-HQ - A high resolution face dataset for face editing purpose
VGGFace2-HQ - A high resolution face dataset for face editing purpose

The first open source high resolution dataset for face swapping!!! A high resolution version of VGGFace2 for academic face editing purpose

Python tools for 3D face: 3DMM, Mesh processing(transform, camera, light, render), 3D face representations.
Python tools for 3D face: 3DMM, Mesh processing(transform, camera, light, render), 3D face representations.

face3d: Python tools for processing 3D face Introduction This project implements some basic functions related to 3D faces. You can use this to process

Video-face-extractor - Video face extractor with Python

Python face extractor Setup Create the srcvideos and faces directories Put your

Face Library is an open source package for accurate and real-time face detection and recognition

Face Library Face Library is an open source package for accurate and real-time face detection and recognition. The package is built over OpenCV and us

null 52 Nov 9, 2022
img2pose: Face Alignment and Detection via 6DoF, Face Pose Estimation

img2pose: Face Alignment and Detection via 6DoF, Face Pose Estimation Figure 1: We estimate the 6DoF rigid transformation of a 3D face (rendered in si

VĂ­tor Albiero 519 Dec 29, 2022
Code for HLA-Face: Joint High-Low Adaptation for Low Light Face Detection (CVPR21)

HLA-Face: Joint High-Low Adaptation for Low Light Face Detection The official PyTorch implementation for HLA-Face: Joint High-Low Adaptation for Low L

Wenjing Wang 77 Dec 8, 2022
AI Face Mesh: This is a simple face mesh detection program based on Artificial intelligence.

AI Face Mesh: This is a simple face mesh detection program based on Artificial Intelligence which made with Python. It's able to detect 468 different

Md. Rakibul Islam 1 Jan 13, 2022
Realtime Face Anti Spoofing with Face Detector based on Deep Learning using Tensorflow/Keras and OpenCV

Realtime Face Anti-Spoofing Detection ?? Realtime Face Anti Spoofing Detection with Face Detector to detect real and fake faces Please star this repo

Prem Kumar 86 Aug 3, 2022
Swapping face using Face Mesh with TensorFlow Lite

Swapping face using Face Mesh with TensorFlow Lite

iwatake 17 Apr 26, 2022
Face-Recognition-Attendence-System - This face recognition Attendence system using Python

Face-Recognition-Attendence-System I have developed this face recognition Attend

Riya Gupta 4 May 10, 2022
[NeurIPS 2021 Spotlight] Code for Learning to Compose Visual Relations

Learning to Compose Visual Relations This is the pytorch codebase for the NeurIPS 2021 Spotlight paper Learning to Compose Visual Relations. Demo Imag

Nan Liu 88 Jan 4, 2023
End-to-end face detection, cropping, norm estimation, and landmark detection in a single onnx model

onnx-facial-lmk-detector End-to-end face detection, cropping, norm estimation, and landmark detection in a single onnx model, model.onnx. Demo You can

atksh 42 Dec 30, 2022
Face and Pose detector that emits MQTT events when a face or human body is detected and not detected.

Face Detect MQTT Face or Pose detector that emits MQTT events when a face or human body is detected and not detected. I built this as an alternative t

Jacob Morris 38 Oct 21, 2022