Downloads · 30 days
0
Shanmukhcr7/Age-Detection
Age-Detection is a image classification model from Shanmukhcr7. Use it when you need a label for an image. The card lists the license as mit.
This is a ResNet18-based age prediction model trained to detect and predict the age of a person from a facial image. It is designed with safety and high performance in mind, originally built for the Age-X Next-Generat…
Downloads · 30 days
0
Access
Public
Updated Jul 24, 2026
Repo size
44.8 MB
Likes
0
Public
Click a slice to open those files.
.pth44.8 MB · 100%
From the Hugging Face model README
This is a ResNet18-based age prediction model trained to detect and predict the age of a person from a facial image. It is designed with safety and high performance in mind, originally built for the Age-X Next-Generation Age Verification Platform.
By open-sourcing this model, we hope to enable developers to build safer, age-aware applications.
You can download the model weights and use them directly with PyTorch. For best results, use a face detector (like OpenCV) to crop the face first, as shown in the age_service.py file included in this repository.
Here is a minimal example of how to load the model and run an inference on a cropped face:
import torch
import torch.nn as nn
from torchvision import models, transforms
from PIL import Image
# 1. Initialize the ResNet18 Model
model = models.resnet18(weights=None)
model.fc = nn.Linear(model.fc.in_features, 1) # Set output to 1 for age regression
model.load_state_dict(torch.load("age_model.pth", map_location="cpu"))
model.eval()
# 2. Prepare the Image
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
# NOTE: The image should be a tightly cropped face for accurate predictions
image = Image.open("path_to_cropped_face.jpg").convert("RGB")
input_tensor = transform(image).unsqueeze(0)
# 3. Predict Age
with torch.no_grad():
predicted_age = model(input_tensor).item()
print(f"Predicted Age: {max(1, min(100, predicted_age)):.1f}")
We have also included an app.py built with Gradio! You can deploy this exact repository to Hugging Face Spaces (select Gradio as the SDK) to get an instant web UI where you can upload photos and see the prediction.
Alternatively, you can run the demo locally:
pip install -r requirements.txt
python app.py
This model provides age estimation based on facial features. Results may vary significantly depending on lighting conditions, camera angles, and demographics. It relies on standard ResNet18 architecture which is optimized for general image processing but may exhibit standard biases present in its training dataset. Always use fallback safety mechanisms in production environments.