Aryan Kumar commited on
Commit
625fbd2
1 Parent(s): 0e5d980

modified: app.ipynb

Browse files
Files changed (2) hide show
  1. app.ipynb +47 -26
  2. app.py +26 -4
app.ipynb CHANGED
@@ -15,46 +15,75 @@
15
  "id": "026f4508",
16
  "metadata": {},
17
  "source": [
18
- "### Dogs V Cats"
19
  ]
20
  },
21
  {
22
  "cell_type": "code",
23
- "execution_count": 28,
24
  "id": "ed9b1499",
25
  "metadata": {},
26
  "outputs": [],
27
  "source": [
28
  "#|export\n",
29
  "from fastai.vision.all import *\n",
30
- "import gradio as gr\n"
 
 
 
 
 
 
31
  ]
32
  },
33
  {
34
  "cell_type": "code",
35
- "execution_count": 29,
36
  "id": "7b05e3e0",
37
  "metadata": {},
38
  "outputs": [],
39
  "source": [
40
  "#|export\n",
41
- "def is_cat(x): return x[0].isupper() "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ]
43
  },
44
  {
45
  "cell_type": "code",
46
- "execution_count": 30,
47
  "id": "0407168f",
48
  "metadata": {},
49
- "outputs": [],
 
 
 
 
 
 
 
 
50
  "source": [
51
  "#|export\n",
52
- "learn = load_learner('export.pkl')"
 
53
  ]
54
  },
55
  {
56
  "cell_type": "code",
57
- "execution_count": 18,
58
  "id": "d3b1540f",
59
  "metadata": {},
60
  "outputs": [
@@ -65,7 +94,7 @@
65
  "PILImage mode=RGB size=192x192"
66
  ]
67
  },
68
- "execution_count": 18,
69
  "metadata": {},
70
  "output_type": "execute_result"
71
  }
@@ -81,7 +110,7 @@
81
  },
82
  {
83
  "cell_type": "code",
84
- "execution_count": 19,
85
  "id": "ac681618",
86
  "metadata": {},
87
  "outputs": [
@@ -126,8 +155,8 @@
126
  "name": "stdout",
127
  "output_type": "stream",
128
  "text": [
129
- "CPU times: total: 156 ms\n",
130
- "Wall time: 112 ms\n"
131
  ]
132
  },
133
  {
@@ -136,7 +165,7 @@
136
  "('teddy', tensor(2), tensor([1.6561e-06, 1.1294e-16, 1.0000e+00]))"
137
  ]
138
  },
139
- "execution_count": 19,
140
  "metadata": {},
141
  "output_type": "execute_result"
142
  }
@@ -147,7 +176,7 @@
147
  },
148
  {
149
  "cell_type": "code",
150
- "execution_count": 31,
151
  "id": "9f3a2ab2",
152
  "metadata": {},
153
  "outputs": [],
@@ -158,7 +187,7 @@
158
  },
159
  {
160
  "cell_type": "code",
161
- "execution_count": 32,
162
  "id": "c476f09a",
163
  "metadata": {},
164
  "outputs": [],
@@ -171,18 +200,10 @@
171
  },
172
  {
173
  "cell_type": "code",
174
- "execution_count": 34,
175
  "id": "09839ebb",
176
  "metadata": {},
177
  "outputs": [
178
- {
179
- "name": "stderr",
180
- "output_type": "stream",
181
- "text": [
182
- "C:\\Users\\teent\\anaconda3\\Lib\\site-packages\\fastai\\torch_core.py:263: UserWarning: 'has_mps' is deprecated, please use 'torch.backends.mps.is_built()'\n",
183
- " return getattr(torch, 'has_mps', False)\n"
184
- ]
185
- },
186
  {
187
  "data": {
188
  "text/html": [
@@ -228,7 +249,7 @@
228
  " 'teddy': 0.9999983310699463}"
229
  ]
230
  },
231
- "execution_count": 34,
232
  "metadata": {},
233
  "output_type": "execute_result"
234
  }
 
15
  "id": "026f4508",
16
  "metadata": {},
17
  "source": [
18
+ "### Bear Classifier"
19
  ]
20
  },
21
  {
22
  "cell_type": "code",
23
+ "execution_count": 54,
24
  "id": "ed9b1499",
25
  "metadata": {},
26
  "outputs": [],
27
  "source": [
28
  "#|export\n",
29
  "from fastai.vision.all import *\n",
30
+ "import gradio as gr\n",
31
+ "from fastbook import *\n",
32
+ "from fastai.vision.widgets import *\n",
33
+ "import gradio as gr\n",
34
+ "btn_upload = widgets.FileUpload()\n",
35
+ "out_pl = widgets.Output()\n",
36
+ "lbl_pred = widgets.Label()"
37
  ]
38
  },
39
  {
40
  "cell_type": "code",
41
+ "execution_count": 55,
42
  "id": "7b05e3e0",
43
  "metadata": {},
44
  "outputs": [],
45
  "source": [
46
  "#|export\n",
47
+ "# def on_data_change(change):\n",
48
+ "# lbl_pred.value = ''\n",
49
+ "# img = PILImage.create(btn_upload.data[-1])\n",
50
+ "# out_pl.clear_output()\n",
51
+ "# with out_pl: display(img.to_thumb(128,128))\n",
52
+ "# pred,pred_idx,probs = learn_inf.predict(img)\n",
53
+ "# lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'\n",
54
+ "\n",
55
+ "class DataLoaders(GetAttr):\n",
56
+ " def __init__(self, *loaders): self.loaders = loaders\n",
57
+ " def __getitem__(self, i): return self.loaders[i]\n",
58
+ " train,valid = add_props(lambda i,self: self[i])\n",
59
+ " \n",
60
+ "def is_cat(x): return x[0].isupper()\n",
61
+ "\n"
62
  ]
63
  },
64
  {
65
  "cell_type": "code",
66
+ "execution_count": 56,
67
  "id": "0407168f",
68
  "metadata": {},
69
+ "outputs": [
70
+ {
71
+ "name": "stdout",
72
+ "output_type": "stream",
73
+ "text": [
74
+ "<class 'fastai.learner.Learner'>\n"
75
+ ]
76
+ }
77
+ ],
78
  "source": [
79
  "#|export\n",
80
+ "learn = load_learner('export.pkl')\n",
81
+ "print(type(learn))"
82
  ]
83
  },
84
  {
85
  "cell_type": "code",
86
+ "execution_count": 57,
87
  "id": "d3b1540f",
88
  "metadata": {},
89
  "outputs": [
 
94
  "PILImage mode=RGB size=192x192"
95
  ]
96
  },
97
+ "execution_count": 57,
98
  "metadata": {},
99
  "output_type": "execute_result"
100
  }
 
110
  },
111
  {
112
  "cell_type": "code",
113
+ "execution_count": 58,
114
  "id": "ac681618",
115
  "metadata": {},
116
  "outputs": [
 
155
  "name": "stdout",
156
  "output_type": "stream",
157
  "text": [
158
+ "CPU times: total: 172 ms\n",
159
+ "Wall time: 292 ms\n"
160
  ]
161
  },
162
  {
 
165
  "('teddy', tensor(2), tensor([1.6561e-06, 1.1294e-16, 1.0000e+00]))"
166
  ]
167
  },
168
+ "execution_count": 58,
169
  "metadata": {},
170
  "output_type": "execute_result"
171
  }
 
176
  },
177
  {
178
  "cell_type": "code",
179
+ "execution_count": 59,
180
  "id": "9f3a2ab2",
181
  "metadata": {},
182
  "outputs": [],
 
187
  },
188
  {
189
  "cell_type": "code",
190
+ "execution_count": 60,
191
  "id": "c476f09a",
192
  "metadata": {},
193
  "outputs": [],
 
200
  },
201
  {
202
  "cell_type": "code",
203
+ "execution_count": 61,
204
  "id": "09839ebb",
205
  "metadata": {},
206
  "outputs": [
 
 
 
 
 
 
 
 
207
  {
208
  "data": {
209
  "text/html": [
 
249
  " 'teddy': 0.9999983310699463}"
250
  ]
251
  },
252
+ "execution_count": 61,
253
  "metadata": {},
254
  "output_type": "execute_result"
255
  }
app.py CHANGED
@@ -1,18 +1,40 @@
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
 
3
  # %% auto 0
4
- __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_img']
 
5
 
6
  # %% app.ipynb 2
7
- from fastai.vision.all import *
8
  import gradio as gr
9
-
 
 
 
 
 
10
 
11
  # %% app.ipynb 3
12
- def is_cat(x): return x[0].isupper()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # %% app.ipynb 4
15
  learn = load_learner('export.pkl')
 
16
 
17
  # %% app.ipynb 7
18
  categories = ('black', 'grizzly', 'teddy')
 
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
 
3
  # %% auto 0
4
+ __all__ = ['btn_upload', 'out_pl', 'lbl_pred', 'learn', 'categories', 'image', 'label', 'examples', 'intf', 'DataLoaders',
5
+ 'is_cat', 'classify_img']
6
 
7
  # %% app.ipynb 2
8
+ from fastai.vision.all import *
9
  import gradio as gr
10
+ from fastbook import *
11
+ from fastai.vision.widgets import *
12
+ import gradio as gr
13
+ btn_upload = widgets.FileUpload()
14
+ out_pl = widgets.Output()
15
+ lbl_pred = widgets.Label()
16
 
17
  # %% app.ipynb 3
18
+ # def on_data_change(change):
19
+ # lbl_pred.value = ''
20
+ # img = PILImage.create(btn_upload.data[-1])
21
+ # out_pl.clear_output()
22
+ # with out_pl: display(img.to_thumb(128,128))
23
+ # pred,pred_idx,probs = learn_inf.predict(img)
24
+ # lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
25
+
26
+ class DataLoaders(GetAttr):
27
+ def __init__(self, *loaders): self.loaders = loaders
28
+ def __getitem__(self, i): return self.loaders[i]
29
+ train,valid = add_props(lambda i,self: self[i])
30
+
31
+ def is_cat(x): return x[0].isupper()
32
+
33
+
34
 
35
  # %% app.ipynb 4
36
  learn = load_learner('export.pkl')
37
+ print(type(learn))
38
 
39
  # %% app.ipynb 7
40
  categories = ('black', 'grizzly', 'teddy')