File size: 1,069 Bytes
b20b59a 529905e 082c81f 529905e 082c81f 529905e |
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 |
import transformers
import datasets
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
dataset = load_dataset('beans')
extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
model = AutoModelForImageClassification.from_pretrained("saved_model_files")
labels = dataset['train'].features['labels'].names
example_imgs = ["example_0.jpg", "example_1.jpg","example_2.jpg"]
def classify(im):
features = feature_extractor(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(classify, inputs='image',
outputs='label',
title='Bean Classification',
description='Check the health of your bean leaves',
examples = example_imgs)
interface.launch(debug=True) |