File size: 1,350 Bytes
8d36d7f
 
81790ad
f7ebce1
8d36d7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59f4ba
8d36d7f
 
 
a84cb0e
b395c6f
8d36d7f
 
f7ebce1
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
import datasets
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
import gradio as gr
import torch

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 = 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

interface = gr.Interface(
                      fn = classify,
                      inputs= "image",
                      outputs= "label",
                      title = 'Leaf Classication',
                      description = "Many farmers are turning machine learning to monitor their crops automatically with great accuracy. This application can be used to detect Angular Leaf Spot and Bean Rust in Bean Leaves :)",
                      examples = [["bean_rust.jpeg"] , ["healthy.jpeg"] , ["angular_leaf_spot.jpeg"] , ['AngularLeafSpotFig1a.jpg'] , ['bacterial-brown-spot-bean.jpg'] , ['beans-viral-diseases-1.jpg']]
                      )

interface.launch()