Commit ·
f562949
1
Parent(s): b3bbed0
:pencil: add to readme
Browse files
README.md
CHANGED
|
@@ -7,3 +7,34 @@ datasets:
|
|
| 7 |
---
|
| 8 |
|
| 9 |
# ViT For Age Classification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
---
|
| 8 |
|
| 9 |
# ViT For Age Classification
|
| 10 |
+
|
| 11 |
+
A vision transformer finetuned to classify the age of a given person's face.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
## Usage in Transformers
|
| 15 |
+
|
| 16 |
+
```python
|
| 17 |
+
import requests
|
| 18 |
+
from PIL import Image
|
| 19 |
+
from io import BytesIO
|
| 20 |
+
|
| 21 |
+
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
| 22 |
+
|
| 23 |
+
# Get example image from official fairface repo + read it in as an image
|
| 24 |
+
r = requests.get('https://github.com/dchen236/FairFace/blob/master/detected_faces/race_Asian_face0.jpg?raw=true')
|
| 25 |
+
im = Image.open(BytesIO(r.content))
|
| 26 |
+
|
| 27 |
+
# Init model, transforms
|
| 28 |
+
model = ViTForImageClassification.from_pretrained('nateraw/vit-age-classifier')
|
| 29 |
+
transforms = ViTFeatureExtractor.from_pretrained('nateraw/vit-age-classifier')
|
| 30 |
+
|
| 31 |
+
# Transform our image and pass it through the model
|
| 32 |
+
inputs = transforms(im, return_tensors='pt')
|
| 33 |
+
output = model(**inputs)
|
| 34 |
+
|
| 35 |
+
# Predicted Class probabilities
|
| 36 |
+
proba = output.logits.softmax(1)
|
| 37 |
+
|
| 38 |
+
# Predicted Classes
|
| 39 |
+
preds = proba.argmax(1)
|
| 40 |
+
```
|