weed_classifier / app.py
dmitryhits
changes article
a350d92
# 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 that 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 barcode labels that might be unique to the particular plant.
The last two images in the examples are not from the dataset. They are getting wrongly classified as <b>Scentless Mayweed</b> even though they are <b>Small-flowered Cranesbill</b> (compare with the second image in the examples)
<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.components.Image(shape=(512, 512)),outputs=gr.components.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation).launch(enable_queue=enable_queue)