Spaces:
Runtime error
Runtime error
Commit
·
a99ddf7
1
Parent(s):
7344cc8
New try, cats and dogs classifier
Browse files- .ipynb_checkpoints/Cats and Dogs classifier test notebook-checkpoint.ipynb +6 -0
- Cat.jpg +0 -0
- Cats and Dogs classifier test notebook.ipynb +221 -0
- Dog.jpg +0 -0
- Dunno.jpg +0 -0
- app.py +4 -4
.ipynb_checkpoints/Cats and Dogs classifier test notebook-checkpoint.ipynb
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [],
|
| 3 |
+
"metadata": {},
|
| 4 |
+
"nbformat": 4,
|
| 5 |
+
"nbformat_minor": 5
|
| 6 |
+
}
|
Cat.jpg
ADDED
|
Cats and Dogs classifier test notebook.ipynb
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 3,
|
| 6 |
+
"id": "78be2d94",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"from fastai.vision.all import *\n",
|
| 11 |
+
"import gradio as gr\n",
|
| 12 |
+
"\n",
|
| 13 |
+
"def is_cat(x): return x[0].isupper()\n",
|
| 14 |
+
"\n",
|
| 15 |
+
"learn = load_learner('model.pkl')\n",
|
| 16 |
+
"\n",
|
| 17 |
+
"categories = ('Dog', 'Cat')\n",
|
| 18 |
+
"\n",
|
| 19 |
+
"def classify_image(img):\n",
|
| 20 |
+
" pred, idx, probs = learn.predict(img)\n",
|
| 21 |
+
" return(dict(zip(categories, map(float, probs))))\n",
|
| 22 |
+
"\n",
|
| 23 |
+
"\n",
|
| 24 |
+
"\n"
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"cell_type": "code",
|
| 29 |
+
"execution_count": 9,
|
| 30 |
+
"id": "99c2c0af",
|
| 31 |
+
"metadata": {},
|
| 32 |
+
"outputs": [],
|
| 33 |
+
"source": [
|
| 34 |
+
"image = gr.Image(shape=(192, 192))\n",
|
| 35 |
+
"label = gr.Label()\n",
|
| 36 |
+
"examples = ['Dog.jpg', 'Cat.jpg', 'Dunno.jpg']"
|
| 37 |
+
]
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"cell_type": "code",
|
| 41 |
+
"execution_count": 10,
|
| 42 |
+
"id": "d4474861",
|
| 43 |
+
"metadata": {},
|
| 44 |
+
"outputs": [
|
| 45 |
+
{
|
| 46 |
+
"name": "stdout",
|
| 47 |
+
"output_type": "stream",
|
| 48 |
+
"text": [
|
| 49 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
| 50 |
+
"\n",
|
| 51 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 52 |
+
]
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"data": {
|
| 56 |
+
"text/html": [
|
| 57 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 58 |
+
],
|
| 59 |
+
"text/plain": [
|
| 60 |
+
"<IPython.core.display.HTML object>"
|
| 61 |
+
]
|
| 62 |
+
},
|
| 63 |
+
"metadata": {},
|
| 64 |
+
"output_type": "display_data"
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"data": {
|
| 68 |
+
"text/plain": []
|
| 69 |
+
},
|
| 70 |
+
"execution_count": 10,
|
| 71 |
+
"metadata": {},
|
| 72 |
+
"output_type": "execute_result"
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"data": {
|
| 76 |
+
"text/html": [
|
| 77 |
+
"\n",
|
| 78 |
+
"<style>\n",
|
| 79 |
+
" /* Turns off some styling */\n",
|
| 80 |
+
" progress {\n",
|
| 81 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 82 |
+
" border: none;\n",
|
| 83 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 84 |
+
" background-size: auto;\n",
|
| 85 |
+
" }\n",
|
| 86 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 87 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 88 |
+
" }\n",
|
| 89 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 90 |
+
" background: #F44336;\n",
|
| 91 |
+
" }\n",
|
| 92 |
+
"</style>\n"
|
| 93 |
+
],
|
| 94 |
+
"text/plain": [
|
| 95 |
+
"<IPython.core.display.HTML object>"
|
| 96 |
+
]
|
| 97 |
+
},
|
| 98 |
+
"metadata": {},
|
| 99 |
+
"output_type": "display_data"
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"data": {
|
| 103 |
+
"text/html": [],
|
| 104 |
+
"text/plain": [
|
| 105 |
+
"<IPython.core.display.HTML object>"
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
"metadata": {},
|
| 109 |
+
"output_type": "display_data"
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"data": {
|
| 113 |
+
"text/html": [
|
| 114 |
+
"\n",
|
| 115 |
+
"<style>\n",
|
| 116 |
+
" /* Turns off some styling */\n",
|
| 117 |
+
" progress {\n",
|
| 118 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 119 |
+
" border: none;\n",
|
| 120 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 121 |
+
" background-size: auto;\n",
|
| 122 |
+
" }\n",
|
| 123 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 124 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 125 |
+
" }\n",
|
| 126 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 127 |
+
" background: #F44336;\n",
|
| 128 |
+
" }\n",
|
| 129 |
+
"</style>\n"
|
| 130 |
+
],
|
| 131 |
+
"text/plain": [
|
| 132 |
+
"<IPython.core.display.HTML object>"
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
"metadata": {},
|
| 136 |
+
"output_type": "display_data"
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"data": {
|
| 140 |
+
"text/html": [],
|
| 141 |
+
"text/plain": [
|
| 142 |
+
"<IPython.core.display.HTML object>"
|
| 143 |
+
]
|
| 144 |
+
},
|
| 145 |
+
"metadata": {},
|
| 146 |
+
"output_type": "display_data"
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"data": {
|
| 150 |
+
"text/html": [
|
| 151 |
+
"\n",
|
| 152 |
+
"<style>\n",
|
| 153 |
+
" /* Turns off some styling */\n",
|
| 154 |
+
" progress {\n",
|
| 155 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 156 |
+
" border: none;\n",
|
| 157 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 158 |
+
" background-size: auto;\n",
|
| 159 |
+
" }\n",
|
| 160 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 161 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 162 |
+
" }\n",
|
| 163 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 164 |
+
" background: #F44336;\n",
|
| 165 |
+
" }\n",
|
| 166 |
+
"</style>\n"
|
| 167 |
+
],
|
| 168 |
+
"text/plain": [
|
| 169 |
+
"<IPython.core.display.HTML object>"
|
| 170 |
+
]
|
| 171 |
+
},
|
| 172 |
+
"metadata": {},
|
| 173 |
+
"output_type": "display_data"
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"data": {
|
| 177 |
+
"text/html": [],
|
| 178 |
+
"text/plain": [
|
| 179 |
+
"<IPython.core.display.HTML object>"
|
| 180 |
+
]
|
| 181 |
+
},
|
| 182 |
+
"metadata": {},
|
| 183 |
+
"output_type": "display_data"
|
| 184 |
+
}
|
| 185 |
+
],
|
| 186 |
+
"source": [
|
| 187 |
+
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
|
| 188 |
+
"intf.launch(inline=True)"
|
| 189 |
+
]
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"cell_type": "code",
|
| 193 |
+
"execution_count": null,
|
| 194 |
+
"id": "fe07da74",
|
| 195 |
+
"metadata": {},
|
| 196 |
+
"outputs": [],
|
| 197 |
+
"source": []
|
| 198 |
+
}
|
| 199 |
+
],
|
| 200 |
+
"metadata": {
|
| 201 |
+
"kernelspec": {
|
| 202 |
+
"display_name": "Python 3 (ipykernel)",
|
| 203 |
+
"language": "python",
|
| 204 |
+
"name": "python3"
|
| 205 |
+
},
|
| 206 |
+
"language_info": {
|
| 207 |
+
"codemirror_mode": {
|
| 208 |
+
"name": "ipython",
|
| 209 |
+
"version": 3
|
| 210 |
+
},
|
| 211 |
+
"file_extension": ".py",
|
| 212 |
+
"mimetype": "text/x-python",
|
| 213 |
+
"name": "python",
|
| 214 |
+
"nbconvert_exporter": "python",
|
| 215 |
+
"pygments_lexer": "ipython3",
|
| 216 |
+
"version": "3.9.13"
|
| 217 |
+
}
|
| 218 |
+
},
|
| 219 |
+
"nbformat": 4,
|
| 220 |
+
"nbformat_minor": 5
|
| 221 |
+
}
|
Dog.jpg
ADDED
|
Dunno.jpg
ADDED
|
app.py
CHANGED
|
@@ -12,11 +12,11 @@ categories = ('Dog', 'Cat')
|
|
| 12 |
|
| 13 |
def classify_image(img):
|
| 14 |
pred, idx, probs = learn.predict(img)
|
| 15 |
-
return(dict(zip(categories, map(float, probs)))
|
| 16 |
|
| 17 |
-
image = gr.
|
| 18 |
-
label = gr.
|
| 19 |
-
examples = ['
|
| 20 |
|
| 21 |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 22 |
intf.launch(inline=False)
|
|
|
|
| 12 |
|
| 13 |
def classify_image(img):
|
| 14 |
pred, idx, probs = learn.predict(img)
|
| 15 |
+
return(dict(zip(categories, map(float, probs))))
|
| 16 |
|
| 17 |
+
image = gr.Image(shape=(192, 192))
|
| 18 |
+
label = gr.Label()
|
| 19 |
+
examples = ['Dog.jpg', 'Cat.jpg', 'Dunno.jpg']
|
| 20 |
|
| 21 |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 22 |
intf.launch(inline=False)
|