Spaces:
Sleeping
Sleeping
Drone or bird classifier
Browse files
app.ipynb
CHANGED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"#| default_exp app"
|
10 |
+
]
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"cell_type": "code",
|
14 |
+
"execution_count": null,
|
15 |
+
"metadata": {},
|
16 |
+
"outputs": [],
|
17 |
+
"source": [
|
18 |
+
"!pip install -Uqq fastbook\n",
|
19 |
+
"!pip install gradio\n",
|
20 |
+
"!pip install nbdev"
|
21 |
+
]
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"cell_type": "code",
|
25 |
+
"execution_count": 8,
|
26 |
+
"metadata": {},
|
27 |
+
"outputs": [],
|
28 |
+
"source": [
|
29 |
+
"#|export\n",
|
30 |
+
"from fastai.vision.all import *\n",
|
31 |
+
"import gradio as gr"
|
32 |
+
]
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"cell_type": "code",
|
36 |
+
"execution_count": 13,
|
37 |
+
"metadata": {},
|
38 |
+
"outputs": [],
|
39 |
+
"source": [
|
40 |
+
"#|export\n",
|
41 |
+
"learner = load_learner('model.pkl')\n",
|
42 |
+
"\n",
|
43 |
+
"categories = ('Bird', 'Drone')\n",
|
44 |
+
"\n",
|
45 |
+
"def calssify_images(img):\n",
|
46 |
+
" pred, idx, probs = learner.predict(img)\n",
|
47 |
+
" return dict(zip(categories, map(float, probs)))"
|
48 |
+
]
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"cell_type": "code",
|
52 |
+
"execution_count": null,
|
53 |
+
"metadata": {},
|
54 |
+
"outputs": [],
|
55 |
+
"source": [
|
56 |
+
"#|export\n",
|
57 |
+
"image = gr.inputs.Image(shape = (192, 192))\n",
|
58 |
+
"label = gr.outputs.Label()\n",
|
59 |
+
"examples = ['BirdExample1.jpg', 'BirdExample2.jpg', 'DroneExample1.jpg', 'DroneExample2.jpg']\n",
|
60 |
+
"\n",
|
61 |
+
"intf = gr.Interface(fn = calssify_images, inputs = image, outputs = label, examples = examples)\n",
|
62 |
+
"intf.launch(inline = False)"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"cell_type": "code",
|
67 |
+
"execution_count": 18,
|
68 |
+
"metadata": {},
|
69 |
+
"outputs": [
|
70 |
+
{
|
71 |
+
"name": "stdout",
|
72 |
+
"output_type": "stream",
|
73 |
+
"text": [
|
74 |
+
"Export successful\n"
|
75 |
+
]
|
76 |
+
}
|
77 |
+
],
|
78 |
+
"source": [
|
79 |
+
"import nbdev\n",
|
80 |
+
"nbdev.export.nb_export('app.ipynb', './')\n",
|
81 |
+
"print('Export successful')"
|
82 |
+
]
|
83 |
+
}
|
84 |
+
],
|
85 |
+
"metadata": {
|
86 |
+
"interpreter": {
|
87 |
+
"hash": "2376d2b9915f38786098b2b3250c4b9f66c08129e4576f9e739de38b6074d39d"
|
88 |
+
},
|
89 |
+
"kernelspec": {
|
90 |
+
"display_name": "Python 3.8.12 ('datasci-env-py38')",
|
91 |
+
"language": "python",
|
92 |
+
"name": "python3"
|
93 |
+
},
|
94 |
+
"language_info": {
|
95 |
+
"codemirror_mode": {
|
96 |
+
"name": "ipython",
|
97 |
+
"version": 3
|
98 |
+
},
|
99 |
+
"file_extension": ".py",
|
100 |
+
"mimetype": "text/x-python",
|
101 |
+
"name": "python",
|
102 |
+
"nbconvert_exporter": "python",
|
103 |
+
"pygments_lexer": "ipython3",
|
104 |
+
"version": "3.8.12"
|
105 |
+
},
|
106 |
+
"orig_nbformat": 4
|
107 |
+
},
|
108 |
+
"nbformat": 4,
|
109 |
+
"nbformat_minor": 2
|
110 |
+
}
|
app.py
CHANGED
@@ -1,7 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learner', 'categories', 'image', 'label', 'examples', 'intf', 'calssify_images']
|
5 |
+
|
6 |
+
# %% app.ipynb 2
|
7 |
+
from fastai.vision.all import *
|
8 |
import gradio as gr
|
9 |
|
10 |
+
# %% app.ipynb 3
|
11 |
+
learner = load_learner('model.pkl')
|
12 |
+
|
13 |
+
categories = ('Bird', 'Drone')
|
14 |
+
|
15 |
+
def calssify_images(img):
|
16 |
+
pred, idx, probs = learner.predict(img)
|
17 |
+
return dict(zip(categories, map(float, probs)))
|
18 |
+
|
19 |
+
# %% app.ipynb 4
|
20 |
+
image = gr.inputs.Image(shape = (192, 192))
|
21 |
+
label = gr.outputs.Label()
|
22 |
+
examples = ['BirdExample1.jpg', 'BirdExample2.jpg', 'DroneExample1.jpg', 'DroneExample2.jpg']
|
23 |
|
24 |
+
intf = gr.Interface(fn = calssify_images, inputs = image, outputs = label, examples = examples)
|
25 |
+
intf.launch(inline = False)
|