Upload Hamidou.py
Browse files- Hamidou.py +22 -0
Hamidou.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
+
|
5 |
+
# url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
6 |
+
|
7 |
+
url = 'https://www.transports.gouv.ci/sites/default/files/securite/103954442_3606826602680429_4157569258353658362_n.jpg'
|
8 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
9 |
+
|
10 |
+
# from IPython.display import Image
|
11 |
+
display(image)
|
12 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained(
|
13 |
+
'google/vit-base-patch16-224')
|
14 |
+
model = ViTForImageClassification.from_pretrained(
|
15 |
+
'google/vit-base-patch16-224')
|
16 |
+
|
17 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
18 |
+
outputs = model(**inputs)
|
19 |
+
logits = outputs.logits
|
20 |
+
|
21 |
+
predicted_class_idx = logits.argmax(-1).item()
|
22 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|