On-Premises Liveness Detection
This document provides a comprehensive guide to deploying the on-premises liveness detection solution, enabling users to perform liveness verification within their own infrastructure. Unlike cloud-based solutions, this on-prem deployment offers enhanced security, data privacy, and complete control over the environment.
The following sections outline the step-by-step process for installation, configuration, and integration to ensure a smooth setup. Additionally, this guide includes detailed instructions for setting up and running the FACIA application using Docker containers. Please follow the outlined guidelines carefully for successful deployment.
Prerequisites
Below are the essential prerequisites to ensure the seamless operation of the Facia services:
| Requirement | Specification |
|---|---|
| OS | Ubuntu 20.04 |
| CPU | 128 cores |
| RAM | 250GB |
| Disk | 1TB |
| Server | Freshly installed and upgraded |
| Docker | Ensure that the latest version of Docker is installed. |
| Docker | Ensure your docker network or facia docker containers have internet access. |
Setting up the Updated Docker Images From Docker Hub
Pulling the updated images from Docker Hub:
There are a total of two images that you need to pull from the docker hub.
Following are the commands to pull the docker images.
docker pull faciaai/cache:latest
docker pull faciaai/liveness-detection:latest
Run the Containers:
- To run the FACIA application on a different IP address and port, modify the -p flag in the docker run command for ml_services_container. (Optional)
- Run the containers with the following commands:
docker run -d --name mongodb_local_container -e USER=mongoAdmin -e PASS=TBbuaxROrspF8K6ugQJ29s8ZMqc --network=bridge faciaai/cache:latest
docker run -d --name ml_services_container_updated_1 --network=bridge -p 127.0.0.1:5001:5001 --link mongodb_local_container:mongodb-local faciaai/liveness-detection:latest
Wait for Initialization:
Allow 5-10 minutes for the services to initialize before proceeding. Check the status of the ml container using the bash command.
curl localhost:5001/status_check
if the response is returned as Service is live Then we are good to go with start putting the requests OR else you need to wait till its ready.
Images must be in PNG, JPG, or JPEG format.
Please Sign Up to get the hash_id, so you can use the docker and can use it. Once logged in, you can retrieve the Hash ID from this URL in settings.
User Authentication and Processing
Endpoint Details
- Method:
POST - URL:
/liveness - Content-Type:
application/json - Request Body:
json_data = {
"hash_id": "your_hash_id",
"selfie_image": "base64_encoded_selfie_image"
}
- Server Response:
Response Code: 201
{
"liveness_result": {
"is_live": 0/1,
"liveness_score": 0.0-1.0
},
"message": "Success"
}
Interpretation of Response
is_live:1if the image is not a spoof0if it is a spoof attack
liveness_score: A score representing how confident the system is that the image is not a spoof.message: Indicates the success of the process.
Use Cases
1. Wrong hash_id
Response
{
"message": "Invalid credentials"
}
2. Corrupted Image
Response
{
"error": "Invalid or corrupt selfie image. Images must be in PNG, JPG, or JPEG format."
}
3. Original/Bonafide Image
Response
{
"liveness_result": {
"is_live": 1,
"liveness_score": 0.9862353
},
"message": "Success"
}
4. Spoofed Attack
Response
Response Code: 201
{
"liveness_result": {
"is_live": 0,
"liveness_score": 0.16925619588358065
},
"message": "Success"
}
5. Missing Image
Response
{
"error": "Selfie_image is required and must be a JPEG, JPG or PNG."
}
6. Demo Limit Reached
Response
{
"message": "Your request limit has been reached."
}
Testing Script in Python:
You need to add the value of the variable within the key “image_path” as per your business needs.
import requests
import base64
import mimetypes
import json
image1_path = "selfi.png"
hash_id="hash_id"
def encode_image_with_mime(image_path):
"""
Reads an image file, encodes it in base64 with a validation string, and includes the mime type.
"""
mime_type, _ = mimetypes.guess_type(image_path) # Get MIME type based on the file extension
if not mime_type:
raise ValueError(f"Could not determine MIME type for {image_path}")
with open(image_path, "rb") as img_file:
base64_string = f"data:{mime_type};base64,{base64.b64encode(img_file.read()).decode('utf-8')}"
return base64_string
# Encode selfie image with validation string
selfie_image_base64 = encode_image_with_mime(image1_path)
# Prepare JSON data with email, password, and encoded image
json_data = {
'hash_id': hash_id,
'selfie_image': selfie_image_base64,
}
r = requests.post("http://127.0.0.1:5001/liveness", json=json_data)
print(f"Response Code: {r.status_code}")
print(json.loads(r.text))
Summary
This report provides a detailed analysis of the performance testing conducted on the system, focusing on response times, success rates, failure rates, and other key performance indicators (KPIs).
Server Specification
| Component | Specification |
|---|---|
| Model | 2x Intel(R) Xeon(R) Gold 6438Y+ |
| CPU | 128 VCPUs |
| RAM | 256 GB |
| Drives | 1 × 2 TB SSD |
Test Overview
| Metric | Value |
|---|---|
| Total Requests Made | 501 |
| Total Success | 501 |
| Total Failures | 0 |
| Success Rate | 100.00% |
| Error Rate | 0.00% |
| Total Data Received | 384 kB |
| Total Data Sent | 88 MB |
| Total Duration | ~5m7s |
| Requests per Minute | ~98-100 req/min |
| Average Requests per Second | 1.63 req/sec |
Request Duration Metrics
| Metric | Value |
|---|---|
| Average Duration | 7.58s |
| Minimum Duration | 3.65s |
| Median Duration | 7.78s |
| Maximum Duration | 14.47s |
| 90th Percentile | 8.94s |
| 95th Percentile | 9.62s |
The system handled 501 requests in 5 minutes, with an average request duration of 7.58s. Since requests were processed concurrently, the system achieved ~100 requests per minute.
Request Breakdown
| Metric | Avg | Min | Median | Max |
|---|---|---|---|---|
| Request Blocked | 3.35ms | 0s | 1µs | 567.28ms |
| Connecting | 967.82µs | 0s | 0s | 27.84ms |
| Request Receiving | 173.35µs | 45µs | 78µs | 25.89ms |
| Request Sending | 40.44ms | 23.6ms | 29.71ms | 118.46ms |
| TLS Handshaking | 1.37ms | 0s | 0s | 40.35ms |
| Request Waiting | 7.54s | 3.58s | 7.73s | 14.44s |
Conclusion
The test results indicate that the system handled all requests successfully.