---
title: vit-age-classifier
canonical_url: "https://www.modelscope.cn/models/nateraw/vit-age-classifier"
md_url: "https://www.modelscope.cn/models/nateraw/vit-age-classifier.md"
repository: nateraw/vit-age-classifier
last_updated: 2024-11-08
pipeline_tag: image-classification
tasks:
  - image-classification
model_type:
  - vit
architectures:
  - ViTForImageClassification
parameters: 85.8M
tensor_type:
  - F32
library_name:
  - transformer
  - safetensors
  - pytorch
frameworks:
  - pytorch
downloads: 1819
stars: 0
tags:
  - image-classification
  - pytorch
---

# vit-age-classifier

> vit-age-classifier - nateraw 在 ModelScope 开源的模型。A vision transformer finetuned to classify the age of a given person's face.

- **Repository**: nateraw/vit-age-classifier
- **Tasks**: image-classification
- **Parameters**: 85.8M
- **Tags**: image-classification, pytorch
- **Downloads**: 1819
- **Stars**: 0
- **Last updated**: 2024-11-08

Source: https://www.modelscope.cn/models/nateraw/vit-age-classifier

---

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




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