Long Hoang commited on
Commit
00b41e5
1 Parent(s): 6093635

adds images

Browse files
Files changed (5) hide show
  1. .DS_Store +0 -0
  2. Cat.jpg +0 -0
  3. app.ipynb +164 -0
  4. app.py +1 -1
  5. dog.jpg +0 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
Cat.jpg ADDED
app.ipynb ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "#|export\n",
10
+ "from fastai.vision.all import *\n",
11
+ "import gradio as gr"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": null,
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "#|default_exp app"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "#|export\n",
30
+ "def is_cat(x): \n",
31
+ " return x[0].isupper()"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": null,
37
+ "metadata": {},
38
+ "outputs": [],
39
+ "source": [
40
+ "im = PILImage.create('data/dog01.jpg')\n",
41
+ "im.thumbnail((192,192))\n",
42
+ "im"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": null,
48
+ "metadata": {},
49
+ "outputs": [],
50
+ "source": [
51
+ "im2 = PILImage.create('data/Cat01.jpg')\n",
52
+ "im2.thumbnail((192,192))\n",
53
+ "im2"
54
+ ]
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "execution_count": null,
59
+ "metadata": {},
60
+ "outputs": [],
61
+ "source": [
62
+ "#|export\n",
63
+ "learn = load_learner('model.pkl')"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": null,
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "%time learn.predict(im2)"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": null,
78
+ "metadata": {},
79
+ "outputs": [],
80
+ "source": [
81
+ "#|export\n",
82
+ "categories = ['Dog', 'Cat']\n",
83
+ "def classify_image(img):\n",
84
+ " pred,idx,probs = learn.predict(img)\n",
85
+ " return dict(zip(categories, map(float, probs)))"
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": null,
91
+ "metadata": {},
92
+ "outputs": [],
93
+ "source": [
94
+ "classify_image(im)"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": null,
100
+ "metadata": {},
101
+ "outputs": [],
102
+ "source": [
103
+ "#|export\n",
104
+ "image = gr.inputs.Image(shape=(192,192))\n",
105
+ "label = gr.outputs.Label()\n",
106
+ "# examples = ['data/Cat01.jpg', 'data/dog01.jpg','data/confuse.jpg']\n",
107
+ "examples = ['confuse.jpg']\n",
108
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
109
+ "intf.launch(inline=False)"
110
+ ]
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "execution_count": null,
115
+ "metadata": {},
116
+ "outputs": [],
117
+ "source": [
118
+ "import nbdev.export"
119
+ ]
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "execution_count": null,
124
+ "metadata": {},
125
+ "outputs": [],
126
+ "source": [
127
+ "# notebook2script('app.ipynb')"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": null,
133
+ "metadata": {},
134
+ "outputs": [],
135
+ "source": []
136
+ }
137
+ ],
138
+ "metadata": {
139
+ "kernelspec": {
140
+ "display_name": "Python 3 (ipykernel)",
141
+ "language": "python",
142
+ "name": "python3"
143
+ },
144
+ "language_info": {
145
+ "codemirror_mode": {
146
+ "name": "ipython",
147
+ "version": 3
148
+ },
149
+ "file_extension": ".py",
150
+ "mimetype": "text/x-python",
151
+ "name": "python",
152
+ "nbconvert_exporter": "python",
153
+ "pygments_lexer": "ipython3",
154
+ "version": "3.9.7 (default, Sep 16 2021, 08:50:36) \n[Clang 10.0.0 ]"
155
+ },
156
+ "vscode": {
157
+ "interpreter": {
158
+ "hash": "9e74e14f5687b90804d746569a5d9cb420b92046434928ed51c35ec37f47b47e"
159
+ }
160
+ }
161
+ },
162
+ "nbformat": 4,
163
+ "nbformat_minor": 2
164
+ }
app.py CHANGED
@@ -13,6 +13,6 @@ def classify_image(img):
13
 
14
  image = gr.inputs.Image(shape=(192,192))
15
  label = gr.outputs.Label()
16
- examples = ['confuse.jpg']
17
  intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
18
  intf.launch(inline=False)
 
13
 
14
  image = gr.inputs.Image(shape=(192,192))
15
  label = gr.outputs.Label()
16
+ examples = ['confuse.jpg', 'dog.jpg', 'Cat.jpg']
17
  intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
18
  intf.launch(inline=False)
dog.jpg ADDED