gbharti commited on
Commit
4b3a8d0
1 Parent(s): eed77db

Setup model

Browse files
.ipynb_checkpoints/README-checkpoint.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Fastai Model Reply
3
+ emoji: ⚡
4
+ colorFrom: blue
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 3.6
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
.ipynb_checkpoints/main-checkpoint.ipynb ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "41971c73-6b80-487e-acdc-836991e62c9d",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|default_exp main"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": null,
16
+ "id": "12171d9b-9822-461a-9c16-3925a275e859",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "#|export\n",
21
+ "from fastai.vision.all import *\n",
22
+ "import gradio as gr\n",
23
+ "\n",
24
+ "def is_cat(x): return x[0].isupper()"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": null,
30
+ "id": "5f678c6f-a7a8-4da2-845c-2c82f056e890",
31
+ "metadata": {},
32
+ "outputs": [],
33
+ "source": [
34
+ "path = untar_data(URLs.PETS)/'images'"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": null,
40
+ "id": "9a2dd42f-3fae-4bcf-a7a9-932dedb19684",
41
+ "metadata": {},
42
+ "outputs": [],
43
+ "source": [
44
+ "dls = ImageDataLoaders.from_name_func('.',\n",
45
+ " get_image_files(path), valid_pct=0.2, seed=42,\n",
46
+ " label_func=is_cat,\n",
47
+ " item_tfms=Resize(192))"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "execution_count": null,
53
+ "id": "09e8e2ad-30eb-45bc-aa4b-9fe5a256287a",
54
+ "metadata": {},
55
+ "outputs": [],
56
+ "source": [
57
+ "learn = vision_learner(dls, resnet18, metrics=error_rate)\n",
58
+ "learn.fine_tune(3)"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "execution_count": null,
64
+ "id": "b601d058-559a-4246-b4bb-2ad490d826f5",
65
+ "metadata": {},
66
+ "outputs": [],
67
+ "source": [
68
+ "learn.export('model.pkl')"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "execution_count": null,
74
+ "id": "5b01bcd5-5c99-4531-9f93-70dc32238dc4",
75
+ "metadata": {},
76
+ "outputs": [],
77
+ "source": [
78
+ "#|export\n",
79
+ "learn = load_learner('model.pkl')"
80
+ ]
81
+ },
82
+ {
83
+ "cell_type": "code",
84
+ "execution_count": null,
85
+ "id": "77bd55bf-2d8a-4ca0-bf94-ff9078eb124b",
86
+ "metadata": {},
87
+ "outputs": [],
88
+ "source": []
89
+ }
90
+ ],
91
+ "metadata": {
92
+ "kernelspec": {
93
+ "display_name": "Python 3 (ipykernel)",
94
+ "language": "python",
95
+ "name": "python3"
96
+ },
97
+ "language_info": {
98
+ "codemirror_mode": {
99
+ "name": "ipython",
100
+ "version": 3
101
+ },
102
+ "file_extension": ".py",
103
+ "mimetype": "text/x-python",
104
+ "name": "python",
105
+ "nbconvert_exporter": "python",
106
+ "pygments_lexer": "ipython3",
107
+ "version": "3.7.13"
108
+ }
109
+ },
110
+ "nbformat": 4,
111
+ "nbformat_minor": 5
112
+ }
app/main.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ..\main.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'is_cat']
5
+
6
+ # %% ..\main.ipynb 1
7
+ from fastai.vision.all import *
8
+ import gradio as gr
9
+
10
+ def is_cat(x): return x[0].isupper()
11
+
12
+ # %% ..\main.ipynb 6
13
+ learn = load_learner('model.pkl')
cat.jpg ADDED
dog.jpg ADDED
main.ipynb ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "41971c73-6b80-487e-acdc-836991e62c9d",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|default_exp main"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 3,
16
+ "id": "12171d9b-9822-461a-9c16-3925a275e859",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "#|export\n",
21
+ "from fastai.vision.all import *\n",
22
+ "import gradio as gr\n",
23
+ "\n",
24
+ "def is_cat(x): return x[0].isupper()"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": null,
30
+ "id": "5f678c6f-a7a8-4da2-845c-2c82f056e890",
31
+ "metadata": {},
32
+ "outputs": [],
33
+ "source": [
34
+ "path = untar_data(URLs.PETS)/'images'"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": null,
40
+ "id": "9a2dd42f-3fae-4bcf-a7a9-932dedb19684",
41
+ "metadata": {},
42
+ "outputs": [],
43
+ "source": [
44
+ "dls = ImageDataLoaders.from_name_func('.',\n",
45
+ " get_image_files(path), valid_pct=0.2, seed=42,\n",
46
+ " label_func=is_cat,\n",
47
+ " item_tfms=Resize(192))"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "execution_count": null,
53
+ "id": "09e8e2ad-30eb-45bc-aa4b-9fe5a256287a",
54
+ "metadata": {},
55
+ "outputs": [],
56
+ "source": [
57
+ "learn = vision_learner(dls, resnet18, metrics=error_rate)\n",
58
+ "learn.fine_tune(3)"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "execution_count": null,
64
+ "id": "b601d058-559a-4246-b4bb-2ad490d826f5",
65
+ "metadata": {},
66
+ "outputs": [],
67
+ "source": [
68
+ "learn.export('model.pkl')"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "execution_count": 4,
74
+ "id": "5b01bcd5-5c99-4531-9f93-70dc32238dc4",
75
+ "metadata": {},
76
+ "outputs": [],
77
+ "source": [
78
+ "#|export\n",
79
+ "learn = load_learner('model.pkl')"
80
+ ]
81
+ },
82
+ {
83
+ "cell_type": "code",
84
+ "execution_count": 5,
85
+ "id": "77bd55bf-2d8a-4ca0-bf94-ff9078eb124b",
86
+ "metadata": {},
87
+ "outputs": [],
88
+ "source": [
89
+ "#|export\n",
90
+ "categories = ('Dog', 'Cat')\n",
91
+ "\n",
92
+ "def classify(img):\n",
93
+ " pred,idx,probs = learn.predict(img)\n",
94
+ " return dict(zip(categories, map(float, probs)))"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": 8,
100
+ "id": "dc00d8a5-a4fe-42ec-9daa-cce8ab31400b",
101
+ "metadata": {},
102
+ "outputs": [
103
+ {
104
+ "name": "stdout",
105
+ "output_type": "stream",
106
+ "text": [
107
+ "Running on local URL: http://127.0.0.1:7860\n",
108
+ "\n",
109
+ "To create a public link, set `share=True` in `launch()`.\n"
110
+ ]
111
+ },
112
+ {
113
+ "data": {
114
+ "text/plain": [
115
+ "(<gradio.routes.App at 0x241de99cfc8>, 'http://127.0.0.1:7860/', None)"
116
+ ]
117
+ },
118
+ "execution_count": 8,
119
+ "metadata": {},
120
+ "output_type": "execute_result"
121
+ }
122
+ ],
123
+ "source": [
124
+ "#|export\n",
125
+ "image = gr.inputs.Image(shape=(192, 192))\n",
126
+ "label = gr.outputs.Label()\n",
127
+ "examples = ['dog.jpg', 'cat.jpg']\n",
128
+ "\n",
129
+ "intf = gr.Interface(fn=classify, inputs=image, outputs=label, examples=examples)\n",
130
+ "intf.launch(inline=False)"
131
+ ]
132
+ },
133
+ {
134
+ "cell_type": "code",
135
+ "execution_count": 9,
136
+ "id": "7cf96e37-8c63-4494-84c5-d91b9ff96e2b",
137
+ "metadata": {},
138
+ "outputs": [
139
+ {
140
+ "name": "stdout",
141
+ "output_type": "stream",
142
+ "text": [
143
+ "Export successful\n"
144
+ ]
145
+ }
146
+ ],
147
+ "source": [
148
+ "import nbdev\n",
149
+ "nbdev.export.nb_export('main.ipynb', 'app')\n",
150
+ "print('Export successful')"
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "execution_count": null,
156
+ "id": "1c513736-d2b5-48d4-89da-746a8b0047cf",
157
+ "metadata": {},
158
+ "outputs": [],
159
+ "source": []
160
+ }
161
+ ],
162
+ "metadata": {
163
+ "kernelspec": {
164
+ "display_name": "Python 3 (ipykernel)",
165
+ "language": "python",
166
+ "name": "python3"
167
+ },
168
+ "language_info": {
169
+ "codemirror_mode": {
170
+ "name": "ipython",
171
+ "version": 3
172
+ },
173
+ "file_extension": ".py",
174
+ "mimetype": "text/x-python",
175
+ "name": "python",
176
+ "nbconvert_exporter": "python",
177
+ "pygments_lexer": "ipython3",
178
+ "version": "3.7.13"
179
+ }
180
+ },
181
+ "nbformat": 4,
182
+ "nbformat_minor": 5
183
+ }
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b33eab6695ce7c20d00b81a88ede5230d3c9a3d7a9b2df485d2b955d3ff3d3ea
3
+ size 47065259