Spaces:
Runtime error
Runtime error
hsaripalli
commited on
Commit
•
c4368ce
1
Parent(s):
40849b7
code changes
Browse files- Methane_Classifier/app.py +38 -0
- app.py +35 -4
- methane-plume-classification-yes-or-no.ipynb +126 -1
Methane_Classifier/app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../methane-plume-classification-yes-or-no.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['temp', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 2
|
7 |
+
import warnings
|
8 |
+
warnings.filterwarnings('ignore')
|
9 |
+
|
10 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 3
|
11 |
+
import pathlib
|
12 |
+
temp = pathlib.PosixPath
|
13 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
14 |
+
|
15 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 4
|
16 |
+
import fastbook
|
17 |
+
import pandas as pd
|
18 |
+
import numpy as np
|
19 |
+
import os
|
20 |
+
|
21 |
+
from fastbook import *
|
22 |
+
from fastai.vision.widgets import *
|
23 |
+
import gradio as gr
|
24 |
+
|
25 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 20
|
26 |
+
categories = ('No Plume', 'Plume')
|
27 |
+
|
28 |
+
def classify_image(img):
|
29 |
+
pred, idx, probs = learn.predict(img)
|
30 |
+
return dict(zip(categories, map(float, probs)))
|
31 |
+
|
32 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 22
|
33 |
+
image = gr.inputs.Image(shape = (152, 152))
|
34 |
+
label = gr.outputs.Label()
|
35 |
+
examples = ['plume1.png', 'plume2.png', 'noplume1.png', 'noplume2.png']
|
36 |
+
|
37 |
+
intf = gr.Interface(fn = classify_image, inputs = image, outputs = label, examples = examples)
|
38 |
+
intf.launch(inline = False)
|
app.py
CHANGED
@@ -1,7 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../methane-plume-classification-yes-or-no.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['temp', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 2
|
7 |
+
import warnings
|
8 |
+
warnings.filterwarnings('ignore')
|
9 |
+
|
10 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 3
|
11 |
+
import pathlib
|
12 |
+
temp = pathlib.PosixPath
|
13 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
14 |
+
|
15 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 4
|
16 |
+
import fastbook
|
17 |
+
import pandas as pd
|
18 |
+
import numpy as np
|
19 |
+
import os
|
20 |
+
|
21 |
+
from fastbook import *
|
22 |
+
from fastai.vision.widgets import *
|
23 |
import gradio as gr
|
24 |
|
25 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 20
|
26 |
+
categories = ('No Plume', 'Plume')
|
27 |
+
|
28 |
+
def classify_image(img):
|
29 |
+
pred, idx, probs = learn.predict(img)
|
30 |
+
return dict(zip(categories, map(float, probs)))
|
31 |
+
|
32 |
+
# %% ../methane-plume-classification-yes-or-no.ipynb 22
|
33 |
+
image = gr.inputs.Image(shape = (152, 152))
|
34 |
+
label = gr.outputs.Label()
|
35 |
+
examples = ['plume1.png', 'plume2.png', 'noplume1.png', 'noplume2.png']
|
36 |
|
37 |
+
intf = gr.Interface(fn = classify_image, inputs = image, outputs = label, examples = examples)
|
38 |
+
intf.launch(inline = False)
|
methane-plume-classification-yes-or-no.ipynb
CHANGED
@@ -36,6 +36,40 @@
|
|
36 |
"# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session"
|
37 |
]
|
38 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
{
|
40 |
"cell_type": "code",
|
41 |
"execution_count": null,
|
@@ -51,7 +85,8 @@
|
|
51 |
},
|
52 |
"outputs": [],
|
53 |
"source": [
|
54 |
-
"
|
|
|
55 |
"import fastbook\n",
|
56 |
"import pandas as pd\n",
|
57 |
"import numpy as np\n",
|
@@ -62,6 +97,17 @@
|
|
62 |
"import gradio as gr"
|
63 |
]
|
64 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
{
|
66 |
"cell_type": "code",
|
67 |
"execution_count": null,
|
@@ -280,6 +326,85 @@
|
|
280 |
"learn.export('methane plume detect.pkl')"
|
281 |
]
|
282 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
{
|
284 |
"cell_type": "code",
|
285 |
"execution_count": null,
|
|
|
36 |
"# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session"
|
37 |
]
|
38 |
},
|
39 |
+
{
|
40 |
+
"cell_type": "code",
|
41 |
+
"execution_count": 4,
|
42 |
+
"metadata": {},
|
43 |
+
"outputs": [],
|
44 |
+
"source": [
|
45 |
+
"#|default_exp app"
|
46 |
+
]
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"cell_type": "code",
|
50 |
+
"execution_count": null,
|
51 |
+
"metadata": {},
|
52 |
+
"outputs": [],
|
53 |
+
"source": [
|
54 |
+
"#|export\n",
|
55 |
+
"\n",
|
56 |
+
"import warnings\n",
|
57 |
+
"warnings.filterwarnings('ignore')"
|
58 |
+
]
|
59 |
+
},
|
60 |
+
{
|
61 |
+
"cell_type": "code",
|
62 |
+
"execution_count": null,
|
63 |
+
"metadata": {},
|
64 |
+
"outputs": [],
|
65 |
+
"source": [
|
66 |
+
"#|export\n",
|
67 |
+
"\n",
|
68 |
+
"import pathlib\n",
|
69 |
+
"temp = pathlib.PosixPath\n",
|
70 |
+
"pathlib.PosixPath = pathlib.WindowsPath"
|
71 |
+
]
|
72 |
+
},
|
73 |
{
|
74 |
"cell_type": "code",
|
75 |
"execution_count": null,
|
|
|
85 |
},
|
86 |
"outputs": [],
|
87 |
"source": [
|
88 |
+
"#|export\n",
|
89 |
+
"\n",
|
90 |
"import fastbook\n",
|
91 |
"import pandas as pd\n",
|
92 |
"import numpy as np\n",
|
|
|
97 |
"import gradio as gr"
|
98 |
]
|
99 |
},
|
100 |
+
{
|
101 |
+
"cell_type": "code",
|
102 |
+
"execution_count": null,
|
103 |
+
"metadata": {},
|
104 |
+
"outputs": [],
|
105 |
+
"source": [
|
106 |
+
"im = PILImage.create('plume1.png')\n",
|
107 |
+
"im.thumbnail((182,192))\n",
|
108 |
+
"im"
|
109 |
+
]
|
110 |
+
},
|
111 |
{
|
112 |
"cell_type": "code",
|
113 |
"execution_count": null,
|
|
|
326 |
"learn.export('methane plume detect.pkl')"
|
327 |
]
|
328 |
},
|
329 |
+
{
|
330 |
+
"cell_type": "code",
|
331 |
+
"execution_count": null,
|
332 |
+
"metadata": {
|
333 |
+
"scrolled": true
|
334 |
+
},
|
335 |
+
"outputs": [],
|
336 |
+
"source": [
|
337 |
+
"learn = load_learner('methane plume detect.pkl')"
|
338 |
+
]
|
339 |
+
},
|
340 |
+
{
|
341 |
+
"cell_type": "code",
|
342 |
+
"execution_count": null,
|
343 |
+
"metadata": {},
|
344 |
+
"outputs": [],
|
345 |
+
"source": [
|
346 |
+
"learn.predict(im)"
|
347 |
+
]
|
348 |
+
},
|
349 |
+
{
|
350 |
+
"cell_type": "code",
|
351 |
+
"execution_count": null,
|
352 |
+
"metadata": {},
|
353 |
+
"outputs": [],
|
354 |
+
"source": [
|
355 |
+
"#|export\n",
|
356 |
+
"\n",
|
357 |
+
"categories = ('No Plume', 'Plume')\n",
|
358 |
+
"\n",
|
359 |
+
"def classify_image(img):\n",
|
360 |
+
" pred, idx, probs = learn.predict(img)\n",
|
361 |
+
" return dict(zip(categories, map(float, probs)))"
|
362 |
+
]
|
363 |
+
},
|
364 |
+
{
|
365 |
+
"cell_type": "code",
|
366 |
+
"execution_count": null,
|
367 |
+
"metadata": {},
|
368 |
+
"outputs": [],
|
369 |
+
"source": [
|
370 |
+
"classify_image(im)"
|
371 |
+
]
|
372 |
+
},
|
373 |
+
{
|
374 |
+
"cell_type": "code",
|
375 |
+
"execution_count": null,
|
376 |
+
"metadata": {},
|
377 |
+
"outputs": [],
|
378 |
+
"source": [
|
379 |
+
"#|export\n",
|
380 |
+
"\n",
|
381 |
+
"image = gr.inputs.Image(shape = (152, 152))\n",
|
382 |
+
"label = gr.outputs.Label()\n",
|
383 |
+
"examples = ['plume1.png', 'plume2.png', 'noplume1.png', 'noplume2.png']\n",
|
384 |
+
"\n",
|
385 |
+
"intf = gr.Interface(fn = classify_image, inputs = image, outputs = label, examples = examples)\n",
|
386 |
+
"intf.launch(inline = False)"
|
387 |
+
]
|
388 |
+
},
|
389 |
+
{
|
390 |
+
"cell_type": "code",
|
391 |
+
"execution_count": 5,
|
392 |
+
"metadata": {},
|
393 |
+
"outputs": [
|
394 |
+
{
|
395 |
+
"name": "stdout",
|
396 |
+
"output_type": "stream",
|
397 |
+
"text": [
|
398 |
+
"Export successful\n"
|
399 |
+
]
|
400 |
+
}
|
401 |
+
],
|
402 |
+
"source": [
|
403 |
+
"import nbdev\n",
|
404 |
+
"nbdev.export.nb_export('methane-plume-classification-yes-or-no.ipynb', 'app')\n",
|
405 |
+
"print('Export successful')"
|
406 |
+
]
|
407 |
+
},
|
408 |
{
|
409 |
"cell_type": "code",
|
410 |
"execution_count": null,
|