Spaces:
Runtime error
Runtime error
hsaripalli
commited on
Commit
β’
40849b7
1
Parent(s):
a626a7f
change file names
Browse files- .ipynb_checkpoints/methane-plume-classification-yes-or-no-checkpoint.ipynb +312 -0
- methane-plume-classification-yes-or-no.ipynb +312 -0
- 01b85fbbaa5d9f3a0d8f.png β noplume1.png +0 -0
- 0021b95ff4079cc9b1b7.png β noplume2.png +0 -0
- GAO20200713t154610p0000-A_r3181_c599-plume.png β plume1.png +0 -0
- GAO20200714t150714p0000-A_r8908_c870-plume.png β plume2.png +0 -0
.ipynb_checkpoints/methane-plume-classification-yes-or-no-checkpoint.ipynb
ADDED
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
|
8 |
+
"_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
|
9 |
+
"execution": {
|
10 |
+
"iopub.execute_input": "2023-06-06T16:12:56.482001Z",
|
11 |
+
"iopub.status.busy": "2023-06-06T16:12:56.481629Z",
|
12 |
+
"iopub.status.idle": "2023-06-06T16:12:56.511919Z",
|
13 |
+
"shell.execute_reply": "2023-06-06T16:12:56.510864Z",
|
14 |
+
"shell.execute_reply.started": "2023-06-06T16:12:56.481922Z"
|
15 |
+
},
|
16 |
+
"scrolled": true
|
17 |
+
},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"# This Python 3 environment comes with many helpful analytics libraries installed\n",
|
21 |
+
"# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n",
|
22 |
+
"# For example, here's several helpful packages to load\n",
|
23 |
+
"\n",
|
24 |
+
"#import numpy as np # linear algebra\n",
|
25 |
+
"#import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
|
26 |
+
"\n",
|
27 |
+
"# Input data files are available in the read-only \"../input/\" directory\n",
|
28 |
+
"# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n",
|
29 |
+
"\n",
|
30 |
+
"#import os\n",
|
31 |
+
"#for dirname, _, filenames in os.walk('/kaggle/input'):\n",
|
32 |
+
"# for filename in filenames:\n",
|
33 |
+
"# print(os.path.join(dirname, filename))\n",
|
34 |
+
"\n",
|
35 |
+
"# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n",
|
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,
|
42 |
+
"metadata": {
|
43 |
+
"execution": {
|
44 |
+
"iopub.execute_input": "2023-06-06T16:12:56.515330Z",
|
45 |
+
"iopub.status.busy": "2023-06-06T16:12:56.514653Z",
|
46 |
+
"iopub.status.idle": "2023-06-06T16:13:17.032978Z",
|
47 |
+
"shell.execute_reply": "2023-06-06T16:13:17.031623Z",
|
48 |
+
"shell.execute_reply.started": "2023-06-06T16:12:56.515291Z"
|
49 |
+
},
|
50 |
+
"scrolled": true
|
51 |
+
},
|
52 |
+
"outputs": [],
|
53 |
+
"source": [
|
54 |
+
"!pip install fastbook\n",
|
55 |
+
"import fastbook\n",
|
56 |
+
"import pandas as pd\n",
|
57 |
+
"import numpy as np\n",
|
58 |
+
"import os \n",
|
59 |
+
"\n",
|
60 |
+
"from fastbook import *\n",
|
61 |
+
"from fastai.vision.widgets import *\n",
|
62 |
+
"import gradio as gr"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"cell_type": "code",
|
67 |
+
"execution_count": null,
|
68 |
+
"metadata": {
|
69 |
+
"execution": {
|
70 |
+
"iopub.execute_input": "2023-06-06T16:13:17.047225Z",
|
71 |
+
"iopub.status.busy": "2023-06-06T16:13:17.046261Z",
|
72 |
+
"iopub.status.idle": "2023-06-06T16:13:17.053274Z",
|
73 |
+
"shell.execute_reply": "2023-06-06T16:13:17.052116Z",
|
74 |
+
"shell.execute_reply.started": "2023-06-06T16:13:17.047171Z"
|
75 |
+
}
|
76 |
+
},
|
77 |
+
"outputs": [],
|
78 |
+
"source": [
|
79 |
+
"path = Path('/kaggle/input/speuntapped/train')"
|
80 |
+
]
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"cell_type": "code",
|
84 |
+
"execution_count": null,
|
85 |
+
"metadata": {
|
86 |
+
"execution": {
|
87 |
+
"iopub.execute_input": "2023-06-06T16:13:17.058708Z",
|
88 |
+
"iopub.status.busy": "2023-06-06T16:13:17.057847Z",
|
89 |
+
"iopub.status.idle": "2023-06-06T16:13:20.265898Z",
|
90 |
+
"shell.execute_reply": "2023-06-06T16:13:20.264895Z",
|
91 |
+
"shell.execute_reply.started": "2023-06-06T16:13:17.058670Z"
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"outputs": [],
|
95 |
+
"source": [
|
96 |
+
"fns = get_image_files(path)\n",
|
97 |
+
"fns"
|
98 |
+
]
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"cell_type": "code",
|
102 |
+
"execution_count": null,
|
103 |
+
"metadata": {
|
104 |
+
"execution": {
|
105 |
+
"iopub.execute_input": "2023-06-06T16:13:20.269200Z",
|
106 |
+
"iopub.status.busy": "2023-06-06T16:13:20.267211Z",
|
107 |
+
"iopub.status.idle": "2023-06-06T16:13:20.276861Z",
|
108 |
+
"shell.execute_reply": "2023-06-06T16:13:20.275708Z",
|
109 |
+
"shell.execute_reply.started": "2023-06-06T16:13:20.269168Z"
|
110 |
+
}
|
111 |
+
},
|
112 |
+
"outputs": [],
|
113 |
+
"source": [
|
114 |
+
"plume = DataBlock(\n",
|
115 |
+
" blocks=(ImageBlock, CategoryBlock),\n",
|
116 |
+
" get_items=get_image_files,\n",
|
117 |
+
" splitter=RandomSplitter(valid_pct=0.2,seed=42),\n",
|
118 |
+
" get_y=parent_label\n",
|
119 |
+
")"
|
120 |
+
]
|
121 |
+
},
|
122 |
+
{
|
123 |
+
"cell_type": "code",
|
124 |
+
"execution_count": null,
|
125 |
+
"metadata": {
|
126 |
+
"execution": {
|
127 |
+
"iopub.execute_input": "2023-06-06T16:13:20.279400Z",
|
128 |
+
"iopub.status.busy": "2023-06-06T16:13:20.279013Z",
|
129 |
+
"iopub.status.idle": "2023-06-06T16:13:20.294720Z",
|
130 |
+
"shell.execute_reply": "2023-06-06T16:13:20.293498Z",
|
131 |
+
"shell.execute_reply.started": "2023-06-06T16:13:20.279361Z"
|
132 |
+
}
|
133 |
+
},
|
134 |
+
"outputs": [],
|
135 |
+
"source": [
|
136 |
+
"plume = plume.new(\n",
|
137 |
+
" item_tfms=RandomResizedCrop(152, min_scale=0.5),\n",
|
138 |
+
" batch_tfms=aug_transforms()\n",
|
139 |
+
")"
|
140 |
+
]
|
141 |
+
},
|
142 |
+
{
|
143 |
+
"cell_type": "code",
|
144 |
+
"execution_count": null,
|
145 |
+
"metadata": {
|
146 |
+
"execution": {
|
147 |
+
"iopub.execute_input": "2023-06-06T16:13:20.296793Z",
|
148 |
+
"iopub.status.busy": "2023-06-06T16:13:20.296142Z",
|
149 |
+
"iopub.status.idle": "2023-06-06T16:13:29.647446Z",
|
150 |
+
"shell.execute_reply": "2023-06-06T16:13:29.646201Z",
|
151 |
+
"shell.execute_reply.started": "2023-06-06T16:13:20.296747Z"
|
152 |
+
}
|
153 |
+
},
|
154 |
+
"outputs": [],
|
155 |
+
"source": [
|
156 |
+
"dls = plume.dataloaders(path)"
|
157 |
+
]
|
158 |
+
},
|
159 |
+
{
|
160 |
+
"cell_type": "code",
|
161 |
+
"execution_count": null,
|
162 |
+
"metadata": {
|
163 |
+
"execution": {
|
164 |
+
"iopub.execute_input": "2023-06-06T16:13:29.649289Z",
|
165 |
+
"iopub.status.busy": "2023-06-06T16:13:29.648894Z",
|
166 |
+
"iopub.status.idle": "2023-06-06T16:13:30.941482Z",
|
167 |
+
"shell.execute_reply": "2023-06-06T16:13:30.940546Z",
|
168 |
+
"shell.execute_reply.started": "2023-06-06T16:13:29.649249Z"
|
169 |
+
}
|
170 |
+
},
|
171 |
+
"outputs": [],
|
172 |
+
"source": [
|
173 |
+
"dls.valid.show_batch(max_n=12, nrows=4) "
|
174 |
+
]
|
175 |
+
},
|
176 |
+
{
|
177 |
+
"cell_type": "code",
|
178 |
+
"execution_count": null,
|
179 |
+
"metadata": {
|
180 |
+
"execution": {
|
181 |
+
"iopub.execute_input": "2023-06-06T16:13:30.942995Z",
|
182 |
+
"iopub.status.busy": "2023-06-06T16:13:30.942633Z",
|
183 |
+
"iopub.status.idle": "2023-06-06T16:16:55.896473Z",
|
184 |
+
"shell.execute_reply": "2023-06-06T16:16:55.895239Z",
|
185 |
+
"shell.execute_reply.started": "2023-06-06T16:13:30.942955Z"
|
186 |
+
}
|
187 |
+
},
|
188 |
+
"outputs": [],
|
189 |
+
"source": [
|
190 |
+
"learn = vision_learner(dls, resnet50, metrics=error_rate)\n",
|
191 |
+
"learn.fine_tune(epochs=3)"
|
192 |
+
]
|
193 |
+
},
|
194 |
+
{
|
195 |
+
"cell_type": "code",
|
196 |
+
"execution_count": null,
|
197 |
+
"metadata": {
|
198 |
+
"execution": {
|
199 |
+
"iopub.execute_input": "2023-06-06T16:16:55.899023Z",
|
200 |
+
"iopub.status.busy": "2023-06-06T16:16:55.898611Z",
|
201 |
+
"iopub.status.idle": "2023-06-06T16:17:12.173908Z",
|
202 |
+
"shell.execute_reply": "2023-06-06T16:17:12.172400Z",
|
203 |
+
"shell.execute_reply.started": "2023-06-06T16:16:55.898975Z"
|
204 |
+
}
|
205 |
+
},
|
206 |
+
"outputs": [],
|
207 |
+
"source": [
|
208 |
+
"from IPython.core.pylabtools import figsize \n",
|
209 |
+
"interp = ClassificationInterpretation.from_learner(learn)\n",
|
210 |
+
"interp.plot_confusion_matrix(figsize=(10,10))"
|
211 |
+
]
|
212 |
+
},
|
213 |
+
{
|
214 |
+
"cell_type": "code",
|
215 |
+
"execution_count": null,
|
216 |
+
"metadata": {
|
217 |
+
"execution": {
|
218 |
+
"iopub.execute_input": "2023-06-06T16:17:12.177922Z",
|
219 |
+
"iopub.status.busy": "2023-06-06T16:17:12.177508Z",
|
220 |
+
"iopub.status.idle": "2023-06-06T16:17:13.734058Z",
|
221 |
+
"shell.execute_reply": "2023-06-06T16:17:13.732857Z",
|
222 |
+
"shell.execute_reply.started": "2023-06-06T16:17:12.177864Z"
|
223 |
+
}
|
224 |
+
},
|
225 |
+
"outputs": [],
|
226 |
+
"source": [
|
227 |
+
"interp.plot_top_losses(20, nrows=10, figsize=(20,20))"
|
228 |
+
]
|
229 |
+
},
|
230 |
+
{
|
231 |
+
"cell_type": "code",
|
232 |
+
"execution_count": null,
|
233 |
+
"metadata": {
|
234 |
+
"execution": {
|
235 |
+
"iopub.execute_input": "2023-06-06T16:17:13.739200Z",
|
236 |
+
"iopub.status.busy": "2023-06-06T16:17:13.735848Z",
|
237 |
+
"iopub.status.idle": "2023-06-06T16:17:13.744700Z",
|
238 |
+
"shell.execute_reply": "2023-06-06T16:17:13.743507Z",
|
239 |
+
"shell.execute_reply.started": "2023-06-06T16:17:13.739151Z"
|
240 |
+
}
|
241 |
+
},
|
242 |
+
"outputs": [],
|
243 |
+
"source": [
|
244 |
+
"test_image = '/kaggle/input/speuntapped/test/test/ang20190922t192642-4_r4928_c373-plume.png'"
|
245 |
+
]
|
246 |
+
},
|
247 |
+
{
|
248 |
+
"cell_type": "code",
|
249 |
+
"execution_count": null,
|
250 |
+
"metadata": {
|
251 |
+
"execution": {
|
252 |
+
"iopub.execute_input": "2023-06-06T16:17:13.750250Z",
|
253 |
+
"iopub.status.busy": "2023-06-06T16:17:13.749605Z",
|
254 |
+
"iopub.status.idle": "2023-06-06T16:17:13.883090Z",
|
255 |
+
"shell.execute_reply": "2023-06-06T16:17:13.881894Z",
|
256 |
+
"shell.execute_reply.started": "2023-06-06T16:17:13.750206Z"
|
257 |
+
}
|
258 |
+
},
|
259 |
+
"outputs": [],
|
260 |
+
"source": [
|
261 |
+
"is_plume,_,probs = learn.predict(PILImage.create(test_image))\n",
|
262 |
+
"print(f\"This is a: {is_plume}.\")\n",
|
263 |
+
"print(f\"Probability it's a plume: {probs[1]:.4f}\")"
|
264 |
+
]
|
265 |
+
},
|
266 |
+
{
|
267 |
+
"cell_type": "code",
|
268 |
+
"execution_count": null,
|
269 |
+
"metadata": {
|
270 |
+
"execution": {
|
271 |
+
"iopub.execute_input": "2023-06-06T16:22:39.764768Z",
|
272 |
+
"iopub.status.busy": "2023-06-06T16:22:39.764285Z",
|
273 |
+
"iopub.status.idle": "2023-06-06T16:22:40.137875Z",
|
274 |
+
"shell.execute_reply": "2023-06-06T16:22:40.136697Z",
|
275 |
+
"shell.execute_reply.started": "2023-06-06T16:22:39.764726Z"
|
276 |
+
}
|
277 |
+
},
|
278 |
+
"outputs": [],
|
279 |
+
"source": [
|
280 |
+
"learn.export('methane plume detect.pkl')"
|
281 |
+
]
|
282 |
+
},
|
283 |
+
{
|
284 |
+
"cell_type": "code",
|
285 |
+
"execution_count": null,
|
286 |
+
"metadata": {},
|
287 |
+
"outputs": [],
|
288 |
+
"source": []
|
289 |
+
}
|
290 |
+
],
|
291 |
+
"metadata": {
|
292 |
+
"kernelspec": {
|
293 |
+
"display_name": "Python 3 (ipykernel)",
|
294 |
+
"language": "python",
|
295 |
+
"name": "python3"
|
296 |
+
},
|
297 |
+
"language_info": {
|
298 |
+
"codemirror_mode": {
|
299 |
+
"name": "ipython",
|
300 |
+
"version": 3
|
301 |
+
},
|
302 |
+
"file_extension": ".py",
|
303 |
+
"mimetype": "text/x-python",
|
304 |
+
"name": "python",
|
305 |
+
"nbconvert_exporter": "python",
|
306 |
+
"pygments_lexer": "ipython3",
|
307 |
+
"version": "3.10.9"
|
308 |
+
}
|
309 |
+
},
|
310 |
+
"nbformat": 4,
|
311 |
+
"nbformat_minor": 4
|
312 |
+
}
|
methane-plume-classification-yes-or-no.ipynb
ADDED
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
|
8 |
+
"_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
|
9 |
+
"execution": {
|
10 |
+
"iopub.execute_input": "2023-06-06T16:12:56.482001Z",
|
11 |
+
"iopub.status.busy": "2023-06-06T16:12:56.481629Z",
|
12 |
+
"iopub.status.idle": "2023-06-06T16:12:56.511919Z",
|
13 |
+
"shell.execute_reply": "2023-06-06T16:12:56.510864Z",
|
14 |
+
"shell.execute_reply.started": "2023-06-06T16:12:56.481922Z"
|
15 |
+
},
|
16 |
+
"scrolled": true
|
17 |
+
},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"# This Python 3 environment comes with many helpful analytics libraries installed\n",
|
21 |
+
"# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n",
|
22 |
+
"# For example, here's several helpful packages to load\n",
|
23 |
+
"\n",
|
24 |
+
"#import numpy as np # linear algebra\n",
|
25 |
+
"#import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
|
26 |
+
"\n",
|
27 |
+
"# Input data files are available in the read-only \"../input/\" directory\n",
|
28 |
+
"# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n",
|
29 |
+
"\n",
|
30 |
+
"#import os\n",
|
31 |
+
"#for dirname, _, filenames in os.walk('/kaggle/input'):\n",
|
32 |
+
"# for filename in filenames:\n",
|
33 |
+
"# print(os.path.join(dirname, filename))\n",
|
34 |
+
"\n",
|
35 |
+
"# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n",
|
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,
|
42 |
+
"metadata": {
|
43 |
+
"execution": {
|
44 |
+
"iopub.execute_input": "2023-06-06T16:12:56.515330Z",
|
45 |
+
"iopub.status.busy": "2023-06-06T16:12:56.514653Z",
|
46 |
+
"iopub.status.idle": "2023-06-06T16:13:17.032978Z",
|
47 |
+
"shell.execute_reply": "2023-06-06T16:13:17.031623Z",
|
48 |
+
"shell.execute_reply.started": "2023-06-06T16:12:56.515291Z"
|
49 |
+
},
|
50 |
+
"scrolled": true
|
51 |
+
},
|
52 |
+
"outputs": [],
|
53 |
+
"source": [
|
54 |
+
"!pip install fastbook\n",
|
55 |
+
"import fastbook\n",
|
56 |
+
"import pandas as pd\n",
|
57 |
+
"import numpy as np\n",
|
58 |
+
"import os \n",
|
59 |
+
"\n",
|
60 |
+
"from fastbook import *\n",
|
61 |
+
"from fastai.vision.widgets import *\n",
|
62 |
+
"import gradio as gr"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"cell_type": "code",
|
67 |
+
"execution_count": null,
|
68 |
+
"metadata": {
|
69 |
+
"execution": {
|
70 |
+
"iopub.execute_input": "2023-06-06T16:13:17.047225Z",
|
71 |
+
"iopub.status.busy": "2023-06-06T16:13:17.046261Z",
|
72 |
+
"iopub.status.idle": "2023-06-06T16:13:17.053274Z",
|
73 |
+
"shell.execute_reply": "2023-06-06T16:13:17.052116Z",
|
74 |
+
"shell.execute_reply.started": "2023-06-06T16:13:17.047171Z"
|
75 |
+
}
|
76 |
+
},
|
77 |
+
"outputs": [],
|
78 |
+
"source": [
|
79 |
+
"path = Path('/kaggle/input/speuntapped/train')"
|
80 |
+
]
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"cell_type": "code",
|
84 |
+
"execution_count": null,
|
85 |
+
"metadata": {
|
86 |
+
"execution": {
|
87 |
+
"iopub.execute_input": "2023-06-06T16:13:17.058708Z",
|
88 |
+
"iopub.status.busy": "2023-06-06T16:13:17.057847Z",
|
89 |
+
"iopub.status.idle": "2023-06-06T16:13:20.265898Z",
|
90 |
+
"shell.execute_reply": "2023-06-06T16:13:20.264895Z",
|
91 |
+
"shell.execute_reply.started": "2023-06-06T16:13:17.058670Z"
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"outputs": [],
|
95 |
+
"source": [
|
96 |
+
"fns = get_image_files(path)\n",
|
97 |
+
"fns"
|
98 |
+
]
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"cell_type": "code",
|
102 |
+
"execution_count": null,
|
103 |
+
"metadata": {
|
104 |
+
"execution": {
|
105 |
+
"iopub.execute_input": "2023-06-06T16:13:20.269200Z",
|
106 |
+
"iopub.status.busy": "2023-06-06T16:13:20.267211Z",
|
107 |
+
"iopub.status.idle": "2023-06-06T16:13:20.276861Z",
|
108 |
+
"shell.execute_reply": "2023-06-06T16:13:20.275708Z",
|
109 |
+
"shell.execute_reply.started": "2023-06-06T16:13:20.269168Z"
|
110 |
+
}
|
111 |
+
},
|
112 |
+
"outputs": [],
|
113 |
+
"source": [
|
114 |
+
"plume = DataBlock(\n",
|
115 |
+
" blocks=(ImageBlock, CategoryBlock),\n",
|
116 |
+
" get_items=get_image_files,\n",
|
117 |
+
" splitter=RandomSplitter(valid_pct=0.2,seed=42),\n",
|
118 |
+
" get_y=parent_label\n",
|
119 |
+
")"
|
120 |
+
]
|
121 |
+
},
|
122 |
+
{
|
123 |
+
"cell_type": "code",
|
124 |
+
"execution_count": null,
|
125 |
+
"metadata": {
|
126 |
+
"execution": {
|
127 |
+
"iopub.execute_input": "2023-06-06T16:13:20.279400Z",
|
128 |
+
"iopub.status.busy": "2023-06-06T16:13:20.279013Z",
|
129 |
+
"iopub.status.idle": "2023-06-06T16:13:20.294720Z",
|
130 |
+
"shell.execute_reply": "2023-06-06T16:13:20.293498Z",
|
131 |
+
"shell.execute_reply.started": "2023-06-06T16:13:20.279361Z"
|
132 |
+
}
|
133 |
+
},
|
134 |
+
"outputs": [],
|
135 |
+
"source": [
|
136 |
+
"plume = plume.new(\n",
|
137 |
+
" item_tfms=RandomResizedCrop(152, min_scale=0.5),\n",
|
138 |
+
" batch_tfms=aug_transforms()\n",
|
139 |
+
")"
|
140 |
+
]
|
141 |
+
},
|
142 |
+
{
|
143 |
+
"cell_type": "code",
|
144 |
+
"execution_count": null,
|
145 |
+
"metadata": {
|
146 |
+
"execution": {
|
147 |
+
"iopub.execute_input": "2023-06-06T16:13:20.296793Z",
|
148 |
+
"iopub.status.busy": "2023-06-06T16:13:20.296142Z",
|
149 |
+
"iopub.status.idle": "2023-06-06T16:13:29.647446Z",
|
150 |
+
"shell.execute_reply": "2023-06-06T16:13:29.646201Z",
|
151 |
+
"shell.execute_reply.started": "2023-06-06T16:13:20.296747Z"
|
152 |
+
}
|
153 |
+
},
|
154 |
+
"outputs": [],
|
155 |
+
"source": [
|
156 |
+
"dls = plume.dataloaders(path)"
|
157 |
+
]
|
158 |
+
},
|
159 |
+
{
|
160 |
+
"cell_type": "code",
|
161 |
+
"execution_count": null,
|
162 |
+
"metadata": {
|
163 |
+
"execution": {
|
164 |
+
"iopub.execute_input": "2023-06-06T16:13:29.649289Z",
|
165 |
+
"iopub.status.busy": "2023-06-06T16:13:29.648894Z",
|
166 |
+
"iopub.status.idle": "2023-06-06T16:13:30.941482Z",
|
167 |
+
"shell.execute_reply": "2023-06-06T16:13:30.940546Z",
|
168 |
+
"shell.execute_reply.started": "2023-06-06T16:13:29.649249Z"
|
169 |
+
}
|
170 |
+
},
|
171 |
+
"outputs": [],
|
172 |
+
"source": [
|
173 |
+
"dls.valid.show_batch(max_n=12, nrows=4) "
|
174 |
+
]
|
175 |
+
},
|
176 |
+
{
|
177 |
+
"cell_type": "code",
|
178 |
+
"execution_count": null,
|
179 |
+
"metadata": {
|
180 |
+
"execution": {
|
181 |
+
"iopub.execute_input": "2023-06-06T16:13:30.942995Z",
|
182 |
+
"iopub.status.busy": "2023-06-06T16:13:30.942633Z",
|
183 |
+
"iopub.status.idle": "2023-06-06T16:16:55.896473Z",
|
184 |
+
"shell.execute_reply": "2023-06-06T16:16:55.895239Z",
|
185 |
+
"shell.execute_reply.started": "2023-06-06T16:13:30.942955Z"
|
186 |
+
}
|
187 |
+
},
|
188 |
+
"outputs": [],
|
189 |
+
"source": [
|
190 |
+
"learn = vision_learner(dls, resnet50, metrics=error_rate)\n",
|
191 |
+
"learn.fine_tune(epochs=3)"
|
192 |
+
]
|
193 |
+
},
|
194 |
+
{
|
195 |
+
"cell_type": "code",
|
196 |
+
"execution_count": null,
|
197 |
+
"metadata": {
|
198 |
+
"execution": {
|
199 |
+
"iopub.execute_input": "2023-06-06T16:16:55.899023Z",
|
200 |
+
"iopub.status.busy": "2023-06-06T16:16:55.898611Z",
|
201 |
+
"iopub.status.idle": "2023-06-06T16:17:12.173908Z",
|
202 |
+
"shell.execute_reply": "2023-06-06T16:17:12.172400Z",
|
203 |
+
"shell.execute_reply.started": "2023-06-06T16:16:55.898975Z"
|
204 |
+
}
|
205 |
+
},
|
206 |
+
"outputs": [],
|
207 |
+
"source": [
|
208 |
+
"from IPython.core.pylabtools import figsize \n",
|
209 |
+
"interp = ClassificationInterpretation.from_learner(learn)\n",
|
210 |
+
"interp.plot_confusion_matrix(figsize=(10,10))"
|
211 |
+
]
|
212 |
+
},
|
213 |
+
{
|
214 |
+
"cell_type": "code",
|
215 |
+
"execution_count": null,
|
216 |
+
"metadata": {
|
217 |
+
"execution": {
|
218 |
+
"iopub.execute_input": "2023-06-06T16:17:12.177922Z",
|
219 |
+
"iopub.status.busy": "2023-06-06T16:17:12.177508Z",
|
220 |
+
"iopub.status.idle": "2023-06-06T16:17:13.734058Z",
|
221 |
+
"shell.execute_reply": "2023-06-06T16:17:13.732857Z",
|
222 |
+
"shell.execute_reply.started": "2023-06-06T16:17:12.177864Z"
|
223 |
+
}
|
224 |
+
},
|
225 |
+
"outputs": [],
|
226 |
+
"source": [
|
227 |
+
"interp.plot_top_losses(20, nrows=10, figsize=(20,20))"
|
228 |
+
]
|
229 |
+
},
|
230 |
+
{
|
231 |
+
"cell_type": "code",
|
232 |
+
"execution_count": null,
|
233 |
+
"metadata": {
|
234 |
+
"execution": {
|
235 |
+
"iopub.execute_input": "2023-06-06T16:17:13.739200Z",
|
236 |
+
"iopub.status.busy": "2023-06-06T16:17:13.735848Z",
|
237 |
+
"iopub.status.idle": "2023-06-06T16:17:13.744700Z",
|
238 |
+
"shell.execute_reply": "2023-06-06T16:17:13.743507Z",
|
239 |
+
"shell.execute_reply.started": "2023-06-06T16:17:13.739151Z"
|
240 |
+
}
|
241 |
+
},
|
242 |
+
"outputs": [],
|
243 |
+
"source": [
|
244 |
+
"test_image = '/kaggle/input/speuntapped/test/test/ang20190922t192642-4_r4928_c373-plume.png'"
|
245 |
+
]
|
246 |
+
},
|
247 |
+
{
|
248 |
+
"cell_type": "code",
|
249 |
+
"execution_count": null,
|
250 |
+
"metadata": {
|
251 |
+
"execution": {
|
252 |
+
"iopub.execute_input": "2023-06-06T16:17:13.750250Z",
|
253 |
+
"iopub.status.busy": "2023-06-06T16:17:13.749605Z",
|
254 |
+
"iopub.status.idle": "2023-06-06T16:17:13.883090Z",
|
255 |
+
"shell.execute_reply": "2023-06-06T16:17:13.881894Z",
|
256 |
+
"shell.execute_reply.started": "2023-06-06T16:17:13.750206Z"
|
257 |
+
}
|
258 |
+
},
|
259 |
+
"outputs": [],
|
260 |
+
"source": [
|
261 |
+
"is_plume,_,probs = learn.predict(PILImage.create(test_image))\n",
|
262 |
+
"print(f\"This is a: {is_plume}.\")\n",
|
263 |
+
"print(f\"Probability it's a plume: {probs[1]:.4f}\")"
|
264 |
+
]
|
265 |
+
},
|
266 |
+
{
|
267 |
+
"cell_type": "code",
|
268 |
+
"execution_count": null,
|
269 |
+
"metadata": {
|
270 |
+
"execution": {
|
271 |
+
"iopub.execute_input": "2023-06-06T16:22:39.764768Z",
|
272 |
+
"iopub.status.busy": "2023-06-06T16:22:39.764285Z",
|
273 |
+
"iopub.status.idle": "2023-06-06T16:22:40.137875Z",
|
274 |
+
"shell.execute_reply": "2023-06-06T16:22:40.136697Z",
|
275 |
+
"shell.execute_reply.started": "2023-06-06T16:22:39.764726Z"
|
276 |
+
}
|
277 |
+
},
|
278 |
+
"outputs": [],
|
279 |
+
"source": [
|
280 |
+
"learn.export('methane plume detect.pkl')"
|
281 |
+
]
|
282 |
+
},
|
283 |
+
{
|
284 |
+
"cell_type": "code",
|
285 |
+
"execution_count": null,
|
286 |
+
"metadata": {},
|
287 |
+
"outputs": [],
|
288 |
+
"source": []
|
289 |
+
}
|
290 |
+
],
|
291 |
+
"metadata": {
|
292 |
+
"kernelspec": {
|
293 |
+
"display_name": "Python 3 (ipykernel)",
|
294 |
+
"language": "python",
|
295 |
+
"name": "python3"
|
296 |
+
},
|
297 |
+
"language_info": {
|
298 |
+
"codemirror_mode": {
|
299 |
+
"name": "ipython",
|
300 |
+
"version": 3
|
301 |
+
},
|
302 |
+
"file_extension": ".py",
|
303 |
+
"mimetype": "text/x-python",
|
304 |
+
"name": "python",
|
305 |
+
"nbconvert_exporter": "python",
|
306 |
+
"pygments_lexer": "ipython3",
|
307 |
+
"version": "3.10.9"
|
308 |
+
}
|
309 |
+
},
|
310 |
+
"nbformat": 4,
|
311 |
+
"nbformat_minor": 4
|
312 |
+
}
|
01b85fbbaa5d9f3a0d8f.png β noplume1.png
RENAMED
File without changes
|
0021b95ff4079cc9b1b7.png β noplume2.png
RENAMED
File without changes
|
GAO20200713t154610p0000-A_r3181_c599-plume.png β plume1.png
RENAMED
File without changes
|
GAO20200714t150714p0000-A_r8908_c870-plume.png β plume2.png
RENAMED
File without changes
|