devudilip commited on
Commit
4b9fc54
·
1 Parent(s): 6ed6ec2
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
.ipynb_checkpoints/classifier-checkpoint.ipynb ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [],
3
+ "metadata": {},
4
+ "nbformat": 4,
5
+ "nbformat_minor": 5
6
+ }
app.py CHANGED
@@ -1,9 +1,11 @@
1
  from fastai.vision.all import *
2
  import gradio as gr
 
3
 
4
  def is_cat(x): return x[0].isupper()
5
 
6
- learn = load_learner('modeltest.pkl')
 
7
 
8
  categories = ('Dog', 'Cat')
9
 
 
1
  from fastai.vision.all import *
2
  import gradio as gr
3
+ import dill
4
 
5
  def is_cat(x): return x[0].isupper()
6
 
7
+ learn = load_learner('model.pkl', pickle_module=dill)
8
+
9
 
10
  categories = ('Dog', 'Cat')
11
 
classifier.ipynb ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "bf596b85",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "!pip install -Uqq fastai"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 3,
16
+ "id": "f6529ac6",
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "name": "stdout",
21
+ "output_type": "stream",
22
+ "text": [
23
+ "/Users/devudilip/projects/AI/fastai_pet_classifier\r\n"
24
+ ]
25
+ }
26
+ ],
27
+ "source": [
28
+ "!pwd"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": 11,
34
+ "id": "0473c217",
35
+ "metadata": {},
36
+ "outputs": [
37
+ {
38
+ "name": "stdout",
39
+ "output_type": "stream",
40
+ "text": [
41
+ "fastai: 2.8.0\n",
42
+ "fastcore: 1.8.0\n",
43
+ "torch: 2.4.1\n"
44
+ ]
45
+ }
46
+ ],
47
+ "source": [
48
+ "import fastai\n",
49
+ "import fastcore\n",
50
+ "import torch\n",
51
+ "\n",
52
+ "print(f\"fastai: {fastai.__version__}\")\n",
53
+ "print(f\"fastcore: {fastcore.__version__}\")\n",
54
+ "print(f\"torch: {torch.__version__}\")"
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": 13,
60
+ "id": "15b4cdfd",
61
+ "metadata": {},
62
+ "outputs": [],
63
+ "source": [
64
+ "from fastai.vision.all import *\n",
65
+ "import dill"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 5,
71
+ "id": "399533a7",
72
+ "metadata": {},
73
+ "outputs": [],
74
+ "source": [
75
+ "path = untar_data(URLs.PETS)/'images'"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": 6,
81
+ "id": "51e0bbe2",
82
+ "metadata": {},
83
+ "outputs": [],
84
+ "source": [
85
+ "def is_cat(x): return x[0].isupper() "
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": 7,
91
+ "id": "915cbf12",
92
+ "metadata": {},
93
+ "outputs": [],
94
+ "source": [
95
+ "dls = ImageDataLoaders.from_name_func('.',\n",
96
+ " get_image_files(path), valid_pct=0.2, seed=42,\n",
97
+ " label_func=is_cat,\n",
98
+ " item_tfms=Resize(192))"
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "execution_count": 8,
104
+ "id": "9bae55cc",
105
+ "metadata": {},
106
+ "outputs": [
107
+ {
108
+ "name": "stderr",
109
+ "output_type": "stream",
110
+ "text": [
111
+ "Downloading: \"https://download.pytorch.org/models/resnet18-f37072fd.pth\" to /Users/devudilip/.cache/torch/hub/checkpoints/resnet18-f37072fd.pth\n",
112
+ "100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44.7M/44.7M [00:09<00:00, 4.89MB/s]\n"
113
+ ]
114
+ },
115
+ {
116
+ "data": {
117
+ "text/html": [
118
+ "\n",
119
+ "<style>\n",
120
+ " /* Turns off some styling */\n",
121
+ " progress {\n",
122
+ " /* gets rid of default border in Firefox and Opera. */\n",
123
+ " border: none;\n",
124
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
125
+ " background-size: auto;\n",
126
+ " }\n",
127
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
128
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
129
+ " }\n",
130
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
131
+ " background: #F44336;\n",
132
+ " }\n",
133
+ "</style>\n"
134
+ ],
135
+ "text/plain": [
136
+ "<IPython.core.display.HTML object>"
137
+ ]
138
+ },
139
+ "metadata": {},
140
+ "output_type": "display_data"
141
+ },
142
+ {
143
+ "data": {
144
+ "text/html": [
145
+ "<table border=\"1\" class=\"dataframe\">\n",
146
+ " <thead>\n",
147
+ " <tr style=\"text-align: left;\">\n",
148
+ " <th>epoch</th>\n",
149
+ " <th>train_loss</th>\n",
150
+ " <th>valid_loss</th>\n",
151
+ " <th>error_rate</th>\n",
152
+ " <th>time</th>\n",
153
+ " </tr>\n",
154
+ " </thead>\n",
155
+ " <tbody>\n",
156
+ " <tr>\n",
157
+ " <td>0</td>\n",
158
+ " <td>0.197639</td>\n",
159
+ " <td>0.045730</td>\n",
160
+ " <td>0.015562</td>\n",
161
+ " <td>01:37</td>\n",
162
+ " </tr>\n",
163
+ " </tbody>\n",
164
+ "</table>"
165
+ ],
166
+ "text/plain": [
167
+ "<IPython.core.display.HTML object>"
168
+ ]
169
+ },
170
+ "metadata": {},
171
+ "output_type": "display_data"
172
+ },
173
+ {
174
+ "data": {
175
+ "text/html": [
176
+ "\n",
177
+ "<style>\n",
178
+ " /* Turns off some styling */\n",
179
+ " progress {\n",
180
+ " /* gets rid of default border in Firefox and Opera. */\n",
181
+ " border: none;\n",
182
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
183
+ " background-size: auto;\n",
184
+ " }\n",
185
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
186
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
187
+ " }\n",
188
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
189
+ " background: #F44336;\n",
190
+ " }\n",
191
+ "</style>\n"
192
+ ],
193
+ "text/plain": [
194
+ "<IPython.core.display.HTML object>"
195
+ ]
196
+ },
197
+ "metadata": {},
198
+ "output_type": "display_data"
199
+ },
200
+ {
201
+ "data": {
202
+ "text/html": [
203
+ "<table border=\"1\" class=\"dataframe\">\n",
204
+ " <thead>\n",
205
+ " <tr style=\"text-align: left;\">\n",
206
+ " <th>epoch</th>\n",
207
+ " <th>train_loss</th>\n",
208
+ " <th>valid_loss</th>\n",
209
+ " <th>error_rate</th>\n",
210
+ " <th>time</th>\n",
211
+ " </tr>\n",
212
+ " </thead>\n",
213
+ " <tbody>\n",
214
+ " <tr>\n",
215
+ " <td>0</td>\n",
216
+ " <td>0.078331</td>\n",
217
+ " <td>0.054597</td>\n",
218
+ " <td>0.018268</td>\n",
219
+ " <td>02:22</td>\n",
220
+ " </tr>\n",
221
+ " <tr>\n",
222
+ " <td>1</td>\n",
223
+ " <td>0.049279</td>\n",
224
+ " <td>0.038220</td>\n",
225
+ " <td>0.010149</td>\n",
226
+ " <td>02:40</td>\n",
227
+ " </tr>\n",
228
+ " <tr>\n",
229
+ " <td>2</td>\n",
230
+ " <td>0.023927</td>\n",
231
+ " <td>0.026168</td>\n",
232
+ " <td>0.008796</td>\n",
233
+ " <td>02:56</td>\n",
234
+ " </tr>\n",
235
+ " </tbody>\n",
236
+ "</table>"
237
+ ],
238
+ "text/plain": [
239
+ "<IPython.core.display.HTML object>"
240
+ ]
241
+ },
242
+ "metadata": {},
243
+ "output_type": "display_data"
244
+ }
245
+ ],
246
+ "source": [
247
+ "learn = vision_learner(dls, resnet18, metrics=error_rate)\n",
248
+ "learn.fine_tune(3)"
249
+ ]
250
+ },
251
+ {
252
+ "cell_type": "code",
253
+ "execution_count": 14,
254
+ "id": "9119ee21",
255
+ "metadata": {},
256
+ "outputs": [],
257
+ "source": [
258
+ "learn.export('model.pkl', pickle_module=dill)"
259
+ ]
260
+ },
261
+ {
262
+ "cell_type": "code",
263
+ "execution_count": null,
264
+ "id": "25a3e6c4",
265
+ "metadata": {},
266
+ "outputs": [],
267
+ "source": []
268
+ }
269
+ ],
270
+ "metadata": {
271
+ "kernelspec": {
272
+ "display_name": "Python 3 (ipykernel)",
273
+ "language": "python",
274
+ "name": "python3"
275
+ },
276
+ "language_info": {
277
+ "codemirror_mode": {
278
+ "name": "ipython",
279
+ "version": 3
280
+ },
281
+ "file_extension": ".py",
282
+ "mimetype": "text/x-python",
283
+ "name": "python",
284
+ "nbconvert_exporter": "python",
285
+ "pygments_lexer": "ipython3",
286
+ "version": "3.12.9"
287
+ },
288
+ "toc": {
289
+ "base_numbering": 1,
290
+ "nav_menu": {},
291
+ "number_sections": true,
292
+ "sideBar": true,
293
+ "skip_h1_title": false,
294
+ "title_cell": "Table of Contents",
295
+ "title_sidebar": "Contents",
296
+ "toc_cell": false,
297
+ "toc_position": {},
298
+ "toc_section_display": true,
299
+ "toc_window_display": false
300
+ }
301
+ },
302
+ "nbformat": 4,
303
+ "nbformat_minor": 5
304
+ }
modeltest.pkl → model.pkl RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1c09d8f778f89c9eb588eefd9a5ba094eb163cd3ea708a4ea567a83e924f149f
3
- size 47059947
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b53c746618a12fcedee7bb22ac77b0613b4a520bdfefb943040ebed2b0d278c5
3
+ size 47063358