Spaces:
Sleeping
Sleeping
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import skimage
|
| 4 |
+
|
| 5 |
+
learn = load_learner('models/flower_classifier.pkl')
|
| 6 |
+
|
| 7 |
+
labels = learn.dls.vocab
|
| 8 |
+
def predict(img):
|
| 9 |
+
img = PILImage.create(img)
|
| 10 |
+
pred,pred_idx,probs = learn.predict(img)
|
| 11 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 12 |
+
|
| 13 |
+
title = "Flower Classifier"
|
| 14 |
+
description = "An introductory project for using fastai to fine-tune an image classifier model, Gradio to demo it on a web interface, and HuggingFace Spaces for deployment to production. The Oxford Flowers 102 dataset, created by the University of Oxford’s Visual Geometry Group, consists of 8,189 images spanning 102 flower species, designed to challenge fine-grained image classification models. With varying lighting, backgrounds, and an uneven class distribution, it serves as a benchmark for testing model robustness and optimizing classification accuracy, making it popular for transfer learning experiments with models like VGG16, ResNet, and EfficientNet."
|
| 15 |
+
article="<p style='text-align: center'><a href='https://www.robots.ox.ac.uk/~vgg/data/flowers/102/index.html' target='_blank'>Blog post</a></p>"
|
| 16 |
+
examples = ['siamese.jpg']
|
| 17 |
+
interpretation='default'
|
| 18 |
+
enable_queue=True
|
| 19 |
+
|
| 20 |
+
gr.Interface(fn=predict,inputs='image', outputs='label')#gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
|