nateraw/vit-age-classifier is a forked repo from huggingface. License: None
Go to file
nateraw f5629497de 📝 add to readme 2021-05-23 21:09:01 -06:00
.gitattributes initial commit 2021-05-24 01:41:30 +00:00
README.md 📝 add to readme 2021-05-23 21:09:01 -06:00
config.json 🎉 init 2021-05-23 19:42:18 -06:00
preprocessor_config.json add preprocessor config 2021-05-23 20:02:13 -06:00
pytorch_model.bin 🎉 init 2021-05-23 19:42:18 -06:00

README.md

tags datasets
image-classification
pytorch
fairface

ViT For Age Classification

A vision transformer finetuned to classify the age of a given person's face.

Usage in Transformers

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)