jeffreymjohnson commited on
Commit
b9391cc
·
1 Parent(s): 92b42f4

Added using shared learner

Browse files
Files changed (2) hide show
  1. Deadpool-Detector.ipynb +193 -78
  2. app.py +1 -2
Deadpool-Detector.ipynb CHANGED
@@ -37,68 +37,6 @@
37
  "Using [SH2022 Dataset](https://www.kaggle.com/datasets/muhammadhananasghar/sh2022-dataset) there is a labeled set of Deadpool images."
38
  ]
39
  },
40
- {
41
- "cell_type": "code",
42
- "execution_count": 102,
43
- "id": "61850308-6410-412b-a0a3-2a9c8c5ac982",
44
- "metadata": {},
45
- "outputs": [],
46
- "source": [
47
- "#|default_exp app"
48
- ]
49
- },
50
- {
51
- "cell_type": "code",
52
- "execution_count": 103,
53
- "id": "3e665c52-32ba-40a7-b100-480e60d128f6",
54
- "metadata": {},
55
- "outputs": [],
56
- "source": [
57
- "from fastai.vision.all import *"
58
- ]
59
- },
60
- {
61
- "cell_type": "code",
62
- "execution_count": null,
63
- "id": "6697efd8-df96-4db1-834a-9136c6d71ebb",
64
- "metadata": {},
65
- "outputs": [],
66
- "source": [
67
- "# copy test data to project if not there already\n",
68
- "data_path = Path(\"/home/zeus/data/SH2022/\")\n",
69
- "data_path.ls()"
70
- ]
71
- },
72
- {
73
- "cell_type": "markdown",
74
- "id": "04538e6b-bc2e-4ef6-b5b7-3134185ba01c",
75
- "metadata": {},
76
- "source": [
77
- "Load the data"
78
- ]
79
- },
80
- {
81
- "cell_type": "code",
82
- "execution_count": null,
83
- "id": "7e40d0c6-7118-4b31-8304-f0fdb1f3c490",
84
- "metadata": {},
85
- "outputs": [],
86
- "source": [
87
- "train_files = get_image_files(data_path/\"train\")\n",
88
- "len(train_files)"
89
- ]
90
- },
91
- {
92
- "cell_type": "code",
93
- "execution_count": null,
94
- "id": "f3e72099-446d-4e7b-8a6d-a6111f6c8556",
95
- "metadata": {},
96
- "outputs": [],
97
- "source": [
98
- "test_files = get_image_files(data_path/\"test/Deadpool\")\n",
99
- "len(test_files)"
100
- ]
101
- },
102
  {
103
  "cell_type": "markdown",
104
  "id": "2549da81-e133-4f5d-93e2-e754885d9d99",
@@ -114,6 +52,10 @@
114
  "metadata": {},
115
  "outputs": [],
116
  "source": [
 
 
 
 
117
  "dls = ImageDataLoaders.from_folder(\n",
118
  " path=data_path,\n",
119
  " train='train',\n",
@@ -162,38 +104,170 @@
162
  ]
163
  },
164
  {
 
165
  "cell_type": "markdown",
166
- "id": "61b3019d-cd37-49b4-bced-503499796d6c",
167
  "metadata": {},
168
  "source": [
169
- "# Create App"
170
  ]
171
  },
172
  {
173
  "cell_type": "code",
174
- "execution_count": 104,
175
- "id": "f678e4ce-6b99-45b2-ae12-3e3a6978fe0a",
176
  "metadata": {},
177
  "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  "source": [
179
- "#|export\n",
180
- "from fastai.vision.all import *"
 
 
 
 
 
 
 
 
 
 
 
181
  ]
182
  },
183
  {
184
  "cell_type": "code",
185
- "execution_count": 105,
186
- "id": "cebedb5a-32ed-483d-90ce-9ccf101bda42",
187
  "metadata": {},
188
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  "source": [
190
  "#|export\n",
191
- "learn = load_learner('/home/zeus/projects/Deadpool-Detector/deadpool-detection-model.pkl')"
 
 
192
  ]
193
  },
194
  {
195
  "cell_type": "code",
196
- "execution_count": 106,
197
  "id": "cc0fa8a2-51fe-4591-9056-e84e0fec9af7",
198
  "metadata": {},
199
  "outputs": [],
@@ -216,7 +290,7 @@
216
  " else:\n",
217
  " x = \"is not\"\n",
218
  " \n",
219
- " print(\"The probability is: [\" + str(probability) + \"] that this \" + x + \" Deadpool\")\n",
220
  " \n",
221
  " if probability < .75:\n",
222
  " return PILImage.create(what_reaction)\n",
@@ -228,7 +302,7 @@
228
  },
229
  {
230
  "cell_type": "code",
231
- "execution_count": 107,
232
  "id": "3cec4455-8159-457b-9563-7e41aa202dc1",
233
  "metadata": {
234
  "tags": []
@@ -238,8 +312,8 @@
238
  "name": "stdout",
239
  "output_type": "stream",
240
  "text": [
241
- "Running on local URL: http://127.0.0.1:7905\n",
242
- "Running on public URL: https://db2b51c5e39e6fc032.gradio.live\n",
243
  "\n",
244
  "This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n"
245
  ]
@@ -247,7 +321,7 @@
247
  {
248
  "data": {
249
  "text/html": [
250
- "<div><iframe src=\"https://db2b51c5e39e6fc032.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
251
  ],
252
  "text/plain": [
253
  "<IPython.core.display.HTML object>"
@@ -255,6 +329,47 @@
255
  },
256
  "metadata": {},
257
  "output_type": "display_data"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  }
259
  ],
260
  "source": [
 
37
  "Using [SH2022 Dataset](https://www.kaggle.com/datasets/muhammadhananasghar/sh2022-dataset) there is a labeled set of Deadpool images."
38
  ]
39
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  {
41
  "cell_type": "markdown",
42
  "id": "2549da81-e133-4f5d-93e2-e754885d9d99",
 
52
  "metadata": {},
53
  "outputs": [],
54
  "source": [
55
+ "from fastai.vision.all import *\n",
56
+ "\n",
57
+ "data_path = Path('/home/zeus/data/SH2022')\n",
58
+ "\n",
59
  "dls = ImageDataLoaders.from_folder(\n",
60
  " path=data_path,\n",
61
  " train='train',\n",
 
104
  ]
105
  },
106
  {
107
+ "attachments": {},
108
  "cell_type": "markdown",
109
+ "id": "792d8a70",
110
  "metadata": {},
111
  "source": [
112
+ "## Share Learner with the world!"
113
  ]
114
  },
115
  {
116
  "cell_type": "code",
117
+ "execution_count": 4,
118
+ "id": "27376bb5",
119
  "metadata": {},
120
  "outputs": [],
121
+ "source": []
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "execution_count": 5,
126
+ "id": "14796a3e",
127
+ "metadata": {},
128
+ "outputs": [
129
+ {
130
+ "data": {
131
+ "application/vnd.jupyter.widget-view+json": {
132
+ "model_id": "491daa3086dd4a109f036d62bdecf5fa",
133
+ "version_major": 2,
134
+ "version_minor": 0
135
+ },
136
+ "text/plain": [
137
+ "Upload 1 LFS files: 0%| | 0/1 [00:00<?, ?it/s]"
138
+ ]
139
+ },
140
+ "metadata": {},
141
+ "output_type": "display_data"
142
+ },
143
+ {
144
+ "data": {
145
+ "application/vnd.jupyter.widget-view+json": {
146
+ "model_id": "46bae672442548c18d955a6d8c7ed5ad",
147
+ "version_major": 2,
148
+ "version_minor": 0
149
+ },
150
+ "text/plain": [
151
+ "model.pkl: 0%| | 0.00/88.7M [00:00<?, ?B/s]"
152
+ ]
153
+ },
154
+ "metadata": {},
155
+ "output_type": "display_data"
156
+ },
157
+ {
158
+ "data": {
159
+ "text/plain": [
160
+ "'https://huggingface.co/jeffreymjohnson/Deadpool-Detector/tree/main/'"
161
+ ]
162
+ },
163
+ "execution_count": 5,
164
+ "metadata": {},
165
+ "output_type": "execute_result"
166
+ }
167
+ ],
168
  "source": [
169
+ "from huggingface_hub import push_to_hub_fastai\n",
170
+ "\n",
171
+ "learn = load_learner('/home/zeus/projects/Deadpool-Detector/deadpool-detection-model.pkl')\n",
172
+ "repo_id = \"jeffreymjohnson/Deadpool-Detector\"\n",
173
+ "push_to_hub_fastai(learner=learn, repo_id=repo_id)"
174
+ ]
175
+ },
176
+ {
177
+ "cell_type": "markdown",
178
+ "id": "61b3019d-cd37-49b4-bced-503499796d6c",
179
+ "metadata": {},
180
+ "source": [
181
+ "# Create App"
182
  ]
183
  },
184
  {
185
  "cell_type": "code",
186
+ "execution_count": 7,
187
+ "id": "f678e4ce-6b99-45b2-ae12-3e3a6978fe0a",
188
  "metadata": {},
189
+ "outputs": [
190
+ {
191
+ "data": {
192
+ "application/vnd.jupyter.widget-view+json": {
193
+ "model_id": "a5c9312bd4be458e8694df43a510adcc",
194
+ "version_major": 2,
195
+ "version_minor": 0
196
+ },
197
+ "text/plain": [
198
+ "Fetching 4 files: 0%| | 0/4 [00:00<?, ?it/s]"
199
+ ]
200
+ },
201
+ "metadata": {},
202
+ "output_type": "display_data"
203
+ },
204
+ {
205
+ "data": {
206
+ "application/vnd.jupyter.widget-view+json": {
207
+ "model_id": "86445259808342c7895ef51c3c30a27b",
208
+ "version_major": 2,
209
+ "version_minor": 0
210
+ },
211
+ "text/plain": [
212
+ "Downloading (…)3b40e/.gitattributes: 0%| | 0.00/1.48k [00:00<?, ?B/s]"
213
+ ]
214
+ },
215
+ "metadata": {},
216
+ "output_type": "display_data"
217
+ },
218
+ {
219
+ "data": {
220
+ "application/vnd.jupyter.widget-view+json": {
221
+ "model_id": "0f5c6206271041c2b3d978afff8af373",
222
+ "version_major": 2,
223
+ "version_minor": 0
224
+ },
225
+ "text/plain": [
226
+ "Downloading (…)4d02d3b40e/README.md: 0%| | 0.00/768 [00:00<?, ?B/s]"
227
+ ]
228
+ },
229
+ "metadata": {},
230
+ "output_type": "display_data"
231
+ },
232
+ {
233
+ "data": {
234
+ "application/vnd.jupyter.widget-view+json": {
235
+ "model_id": "576a45913eff4216bac8db9e6a3bd8f5",
236
+ "version_major": 2,
237
+ "version_minor": 0
238
+ },
239
+ "text/plain": [
240
+ "Downloading (…)3b40e/pyproject.toml: 0%| | 0.00/162 [00:00<?, ?B/s]"
241
+ ]
242
+ },
243
+ "metadata": {},
244
+ "output_type": "display_data"
245
+ },
246
+ {
247
+ "data": {
248
+ "application/vnd.jupyter.widget-view+json": {
249
+ "model_id": "c847d69e1eab41b6bc51f1e65124ed5f",
250
+ "version_major": 2,
251
+ "version_minor": 0
252
+ },
253
+ "text/plain": [
254
+ "Downloading model.pkl: 0%| | 0.00/88.7M [00:00<?, ?B/s]"
255
+ ]
256
+ },
257
+ "metadata": {},
258
+ "output_type": "display_data"
259
+ }
260
+ ],
261
  "source": [
262
  "#|export\n",
263
+ "from huggingface_hub import from_pretrained_fastai\n",
264
+ "\n",
265
+ "learner = from_pretrained_fastai(\"jeffreymjohnson/Deadpool-Detector\")"
266
  ]
267
  },
268
  {
269
  "cell_type": "code",
270
+ "execution_count": 8,
271
  "id": "cc0fa8a2-51fe-4591-9056-e84e0fec9af7",
272
  "metadata": {},
273
  "outputs": [],
 
290
  " else:\n",
291
  " x = \"is not\"\n",
292
  " \n",
293
+ " #print(\"The probability is: [\" + str(probability) + \"] that this \" + x + \" Deadpool\")\n",
294
  " \n",
295
  " if probability < .75:\n",
296
  " return PILImage.create(what_reaction)\n",
 
302
  },
303
  {
304
  "cell_type": "code",
305
+ "execution_count": 9,
306
  "id": "3cec4455-8159-457b-9563-7e41aa202dc1",
307
  "metadata": {
308
  "tags": []
 
312
  "name": "stdout",
313
  "output_type": "stream",
314
  "text": [
315
+ "Running on local URL: http://127.0.0.1:7860\n",
316
+ "Running on public URL: https://ed025bd9d3a5e5798f.gradio.live\n",
317
  "\n",
318
  "This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n"
319
  ]
 
321
  {
322
  "data": {
323
  "text/html": [
324
+ "<div><iframe src=\"https://ed025bd9d3a5e5798f.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
325
  ],
326
  "text/plain": [
327
  "<IPython.core.display.HTML object>"
 
329
  },
330
  "metadata": {},
331
  "output_type": "display_data"
332
+ },
333
+ {
334
+ "name": "stdout",
335
+ "output_type": "stream",
336
+ "text": [
337
+ "The probability is: [0.9999980926513672] that this is Deadpool\n"
338
+ ]
339
+ },
340
+ {
341
+ "data": {
342
+ "text/html": [
343
+ "\n",
344
+ "<style>\n",
345
+ " /* Turns off some styling */\n",
346
+ " progress {\n",
347
+ " /* gets rid of default border in Firefox and Opera. */\n",
348
+ " border: none;\n",
349
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
350
+ " background-size: auto;\n",
351
+ " }\n",
352
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
353
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
354
+ " }\n",
355
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
356
+ " background: #F44336;\n",
357
+ " }\n",
358
+ "</style>\n"
359
+ ],
360
+ "text/plain": [
361
+ "<IPython.core.display.HTML object>"
362
+ ]
363
+ },
364
+ "metadata": {},
365
+ "output_type": "display_data"
366
+ },
367
+ {
368
+ "name": "stdout",
369
+ "output_type": "stream",
370
+ "text": [
371
+ "The probability is: [0.9999998807907104] that this is not Deadpool\n"
372
+ ]
373
  }
374
  ],
375
  "source": [
app.py CHANGED
@@ -1,7 +1,7 @@
1
  from huggingface_hub import from_pretrained_fastai
2
  import gradio as gr
3
 
4
- learn = from_pretrained_fastai('./deadpool-detection-model.pkl')
5
 
6
  labels = learn.dls.vocab
7
 
@@ -21,7 +21,6 @@ def predict(img):
21
  else:
22
  x = "is not"
23
 
24
- print("The probability is: [" + str(probability) + "] that this " + x + " Deadpool")
25
 
26
  if probability < .75:
27
  return PILImage.create(what_reaction)
 
1
  from huggingface_hub import from_pretrained_fastai
2
  import gradio as gr
3
 
4
+ learn = from_pretrained_fastai("jeffreymjohnson/Deadpool-Detector")
5
 
6
  labels = learn.dls.vocab
7
 
 
21
  else:
22
  x = "is not"
23
 
 
24
 
25
  if probability < .75:
26
  return PILImage.create(what_reaction)