Age Estimation
Age Estimation (On-Premises) analyzes facial features to predict a person’s age with high accuracy. All processing happens within your internal environment, helping you maintain strict data privacy and comply with organizational or regulatory requirements.
Prerequisites
Below are the essential prerequisites to ensure the seamless operation of the Facia services:
Requirement | Specification |
---|---|
OS | Ubuntu 22.04 |
CPU | 8 Core 16 Threads |
RAM | 32GB |
Disk | 500GB |
Server | Freshly installed and upgraded |
Docker | Ensure that the latest version of Docker is installed |
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.
If you are not using the internet in your environment then you might need to enable it temporarily to fetch the registories.
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
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/age_estimation:hash_id
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:
- Create a Docker network:
docker network create facia-network
- 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
- 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/age_estimation:hash_id
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.
User Authentication and Processing
- Method:
POST
- URL:
/age_estimation
- 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.
{
"hash_id": "hash_id",
"selfie_image": "selfie_image_base64_encoded_string"
}
Server Response
Response Code: 201
{
"age": 22,
"message": "Success!"
}
Interpretation of Response
- age: age of person
- message: Indicates the success of the process
Use Cases
1. Wrong hash_id
{
"message": "Invalid credentials"
}
2. Missing hash_id
{
"error": "hash_id is required"
}
3. Corrupted Image
{
"error": "Invalid or corrupt selfie image. Images must be in PNG, JPG, or JPEG format."
}
4. Missing image
{
"error": "Selfie_image is required and must be a JPEG, JPG or PNG"
}
5. Demo Limit Reached
{
"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 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 = "image"
json_data = {
'hash_id':'',
'selfie_image': encode_image_to_base64(image1_path)
}
st = time.time()
response = requests.post("http://127.0.0.1:5001/age_estimation", json=json_data)
print(f"Response Code: {response.status_code}")
print(f"Response Text: {response.json()}")
print("Total time:", time.time() - st)