File size: 1,790 Bytes
76b3aa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
license: apache-2.0
---

# AGE-ViT
Age-classifying Generative Entity Vision Transformer

A Vision Transformer finetuned to classify images of human faces into 'minor' or 'adult'.

This model is a finetuned version of https://huggingface.co/nateraw/vit-age-classifier which was finetuned on the fairface dataset. 

## Datasets
These datasets were used in finetuning, with fairface finetuning the classifier we built on top of. 

### FairFace dataset
https://github.com/dchen236/FairFace

This is a balanced dataset for race, gender, and age and was initial intended for bias mitigation. The majority of the images in this dataset are direct and front facing.

### Synthetic Dataset
https://civitai.com/models/668458/synthetic-human-dataset

This dataset was fully generated by flux and contains 15k images of men, women, boys, and girls from the front, side, and slightly above. This dataset will be expanded with sd15 images and the model will be retrained. 

To use the model 

```
import requests
from PIL import Image
from io import BytesIO

from transformers import ViTImageProcessor, ViTForImageClassification

# Get example image from official fairface repo + read it in as an image
r = requests.get('https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/9488af10-7f1f-4361-877b-d9cfafeab131/original=true,quality=90/24599129.jpeg')
im = Image.open(BytesIO(r.content))

model_dir = 'civitai/age-vit'

# Init model, transforms
model = ViTForImageClassification.from_pretrained(model_dir)
transforms = ViTFeatureExtractor.from_pretrained(model_dir)

# 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)
```