File size: 925 Bytes
b92347d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""imageClassifier.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1S-yO7cqOfeKz8Iu1h-DwhTgkkGml0tKb
"""

pip install git+https://github.com/huggingface/transformers.git

from transformers import ViTFeatureExtractor, ViTForImageClassification
from PIL import Image
import requests

url = 'https://www.livechennai.com/businesslistings/News_photo/dosa11218.jpg'
image = Image.open(requests.get(url, stream=True).raw)

display(image)

feature_extractor = ViTFeatureExtractor.from_pretrained("Amrrs/south-indian-foods")
model = ViTForImageClassification.from_pretrained("Amrrs/south-indian-foods")

inputs = feature_extractor(images=image, return_tensors="pt")

outputs = model(**inputs)

logits = outputs.logits

predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])