File size: 2,171 Bytes
841823d
 
 
8976dd3
841823d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8976dd3
 
 
 
 
 
a6f11ac
8976dd3
 
 
28bd75a
841823d
28bd75a
a6f11ac
841823d
 
28bd75a
 
38c5da5
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
32
33
34
35
36
37
38
39
40
# AUTOGENERATED! DO NOT EDIT! File to edit: ../weed_classifier.ipynb.

# %% auto 0
__all__ = ['learn', 'labels', 'article', 'title', 'description', 'examples', 'interpretation', 'enable_queue', 'predict']

# %% ../weed_classifier.ipynb 1
from fastai.vision.all import *
import gradio as gr
import skimage

# %% ../weed_classifier.ipynb 2
learn = load_learner('export.pkl')

# %% ../weed_classifier.ipynb 3
labels = learn.dls.vocab
def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

# %% ../weed_classifier.ipynb 5
article = """<div>This model was trained on the dataset contains 5,539 images of crop and weed seedlings. 
The images are grouped into 12 classes. 
These classes represent common plant species in Danish agriculture at different growth stages.
 A pretrained ResNet34  model was fine-tuned using fastai vision library. The error rate achived on the validation dataset is 2.5% after 4 epochs.
Currently the model does not generalize well on the out-of-domain images. Probably because of the specificity of the dataset. 
The images in the dataset are of a single plant taken from the top and on a single background of a grit surface. Some images have labels that might be unique to the particular plant.
<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>
</div>"""

# %% ../weed_classifier.ipynb 6
title = "Weed Classifier"
description = "<h3 style='text-align: center'>A weed classifier trained on the Kaggle V2 Plant Seedling dataset with fastai.</h3>"
examples = ['SugarBeet.png', 'SmallFloweredCranesBill.png', 'FatHen.png', 'LooseSilkyBent.png', 'CommonChickweed.png', 'MultipleSmallFloweredCranesBill.jpg', 'SmallFloweredCranesBill_02.png']
interpretation='default'
enable_queue=True

# %% ../weed_classifier.ipynb 7
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation).launch(enable_queue=enable_queue)