File size: 1,152 Bytes
91e0ded
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c41f5ea
61e9988
 
91e0ded
 
 
 
 
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

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()