Spaces:
Runtime error
Runtime error
Jeff Vestal
commited on
Commit
•
f4e668e
1
Parent(s):
2b46b09
first push of bird identifier
Browse files- app.py +32 -0
- birds-convnext_small_in22k.pkl +3 -0
- cardinal1.jpeg +0 -0
- crow.jpeg +0 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import skimage
|
4 |
+
import timm
|
5 |
+
|
6 |
+
|
7 |
+
# quick function to strip the leading ###. off the parent label name
|
8 |
+
def strip_parent_num(o):
|
9 |
+
return parent_label(o).split('.')[1]
|
10 |
+
|
11 |
+
# load the model
|
12 |
+
learn = load_learner('birds-convnext_small_in22k.pkl')
|
13 |
+
|
14 |
+
#function to run the image through the model and get the prediction
|
15 |
+
labels = learn.dls.vocab
|
16 |
+
def predict(img):
|
17 |
+
img = PILImage.create(img)
|
18 |
+
pred,pred_idx,probs = learn.predict(img)
|
19 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
20 |
+
|
21 |
+
|
22 |
+
# Gradio customizations
|
23 |
+
title = 'Bird Identifier'
|
24 |
+
description = 'This model will predict the type of bird from an image.\n\nThe convnext_tiny_in22k model was refined using the CUB_200_2011 bird dataset.'
|
25 |
+
examples = ['cardinal1.jpeg', 'crow.jpg']
|
26 |
+
interpretation = 'default'
|
27 |
+
enable_queue = True
|
28 |
+
article = '''<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Learning from -> Gradio + HuggingFace Spaces: A Tutorial</a></p>'''
|
29 |
+
|
30 |
+
# Deploy gradio
|
31 |
+
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,enable_queue=enable_queue).launch(share=True)
|
32 |
+
|
birds-convnext_small_in22k.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4834a280d712f1009acce525e620a25c9dc347b2fbb67926d475328e2e01e27d
|
3 |
+
size 201854910
|
cardinal1.jpeg
ADDED
crow.jpeg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
scikit-image
|
3 |
+
timm
|