Age & Gender Prediction using swatahVision (OpenVINO Engine)
This example demonstrates how to perform Age and Gender prediction
using the age-gender-recognition-retail-0013 model through the
swatahVision framework, powered internally by the OpenVINO engine.
The script loads two face images, runs inference on CPU,
and prints the predicted age and gender in the terminal.
๐ฅ Model Download
Pretrained models for swatahVision are available in the Model Zoo.
๐ https://visionai4bharat.github.io/swatahVision/model_zoo/
๐ Folder Structure
age_gender_project/
โโโ age-gender-recognition-retail-0013.xml
โโโ age-gender-recognition-retail-0013.bin
โโโ age_gender_prediction.py
โโโ README.md
โโโ image_old_man.jpg
โโโ image_boy.jpg
๐ง Requirements
- Python 3.9+
- NumPy
- OpenCV
- swatahVision
๐งฉ Installation
Create Environment (Recommended)
conda create -n swatah_env python=3.9 -y
conda activate swatah_env
Install Dependencies
pip install numpy
pip install opencv-python
pip install swatahVision
๐ How to Run
python age_gender_prediction.py
๐งช Complete Source Code
Below is the exact code used in this project:
import swatahVision as sv
import numpy as np
import cv2
MODEL_PATH = "age-gender-recognition-retail-0013.xml"
IMAGE_PATH_OLD = "image_old_man.jpg"
IMAGE_PATH_BOY = "image_boy.jpg"
model = sv.Model(
model=MODEL_PATH,
engine=sv.Engine.OPENVINO,
hardware=sv.Hardware.CPU
)
# -----------------------------
# First Image Prediction
# -----------------------------
img = sv.Image.load_from_file(IMAGE_PATH_OLD)
outputs = model(img)[0]
gender_blob = outputs[0]
age_blob = outputs[1]
gender_id = int(np.argmax(gender_blob))
gender = "Male" if gender_id == 1 else "Female"
age = int(age_blob[0][0][0][0] * 100)
print("Predicted Age :", age)
print("Predicted Gender:", gender)
# -----------------------------
# Second Image Prediction
# -----------------------------
image = sv.Image.load_from_file(IMAGE_PATH_BOY)
outputs = model(image)[0]
print(outputs)
gender_blob = outputs[0]
age_blob = outputs[1]
gender_id = int(np.argmax(gender_blob))
gender = "Male" if gender_id == 1 else "Female"
age = int(age_blob[0][0][0][0] * 100)
print("Predicted Age :", age)
print("Predicted Gender:", gender)
๐ค Sample Output
Predicted Age : 62
Predicted Gender: Male
Predicted Age : 14
Predicted Gender: Male
๐ง Model Information
- Model Name:
age-gender-recognition-retail-0013 - Framework: swatahVision
- Inference Engine: OpenVINO (internal)
- Hardware: CPU
- Age Output: Normalized value ร 100
- Gender Output: Probability scores
[Female, Male]
โ ๏ธ Notes
- The model expects cropped face images.
- Only single-face inference is supported.
- Age prediction is an estimate.
- Accuracy depends on lighting and image quality.