ONNX Model Zoo

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

  1. Create a new Hugging Face model repository

  2. Upload the following files:

    • model_quantized.onnx
    • handler.py
    • requirements.txt
    • README.md
    • .huggingface/inference-config.yaml
  3. 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:

  1. Create a new Hugging Face Space

  2. Upload the following files:

    • model_quantized.onnx
    • handler.py
    • app_huggingface.py (rename to app.py when uploading)
    • requirements.txt
    • README.md
  3. 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 format
  • model.py: Model architecture definition
  • quantize_model.py: Quantizes ONNX model for faster inference
  • handler.py: Inference handler for Hugging Face deployment
  • app.py: FastAPI application for local testing
  • app_huggingface.py: Gradio UI for Hugging Face Spaces
  • requirements.txt: Required Python dependencies
  • Dockerfile: Container definition for deployment

Model info

onnx endpoints_compatible region:us
↓ 0 ♥ 0

Created: 2025-05-19

Updated: 2025-05-19

View on Hugging Face

Files (15)

.gitattributes
.huggingface/inference-config.yaml
DEPLOYMENT_STEPS.md
FIXED_README.md
README.md
README.txt
app_huggingface.py
deploy_to_huggingface.sh
handler.py
inference-config.yaml
model_quantized.onnx ONNX
requirements.txt
test.jpg
test_handler.py
verify_huggingface_deployment.py

Related models