Skip to main content

Face Liveness

Face Liveness (On-Premises) uses advanced AI to verify that a real, live person is present in front of the camera — effectively detecting and blocking attempts using photos, videos, or masks. All processing is performed entirely within your own infrastructure, ensuring complete data privacy, compliance, and protection against spoofing attacks

Prerequisites

Below are the essential prerequisites to ensure the seamless operation of the Facia services:

RequirementSpecification
OSUbuntu 22.04
CPU32 Cores / 64 Threads
RAM128GB
Disk500GB
ServerFreshly installed and upgraded
DockerEnsure that the latest version of Docker is installed.
DockerEnsure your docker network or facia docker containers have internet access.

Install and Configure AWS Account:

The installation of awscli can be done using the following command, please run the commands in the following order as it is.

Note

If you are not using the internet in your environment then you might need to enable it temporarily to fetch the registries.

sudo apt update 
sudo apt install awscli
aws --version

In order to configure the aws cli we need to run the below commands, this will show the prompt which requires the secret token.

aws configure 

Once the above command is run then, we need to enter the id and the secret key during the aws cli configuration.

You will be prompted to enter the Client ID, Secret Token, and AWS Region. Please copy and paste these credentials from the On-Prem Keys section available on the Merchant Portal. After login/signup, input the required values as follows:

  • Client ID
  • Secret Token
  • AWS Region

When prompted with: Default output format [None]: Simply press the Enter key to continue without selecting any output format. Make sure to enter the credentials accurately to ensure a successful configuration.

Sample Response:

root@root:~# aws configure
Access Key ID [None]: your_access_id
AWS Secret Access Key [None]: your_secret_key
Default region name [None]: your_region_name
Default output format [None]:

Now you will have the aws cli configured in your server and good to start builds pulling from the Elastic Container Registry (ECR)

aws configure list 

Docker Login to AWS ECR Registry:

To access Docker images stored in AWS Elastic Container Registry (ECR), run the following command:

aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin 084864413923.dkr.ecr.eu-north-1.amazonaws.com

Setting up the Updated Docker Images from AWS ECR Registry

Pulling the updated images from AWS ECR Registry:

There are a total of four images that you need to pull from the AWS ECR registry. Following are the commands to pull the docker images.

docker pull 084864413923.dkr.ecr.eu-north-1.amazonaws.com/cache:latest
docker pull 084864413923.dkr.ecr.eu-north-1.amazonaws.com/face_liveness:docker_hub

Run the Containers:

  1. 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)
  2. Create a Docker network named facia-network and run the containers with the following commands:
docker network create facia-network
docker run -d --name mongodb_local_container -e USER=mongoAdmin -e PASS=TBbuaxROrspF8K6ugQJ29s8ZMqc --network=facia-network 084864413923.dkr.ecr.eu-north-1.amazonaws.com/cache:latest
docker run -d --name ml_services_container --network=facia-network -p 127.0.0.1:5001:5001 --link mongodb_local_container:mongodb-local 084864413923.dkr.ecr.eu-north-1.amazonaws.com/face_liveness:docker_hub

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 Services is live Then we are good to go with start putting the requests OR else you need to wait till its ready.

Note

Images must be in PNG, JPG, or JPEG format.

User Authentication and Processing:

  • Method: POST
  • URL: /liveness
  • Content-Type: application/json
  • Request Body: Please Login/Signup to your Facia account in order to get the Hash_id, so you can use docker. Once logged in, you can retrieve the Hash ID from this URL in settings.
json_data = {
'hash_id': hash_id,
'selfie_image': selfie_image_base64_encoded_string
}

Server Response:

Response Code: 201
{
"liveness_result": {
"is_live": 0/1,
"liveness_score": 0.0-1.0
},
"message": "Success"
}

Interpretation of Response:

  • is live: 1 if the image is not a spoof, 0 if it's a spoof attack.
  • liveness score: A score representing how confident the system is thatthe 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

Response Code: 201
{
"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:

Note

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)


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))