Spaces:
Runtime error
Runtime error
LuniLand
commited on
Commit
•
c6c7820
1
Parent(s):
5b0de45
let's deploy to huggingface spaces
Browse files- app.py +91 -0
- models/Examples/Pascal/000751.jpg +0 -0
- models/Examples/Pascal/000751.jpg:Zone.Identifier +3 -0
- models/Examples/Pascal/002009.jpg +0 -0
- models/Examples/Pascal/002009.jpg:Zone.Identifier +3 -0
- models/Examples/Pascal/003800.jpg +0 -0
- models/Examples/Pascal/003800.jpg:Zone.Identifier +3 -0
- models/Examples/Pascal/008964.jpg +0 -0
- models/Examples/Pascal/008964.jpg:Zone.Identifier +3 -0
- models/Examples/Pets/Bengal_132.jpg +0 -0
- models/Examples/Pets/Bengal_132.jpg:Zone.Identifier +3 -0
- models/Examples/Pets/Birman_198.jpg +0 -0
- models/Examples/Pets/Birman_198.jpg:Zone.Identifier +3 -0
- models/Examples/Pets/Bombay_86.jpg:Zone.Identifier +3 -0
- models/Examples/Pets/Ragdoll_154.jpg +0 -0
- models/Examples/Pets/Ragdoll_154.jpg:Zone.Identifier +3 -0
- models/Examples/Pets/Russian_Blue_36.jpg:Zone.Identifier +3 -0
- models/Examples/Pets/beagle_82.jpg +0 -0
- models/Examples/Pets/beagle_82.jpg:Zone.Identifier +3 -0
- models/Examples/Pets/shiba_inu_44.jpg +0 -0
- models/Examples/Pets/shiba_inu_44.jpg:Zone.Identifier +3 -0
- models/breeds-classifier.pkl +3 -0
- models/breeds-classifier.pkl:Zone.Identifier +3 -0
- models/dog-cat-classifier.pkl +3 -0
- models/dog-cat-classifier.pkl:Zone.Identifier +3 -0
- models/multi-label-classification.pkl +3 -0
- models/multi-label-classification.pkl:Zone.Identifier +3 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['single_classifier', 'multi_class_classifier', 'multi_label_classifier', 'binary_labels', 'multi_class_labels',
|
5 |
+
'multi_label_labels', 'label_func', 'single_classification', 'multi_class_classification',
|
6 |
+
'multi_label_classification']
|
7 |
+
|
8 |
+
# %% app.ipynb 1
|
9 |
+
import gradio as gr
|
10 |
+
import nbdev
|
11 |
+
from fastai.vision.all import *
|
12 |
+
import os
|
13 |
+
|
14 |
+
# %% app.ipynb 2
|
15 |
+
def label_func(f): return 'Cat' if f[0].isupper() else 'Dog'
|
16 |
+
|
17 |
+
# %% app.ipynb 3
|
18 |
+
single_classifier = load_learner('models/dog-cat-classifier.pkl')
|
19 |
+
multi_class_classifier = load_learner('models/breeds-classifier.pkl')
|
20 |
+
multi_label_classifier = load_learner('models/multi-label-classification.pkl')
|
21 |
+
|
22 |
+
# %% app.ipynb 4
|
23 |
+
binary_labels = single_classifier.dls.vocab
|
24 |
+
|
25 |
+
def single_classification(img):
|
26 |
+
img = PILImage.create(img)
|
27 |
+
pred, pred_idx, probs = single_classifier.predict(img)
|
28 |
+
return dict(zip(binary_labels, map(float, probs)))
|
29 |
+
|
30 |
+
# %% app.ipynb 5
|
31 |
+
multi_class_labels = multi_class_classifier.dls.vocab
|
32 |
+
|
33 |
+
def multi_class_classification(img):
|
34 |
+
img = PILImage.create(img)
|
35 |
+
pred, pred_idx, probs = multi_class_classifier.predict(img)
|
36 |
+
return dict(zip(multi_class_labels, map(float, probs)))
|
37 |
+
|
38 |
+
# %% app.ipynb 6
|
39 |
+
multi_label_labels = multi_label_classifier.dls.vocab
|
40 |
+
|
41 |
+
def multi_label_classification(img):
|
42 |
+
img = PILImage.create(img)
|
43 |
+
pred, pred_idx, probs = multi_label_classifier.predict(img)
|
44 |
+
return dict(zip(multi_label_labels, map(float, probs)))
|
45 |
+
|
46 |
+
# %% app.ipynb 7
|
47 |
+
with gr.Blocks() as demo:
|
48 |
+
gr.Markdown("This demo allowing you to try different vision classification models - \
|
49 |
+
From binary classification through multi-class and multi-label classification and finally segmentation.")
|
50 |
+
|
51 |
+
with gr.Tab("Binary"):
|
52 |
+
with gr.Row():
|
53 |
+
with gr.Column():
|
54 |
+
b_image_input = gr.inputs.Image(shape = (460,460))
|
55 |
+
with gr.Row():
|
56 |
+
b_button = gr.Button("Run")
|
57 |
+
|
58 |
+
b_examples = 'models/Examples/Pets'
|
59 |
+
examples = gr.Examples(examples=[b_examples + '/shiba_inu_44.jpg', b_examples + '/Bengal_132.jpg',], inputs = b_image_input)
|
60 |
+
binary_out = gr.Label(num_top_classes=len(binary_labels))
|
61 |
+
|
62 |
+
|
63 |
+
with gr.Tab("MultiClass"):
|
64 |
+
with gr.Row():
|
65 |
+
with gr.Column():
|
66 |
+
m_image_input = gr.inputs.Image(shape = (460,460))
|
67 |
+
with gr.Row():
|
68 |
+
m_button = gr.Button("Run")
|
69 |
+
|
70 |
+
m_examples = 'models/Examples/Pets'
|
71 |
+
examples = gr.Examples(examples=[os.path.join(m_examples, s) for s in os.listdir(m_examples) if s.endswith('jpg')], inputs = m_image_input)
|
72 |
+
multi_out = gr.Label(num_top_classes=len(multi_class_labels))
|
73 |
+
|
74 |
+
|
75 |
+
with gr.Tab("MultiLabel"):
|
76 |
+
with gr.Row():
|
77 |
+
with gr.Column():
|
78 |
+
ml_image_input = gr.inputs.Image(shape = (460,460))
|
79 |
+
with gr.Row():
|
80 |
+
ml_button = gr.Button("Run")
|
81 |
+
|
82 |
+
ml_examples = 'models/Examples/Pascal'
|
83 |
+
examples = gr.Examples(examples=[os.path.join(ml_examples, s) for s in os.listdir(ml_examples) if s.endswith('jpg')], inputs = ml_image_input)
|
84 |
+
|
85 |
+
multil_out = gr.Label(num_top_classes=len(multi_label_labels))
|
86 |
+
|
87 |
+
b_button.click(single_classification, inputs=b_image_input, outputs=binary_out)
|
88 |
+
m_button.click(multi_class_classification, inputs=m_image_input, outputs=multi_out)
|
89 |
+
ml_button.click(multi_label_classification, inputs=ml_image_input, outputs=multil_out)
|
90 |
+
|
91 |
+
demo.launch()
|
models/Examples/Pascal/000751.jpg
ADDED
models/Examples/Pascal/000751.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pascal/002009.jpg
ADDED
models/Examples/Pascal/002009.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pascal/003800.jpg
ADDED
models/Examples/Pascal/003800.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pascal/008964.jpg
ADDED
models/Examples/Pascal/008964.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pets/Bengal_132.jpg
ADDED
models/Examples/Pets/Bengal_132.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pets/Birman_198.jpg
ADDED
models/Examples/Pets/Birman_198.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pets/Bombay_86.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pets/Ragdoll_154.jpg
ADDED
models/Examples/Pets/Ragdoll_154.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pets/Russian_Blue_36.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pets/beagle_82.jpg
ADDED
models/Examples/Pets/beagle_82.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/Examples/Pets/shiba_inu_44.jpg
ADDED
models/Examples/Pets/shiba_inu_44.jpg:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://51dw3zi9gvg-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/breeds-classifier.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e6e9b3904274b6dc38aa4c324690299f418f5c9fef7b9248f1274f3a541b2270
|
3 |
+
size 87639765
|
models/breeds-classifier.pkl:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://3vx4kj165xn-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/dog-cat-classifier.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f7a50dd19768eceee64045a07a3a7ac969613fd71574c9655f3f6d74c1e4d06f
|
3 |
+
size 87560565
|
models/dog-cat-classifier.pkl:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://3vx4kj165xn-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
models/multi-label-classification.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:96672632a8accfb60848663ad83ccb852e6bd7fe363d5a7aea6160da8381836b
|
3 |
+
size 87572123
|
models/multi-label-classification.pkl:Zone.Identifier
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[ZoneTransfer]
|
2 |
+
ZoneId=3
|
3 |
+
HostUrl=https://3vx4kj165xn-496ff2e9c6d22116-0-colab.googleusercontent.com/
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fastai
|