Spaces:
Runtime error
Runtime error
import transformers | |
import gradio as gr | |
import datasets | |
import torch | |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification | |
# from transformers import ViTFeatureExtractor, ViTForImageClassification | |
dataset = datasets.load_dataset('beans') | |
extractor = AutoFeatureExtractor.from_pretrained("suresh-subramanian/beans-classification") | |
model = AutoModelForImageClassification.from_pretrained("suresh-subramanian/beans-classification") | |
# feature_extractor = ViTFeatureExtractor.from_pretrained("google/vit-base-patch16-224") | |
labels = dataset['train'].features['labels'].names | |
def classify(im): | |
features = extractor(im, return_tensors='pt') | |
with torch.no_grad(): | |
logits = model(features["pixel_values"])[-1] | |
probability = torch.nn.functional.softmax(logits, dim=-1) | |
probs = probability[0].detach().numpy() | |
confidences = {label: float(probs[i]) for i, label in enumerate(labels)} | |
return confidences | |
# examples = [["powdery mildew.jpg"], ["375010.jpg"]] | |
# Set gradio interface | |
gr_interface = gr.Interface(classify, inputs='image', outputs='label', title='Bean Classification', description='Monitor your crops health in easier way') | |
# Launch gradio | |
gr_interface.launch(debug=True) |