Skip to main content

Merged Solutions

The Merged Solution combines Face Liveness and Face Match into a single, seamless process. It first verifies that a live person is present, then immediately matches their face to a reference image — all performed securely within your infrastructure for streamlined and protected identity verification.

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
NetworkEnsure 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.

Install AWS CLI

sudo apt update 
sudo apt install awscli
aws --version

Configure AWS Credentials

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 2>/dev/null

Setting up the Updated Docker Images from AWS ECR Registry

Pull 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_match_onp: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)
  • Create a Docker network named facia-network and run the containers with the following commands:
  1. Create a Docker network:
docker network create facia-network
  1. Run the MongoDB container:
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
  1. Run the ML services container:
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_match_onp: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.

Note

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

User Authentication and Processing

  • Method: POST
  • URL: /process_face
  • Content-Type: application/json
  • Request Body:

Please Signup 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.

{
"hash_id": "hash_id",
"selfie_image": "selfie_image_base64_encoded_string",
"document_image": "document_image_base64_encoded_string"
}

Server Response

Response code: 201
{
"face_similarity_result": {
"is_match": 1/0,
"similarity_score": 0.0-1
},
"liveness_result": {
"is_live": 0/1,
"liveness_score": 0.0-0.1
},
"message": "Success"/"Fail"
}

Interpretation of Response

  • is_match: 1 if the faces match, 0 if they do not match
  • is_live: 1 if the image is not a spoof, 0 if it's a spoof attack
  • similarity_score: A score representing the similarity between the two faces
  • 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

{
"message": "Invalid credentials"
}

2. Corrupted Image

{
"error": "Invalid or corrupt selfie image. Images must be in PNG, JPG, or JPEG format"
}

3. Face Match and Original/Bonafide Image

Response code: 201
{
"face_similarity_result": {
"is_match": 1,
"similarity_score": 0.9876343
},
"liveness_result": {
"is_live": 1,
"liveness_score": 0.98765
},
"message": "Success"
}

4. Face Not Match and Spoofed Attack

Response code: 201
{
"face_similarity_result": {
"is_match": 0,
"similarity_score": 0.2335
},
"liveness_result": {
"is_live": 0,
"liveness_score": 0.12325
},
"message": "Success"
}

5. Missing Image

{
"error": "Both selfie_image and document_image are required"
}

6. Demo Limit Reached

{
"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 base64
import uuid, time
import requests
import os
import mimetypes

def generate_reference_id():
return str(uuid.uuid4()).replace('-', '').upper()

def encode_image_to_base64(image_path):
if not os.path.exists(image_path):
raise FileNotFoundError(f"{image_path} not found")
mime_type, _ = mimetypes.guess_type(image_path)
if not mime_type or not mime_type.startswith("image/"):
raise ValueError("Invalid image file")
with open(image_path, "rb") as img:
return f"data:{mime_type};base64,{base64.b64encode(img.read()).decode()}"

image1_path = img_path1
image2_path = img_path2

json_data = {
'hash_id': 'hash_id',
'selfie_image': encode_image_to_base64(image1_path),
'document_image': encode_image_to_base64(image2_path)
}
response = requests.post("http://127.0.0.1:5001/process_face", json=json_data)
print(f"Response Code: {response.status_code}")
print(f"Response Text: {response.json()}")