leaf_classifier / app.py
sridiyer's picture
typo fix
c41f5ea
import datasets
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
import gradio as gr
dataset = datasets.load_dataset("beans")
extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
model = AutoModelForImageClassification.from_pretrained("saved_model_files")
labels = dataset['train'].features['labels'].names
def classify(im):
features = feature_extractor(im, return_tensors='pt')
logits = model(**features).logits
logits = torch.nn.functional.softmax(logits, dim=-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
# following dummy till i figure out how to upload custom saved model
def classify1(im):
label = {'leaf spot' : 0.9, 'rust' : 0.1}
return label
interface = interface = gr.Interface(classify1, inputs='image', outputs='label', title='Leaf Classification demo',
description='Demo of fine-tuning a ViT for image classification based on the bean dataset classification') # FILL HERE
interface.launch()