Upload README.md
Browse files
README.md
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Pokémon Classifier
|
2 |
+
|
3 |
+
# Intro
|
4 |
+
|
5 |
+
A fine-tuned version of ViT-base on a collected set of Pokémon images. You can read more about the model [here](https://medium.com/@imjeffhi4/tutorial-using-vision-transformer-vit-to-create-a-pok%C3%A9mon-classifier-cb3f26ff2c20).
|
6 |
+
|
7 |
+
# Using the model
|
8 |
+
|
9 |
+
```python
|
10 |
+
from transformers import ViTForImageClassification, ViTFeatureExtractor
|
11 |
+
from PIL import Image
|
12 |
+
import torch
|
13 |
+
|
14 |
+
# Loading in Model
|
15 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
+
model = ViTForImageClassification.from_pretrained( "./PokemonModel").to(device)
|
17 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained('google/vit-base-patch16-224')
|
18 |
+
|
19 |
+
# Caling the model on a test image
|
20 |
+
img = Image.open('test.jpg')
|
21 |
+
extracted = feature_extractor(images=img, return_tensors='pt').to(device)
|
22 |
+
predicted_id = model(**extracted).logits.argmax(-1).item()
|
23 |
+
predicted_pokemon = model.config.id2label[predicted_id]
|
24 |
+
```
|