fanclan/age-gender-model
By fanclan · ↓ 0 · ♥ 0 · Updated 2025-05-19
What's in this repo
This page lists the files in fanclan/age-gender-model, including model_quantized.onnx.
- 1 ONNX models (.onnx files)
- 15 files, including 4 .py, 3 .md, 2 .yaml, 2 .txt, 1 .sh, 1 .onnx
- Last updated 2025-05-19
ONNX files
| File | Size | Download |
|---|---|---|
| model_quantized.onnx | — | Download |
How to use
These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.
README
Image to Age & Gender Model
This repository contains tools for converting, quantizing, and deploying an image-based age and gender prediction model to Hugging Face Inference API.
Model Details
The model is a multi-task ResNet50 architecture that predicts both age group and gender from profile images. It outputs:
- Age classification into 5 age groups (e.g., 18-24, 25-34, 35-44, 45-54, 55+)
- Gender classification (Woman/Man)
Quick Start
Follow these steps to convert your PyTorch model to ONNX, quantize it, and deploy to Hugging Face:
1. Convert PyTorch model to ONNX
python convert_to_onnx.py --pth-path model.pth --onnx-path model.onnx --num-age-classes 5 --num-gender-classes 2
2. Quantize ONNX model
python quantize_model.py --input-path model.onnx --output-path model_quantized.onnx
This reduces model size and improves inference speed.
3. Test locally with FastAPI
python app.py
Visit http://localhost:8000/docs in your browser to test the API.
Deployment Options
Option 1: Hugging Face Inference API
-
Create a new Hugging Face model repository
-
Upload the following files:
model_quantized.onnxhandler.pyrequirements.txtREADME.md.huggingface/inference-config.yaml
-
Set the following environment variable in your Hugging Face model settings:
AGE_CLASSES: Comma-separated list of age class names (e.g., "18-24,25-34,35-44,45-54,55+")
Option 2: Hugging Face Spaces (Gradio UI)
This option provides a web UI for your model:
-
Create a new Hugging Face Space
-
Upload the following files:
model_quantized.onnxhandler.pyapp_huggingface.py(rename toapp.pywhen uploading)requirements.txtREADME.md
-
In the Space settings, set:
- SDK: Gradio
- Python version: 3.10
API Usage
Input
- Image file (JPG/PNG)
Output
{
"age": {
"prediction": "<AGE_GROUP>",
"confidence": 0.85,
"all_probabilities": {
"<AGE_GROUP_1>": 0.05,
"<AGE_GROUP_2>": 0.85,
...
}
},
"gender": {
"prediction": "<GENDER>",
"confidence": 0.92,
"all_probabilities": {
"Woman": 0.08,
"Man": 0.92
}
}
}
Files Overview
convert_to_onnx.py: Converts PyTorch model to ONNX formatmodel.py: Model architecture definitionquantize_model.py: Quantizes ONNX model for faster inferencehandler.py: Inference handler for Hugging Face deploymentapp.py: FastAPI application for local testingapp_huggingface.py: Gradio UI for Hugging Face Spacesrequirements.txt: Required Python dependenciesDockerfile: Container definition for deployment
Model info
Created: 2025-05-19
Updated: 2025-05-19
View on Hugging FaceFiles (15)
Related models
More from fanclan
No other models by this author.
More models
No task type declared.