dog-cat model
Browse files- Minimal - a Hugging Face Space by fgs22002.pdf +0 -0
- app.ipynb +133 -0
- app.py +18 -4
- app_old.py +7 -0
- cat.jpg +0 -0
- dog.jpg +0 -0
- dunno.jpg +0 -0
- model.pkl +3 -0
Minimal - a Hugging Face Space by fgs22002.pdf
ADDED
Binary file (167 kB). View file
|
|
app.ipynb
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"#|default_exp app"
|
10 |
+
]
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"attachments": {},
|
14 |
+
"cell_type": "markdown",
|
15 |
+
"metadata": {},
|
16 |
+
"source": [
|
17 |
+
"# Dogs v Cats"
|
18 |
+
]
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"cell_type": "code",
|
22 |
+
"execution_count": null,
|
23 |
+
"metadata": {},
|
24 |
+
"outputs": [],
|
25 |
+
"source": [
|
26 |
+
"#|export\n",
|
27 |
+
"from fastai.vision.all import *\n",
|
28 |
+
"import gradio as gr\n",
|
29 |
+
"\n",
|
30 |
+
"def is_cat(x): return x[0].isupper()"
|
31 |
+
]
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"cell_type": "code",
|
35 |
+
"execution_count": null,
|
36 |
+
"metadata": {},
|
37 |
+
"outputs": [],
|
38 |
+
"source": [
|
39 |
+
"im = PILImage.create('dog.jpg')\n",
|
40 |
+
"im.thumbnail((192,192))\n",
|
41 |
+
"im"
|
42 |
+
]
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"cell_type": "code",
|
46 |
+
"execution_count": null,
|
47 |
+
"metadata": {},
|
48 |
+
"outputs": [],
|
49 |
+
"source": [
|
50 |
+
"#|export\n",
|
51 |
+
"import pathlib\n",
|
52 |
+
"temp = pathlib.PosixPath\n",
|
53 |
+
"pathlib.PosixPath = pathlib.WindowsPath\n",
|
54 |
+
"learn = load_learner('model.pkl')\n",
|
55 |
+
"pathlib.PosixPath = temp"
|
56 |
+
]
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"cell_type": "code",
|
60 |
+
"execution_count": null,
|
61 |
+
"metadata": {},
|
62 |
+
"outputs": [],
|
63 |
+
"source": [
|
64 |
+
"learn.predict(im)"
|
65 |
+
]
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"cell_type": "code",
|
69 |
+
"execution_count": null,
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [],
|
72 |
+
"source": [
|
73 |
+
"#|export\n",
|
74 |
+
"categories = ('Dog', 'Cat')\n",
|
75 |
+
"\n",
|
76 |
+
"def classify_image(img):\n",
|
77 |
+
" pred,idx,probs = learn.predict(img)\n",
|
78 |
+
" return dict(zip(categories, map(float, probs)))"
|
79 |
+
]
|
80 |
+
},
|
81 |
+
{
|
82 |
+
"cell_type": "code",
|
83 |
+
"execution_count": null,
|
84 |
+
"metadata": {},
|
85 |
+
"outputs": [],
|
86 |
+
"source": [
|
87 |
+
"classify_image(im)"
|
88 |
+
]
|
89 |
+
},
|
90 |
+
{
|
91 |
+
"cell_type": "code",
|
92 |
+
"execution_count": null,
|
93 |
+
"metadata": {},
|
94 |
+
"outputs": [],
|
95 |
+
"source": [
|
96 |
+
"#|export\n",
|
97 |
+
"image = gr.inputs.Image(shape=(192,192))\n",
|
98 |
+
"label = gr.outputs.Label()\n",
|
99 |
+
"examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']\n",
|
100 |
+
"\n",
|
101 |
+
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
|
102 |
+
"intf.launch(inline=False)"
|
103 |
+
]
|
104 |
+
}
|
105 |
+
],
|
106 |
+
"metadata": {
|
107 |
+
"kernelspec": {
|
108 |
+
"display_name": "base",
|
109 |
+
"language": "python",
|
110 |
+
"name": "python3"
|
111 |
+
},
|
112 |
+
"language_info": {
|
113 |
+
"codemirror_mode": {
|
114 |
+
"name": "ipython",
|
115 |
+
"version": 3
|
116 |
+
},
|
117 |
+
"file_extension": ".py",
|
118 |
+
"mimetype": "text/x-python",
|
119 |
+
"name": "python",
|
120 |
+
"nbconvert_exporter": "python",
|
121 |
+
"pygments_lexer": "ipython3",
|
122 |
+
"version": "3.8.8"
|
123 |
+
},
|
124 |
+
"orig_nbformat": 4,
|
125 |
+
"vscode": {
|
126 |
+
"interpreter": {
|
127 |
+
"hash": "793ac646cb1bdfbbf9b49ec8438cf418377ae0464a060bb58045a63a1c103122"
|
128 |
+
}
|
129 |
+
}
|
130 |
+
},
|
131 |
+
"nbformat": 4,
|
132 |
+
"nbformat_minor": 2
|
133 |
+
}
|
app.py
CHANGED
@@ -1,7 +1,21 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
-
iface.launch()
|
|
|
1 |
+
|
2 |
+
from fastai.vision.all import *
|
3 |
import gradio as gr
|
4 |
|
5 |
+
def is_cat(x): return x[0].isupper()
|
6 |
+
import pathlib
|
7 |
+
temp = pathlib.PosixPath
|
8 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
9 |
+
learn = load_learner('model.pkl')
|
10 |
+
pathlib.PosixPath = temp
|
11 |
+
categories = ('Dog', 'Cat')
|
12 |
+
def classify_image(img):
|
13 |
+
pred,idx,probs = learn.predict(img)
|
14 |
+
return dict(zip(categories, map(float, probs)))
|
15 |
+
image = gr.inputs.Image(shape=(192,192))
|
16 |
+
label = gr.outputs.Label()
|
17 |
+
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
|
18 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
19 |
+
intf.launch(inline=False)
|
20 |
+
|
21 |
|
|
|
|
app_old.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def greet(name):
|
4 |
+
return "Hello " + name + "!!"
|
5 |
+
|
6 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
+
iface.launch()
|
cat.jpg
ADDED
![]() |
dog.jpg
ADDED
![]() |
dunno.jpg
ADDED
![]() |
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:973902c0345a943c47acdfc4b5db1e51c338c0cd314d59f9cd910451841bfe7e
|
3 |
+
size 47061483
|