Spaces:
Sleeping
Sleeping
File size: 2,420 Bytes
841823d 8976dd3 841823d 8976dd3 d2def97 8976dd3 d2def97 a350d92 8976dd3 28bd75a 841823d 28bd75a a6f11ac 841823d 28bd75a 3e28d8a |
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 41 |
# 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)
|