Downloads · 30 days
10
3% of all-time downloads
anggiatm/vit-female-age-classification
vit-female-age-classification is a image classification model from anggiatm. Use it when you need a label for an image. The card lists the license as mit.
This repository contains a Vision Transformer (ViT) model trained to classify the age of women based on facial images. The model predicts the following age groups: Child, Teen, Woman, and Senior.
Downloads · 30 days
10
3% of all-time downloads
All-time downloads
314
Public
Parameters
85.8M
1 GB on disk
Likes
0
Public
Click a slice to open those files.
.pt687 MB · 50%
From the Hugging Face model README
This repository contains a Vision Transformer (ViT) model trained to classify the age of women based on facial images. The model predicts the following age groups: Child, Teen, Woman, and Senior.
transformersYou can run the model using the following Python code:
Make sure to install the necessary packages:
pip install transformers torch torchvision pillow opencv-python
Here’s an example of how to load the model and classify an image:
from transformers import pipeline
import cv2
from PIL import Image
# Load the pre-trained model from Hugging Face Hub
model_dir = 'anggiatm/vit-female-age-classification'
female_age = pipeline("image-classification", model=model_dir, device='cuda') # Use CUDA if available
# Path to your image file
file_path = '/path/to/your/image.jpg'
# Load and preprocess the image
img = cv2.imread(file_path)
if img is not None:
# Convert the image from BGR to RGB format
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Resize the image to 224x224
img_resized = cv2.resize(img_rgb, (224, 224))
# Convert to PIL image format
pil_image = Image.fromarray(img_resized)
# Run the image through the model
female_age_preds = female_age(pil_image)
# Get the label and confidence score
label = female_age_preds[0]['label']
score = female_age_preds[0]['score'] * 100
# Print the result
print(f"{file_path:<23} {label:<10} {score:>10.2f}%")
/path/to/your/image.jpg Woman 95.72%
The model was trained on a dataset of female facial images categorized into the following age groups:
Each image is resized to 224x224 pixels before being fed into the model.
You can access the dataset here.
Please note that while this model performs well in most cases, there may be occasional misclassifications. The dataset was labeled manually, and some age groups may overlap or be inaccurately represented in certain images. Use the model results with this caution in mind.
This project is licensed under the MIT License - see the LICENSE file for details.
This model was built using the Hugging Face transformers library and Vision Transformer (ViT) architecture.
Happy Coding! 😊