File size: 994 Bytes
34760af
70b8880
b7f50cf
34760af
 
 
a7eeb50
70b8880
34760af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44a56f2
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
import datasets
from transformers import ViTImageProcessor, ViTForImageClassification
import torch

dataset =  datasets.load_dataset('beans') # This should be the same as the first line of Python code in this Colab notebook

feature_extractor = ViTImageProcessor.from_pretrained("saved_model_files")
model = ViTForImageClassification.from_pretrained("saved_model_files")

labels = dataset['train'].features['labels'].names

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

description = "Predict whether it is healthy or diseased"
title = "Leaf Classification"
interface = gr.Interface(fn=classify, inputs="image", outputs="label", title=title, description=description ) 

interface.launch(debug=True)