Downloads · 30 days
421
100% of all-time downloads
wolf1280/vit-age-classifier
vit-age-classifier is a image classification model from wolf1280. Use it when you need a label for an image.
A vision transformer finetuned to classify the age of a given person's face.
Downloads · 30 days
421
100% of all-time downloads
All-time downloads
421
Public
Parameters
85.8M
687 MB on disk
Likes
0
Public
Click a slice to open those files.
.bin343 MB · 50%
From the Hugging Face model README
A vision transformer finetuned to classify the age of a given person's face.
import requests
from PIL import Image
from io import BytesIO
from transformers import ViTFeatureExtractor, ViTForImageClassification
# Get example image from official fairface repo + read it in as an image
r = requests.get('https://github.com/dchen236/FairFace/blob/master/detected_faces/race_Asian_face0.jpg?raw=true')
im = Image.open(BytesIO(r.content))
# Init model, transforms
model = ViTForImageClassification.from_pretrained('nateraw/vit-age-classifier')
transforms = ViTFeatureExtractor.from_pretrained('nateraw/vit-age-classifier')
# Transform our image and pass it through the model
inputs = transforms(im, return_tensors='pt')
output = model(**inputs)
# Predicted Class probabilities
proba = output.logits.softmax(1)
# Predicted Classes
preds = proba.argmax(1)