Spaces:
Runtime error
Runtime error
File size: 1,058 Bytes
822867f 37c19ea 96aaaaa cfc0bd4 822867f 17f207b 822867f ead77c4 822867f ead77c4 |
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 34 |
import datasets
import torch
from datasets import load_dataset, Image
from transformers import AutoFeatureExtractor, AutoModelForImageClassification, ViTImageProcessor, ViTForImageClassification
dataset = load_dataset("beans")
image_processor = ViTImageProcessor.from_pretrained('google/vit-base-patch16-224')
extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
model = AutoModelForImageClassification.from_pretrained("saved_model_files")
labels = dataset['train'].features['labels'].names
def classify(im):
features = image_processor(im, return_tensors='pt')
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
import gradio as gr
interface = gr.Interface(
fn=classify,
inputs="image",
outputs="label",
title="Bean Leaf Disease Classifier",
description="Upload Your Bean Leaf Pic Here"
)
interface.launch() |