imageclassifier / imageclassifier.py
hrishikesh
Create imageclassifier.py
b92347d
raw
history blame contribute delete
925 Bytes
# -*- 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])