-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath_cases.py
304 lines (222 loc) · 9.04 KB
/
path_cases.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import os
import random
import keras.backend as K
import matplotlib
import tensorflow as tf
from break_my_ice import break_my_ice
from ice_data import IceDetector
matplotlib.use('agg')
import matplotlib.pyplot as plt
def init_session():
config = tf.ConfigProto()
config.gpu_options.visible_device_list = "1"
K.set_session(tf.Session(config=config))
def full_ice(file_name):
good = []
for month in range(1, 13):
init_session()
detector = IceDetector(0.5, str(month)) if month >= 10 else IceDetector(0.5, "0" + str(month))
pred, val = detector.detect(file_name)
good.append(val * 100.0)
print(month, val)
return good
def generate_holes(size):
dir = "samples/conc_satellite/2013/"
holes_dir = "samples/pathological_cases/holes/" + str(size) + "/"
for month in range(1, 13):
month_str = str(month) if month >= 10 else "0" + str(month)
file = random.choice(os.listdir(dir + month_str + "/"))
from_dir = dir + month_str + "/" + file
to_dir = holes_dir + file + '_break.nc'
os.system('cp ' + from_dir + ' ' + to_dir)
print(to_dir)
break_my_ice(to_dir, 1100, 400, 'hole_' + str(size))
def generate_spots():
dir = "samples/conc_satellite/2013/"
holes_dir = "samples/pathological_cases/spots/"
for month in range(1, 13):
month_str = str(month) if month >= 10 else "0" + str(month)
file = random.choice(os.listdir(dir + month_str + "/"))
from_dir = dir + month_str + "/" + file
to_dir = holes_dir + file + '_break.nc'
os.system('cp ' + from_dir + ' ' + to_dir)
print(to_dir)
break_my_ice(to_dir, 1100, 400, 'spots')
def generate_noise():
dir = "samples/conc_satellite/2013/"
holes_dir = "samples/pathological_cases/noise/"
for month in range(1, 13):
month_str = str(month) if month >= 10 else "0" + str(month)
file = random.choice(os.listdir(dir + month_str + "/"))
from_dir = dir + month_str + "/" + file
to_dir = holes_dir + file + '_break.nc'
os.system('cp ' + from_dir + ' ' + to_dir)
print(to_dir)
break_my_ice(to_dir, 1100, 400, 'noise')
def detect_holes(size):
holes_dir = "samples/pathological_cases/holes/" + str(size) + "/"
files = []
for file in os.listdir(holes_dir):
files.append(holes_dir + file)
files = sorted(files)
good = []
idx = 1
for file in files:
init_session()
detector = IceDetector(0.5, str(idx)) if idx >= 10 else IceDetector(0.5, "0" + str(idx))
pred, val = detector.detect(file)
good.append(val * 100.0)
print(idx, val)
idx += 1
return good
def detect_spots():
holes_dir = "samples/pathological_cases/spots/"
files = []
for file in os.listdir(holes_dir):
files.append(holes_dir + file)
files = sorted(files)
good = []
idx = 1
for file in files:
init_session()
detector = IceDetector(0.5, str(idx)) if idx >= 10 else IceDetector(0.5, "0" + str(idx))
pred, val = detector.detect(file)
good.append(val * 100.0)
print(idx, val)
idx += 1
return good
def detect_noise():
holes_dir = "samples/pathological_cases/noise/"
files = []
for file in os.listdir(holes_dir):
files.append(holes_dir + file)
files = sorted(files)
good = []
idx = 1
for file in files:
init_session()
detector = IceDetector(0.5, str(idx)) if idx >= 10 else IceDetector(0.5, "0" + str(idx))
pred, val = detector.detect(file)
good.append(val * 100.0)
print(idx, val)
idx += 1
return good
def plot_holes():
plt.rcParams.update({'font.size': 22})
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot(111)
months = [i for i in range(1, 13)]
good = detect_holes(50)
plt.plot(months, good, marker='o', c="c")
good = detect_holes(100)
plt.plot(months, good, marker='o', c="y")
good = detect_holes(200)
plt.plot(months, good, marker='o', c="r")
labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
ax.set_xticks(months)
ax.set_xticklabels(labels)
plt.xlabel('Month')
plt.ylabel('Squares recognized as correct, %')
plt.title('Prediction results for ice with holes')
legend = plt.legend(['holes amount = 50', 'holes amount = 100', 'holes amount = 200'],
bbox_to_anchor=(1.05, 1), loc=2,
borderaxespad=0.)
plt.savefig("samples/pathological_cases/holes_results.png", bbox_extra_artists=(legend,), bbox_inches='tight',
dpi=500)
def plot_spots():
plt.rcParams.update({'font.size': 22})
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot(111)
months = [i for i in range(1, 13)]
good = detect_spots()
plt.plot(months, good, marker='o', c="c")
labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
ax.set_xticks(months)
ax.set_xticklabels(labels)
plt.xlabel('Month')
plt.ylabel('Squares recognized as correct, %')
plt.title('Prediction results for ice with spots')
# legend = plt.legend(['holes amount = 50', 'holes amount = 100', 'holes amount = 200'],
# bbox_to_anchor=(1.05, 1), loc=2,
# borderaxespad=0.)
plt.savefig("samples/pathological_cases/spots_results.png", dpi=500)
def plot_noise():
plt.rcParams.update({'font.size': 22})
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot(111)
months = [i for i in range(1, 13)]
good = detect_noise()
plt.plot(months, good, marker='o', c="c")
labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
ax.set_xticks(months)
ax.set_xticklabels(labels)
plt.xlabel('Month')
plt.ylabel('Squares recognized as correct, %')
plt.title('Prediction results for ice with noise')
# legend = plt.legend(['holes amount = 50', 'holes amount = 100', 'holes amount = 200'],
# bbox_to_anchor=(1.05, 1), loc=2,
# borderaxespad=0.)
plt.savefig("samples/pathological_cases/noise_results.png", dpi=500)
def plot_full_ice():
plt.rcParams.update({'font.size': 22})
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot(111)
months = [i for i in range(1, 13)]
good = full_ice("samples/pathological_cases/no_ice.nc")
plt.plot(months, good, marker='o', c="c")
good = full_ice("samples/pathological_cases/full_ice_02.nc")
plt.plot(months, good, marker='o', c="m")
good = full_ice("samples/pathological_cases/full_ice_05.nc")
plt.plot(months, good, marker='o', c="g")
good = full_ice("samples/pathological_cases/full_ice_08.nc")
plt.plot(months, good, marker='o', c="y")
good = full_ice("samples/pathological_cases/full_ice_10.nc")
plt.plot(months, good, marker='o', c='r')
m = [i for i in range(1, 13)]
labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
ax.set_xticks(m)
ax.set_xticklabels(labels)
plt.xlabel('Month')
plt.ylabel('Sub-areas recognized as correct, %')
plt.title('Prediction results for full ice case')
legend = plt.legend(['conc = 0.0', 'conc = 0.2', 'conc = 0.5', 'conc = 0.8', 'conc = 1.0'],
bbox_to_anchor=(1.05, 1), loc=2,
borderaxespad=0.)
plt.savefig("samples/pathological_cases/full_ice_results.png", bbox_extra_artists=(legend,), bbox_inches='tight',
dpi=500)
def plot_path_cases():
plt.rcParams.update({'font.size': 22})
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot(111)
months = [i for i in range(1, 13)]
noise = detect_noise()
plt.plot(months, noise, marker='o', c="c", label='Noise')
holes50 = detect_holes(50)
plt.plot(months, holes50, marker='o', c="g", label='Holes with amount = 50')
holes100 = detect_holes(100)
plt.plot(months, holes100, marker='o', c="r", label='Holes with amount = 100')
holes100 = detect_holes(200)
plt.plot(months, holes100, marker='o', c="b", label='Holes with amount = 200')
spots = detect_spots()
plt.plot(months, spots, marker='o', c="y", label='Spots')
labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
ax.set_xticks(months)
ax.set_xticklabels(labels)
plt.xlabel('Month')
plt.ylabel('Sub-areas recognized as correct, %')
plt.title('Prediction results for pathological cases')
plt.legend(loc='lower right', fontsize='medium')
# legend = plt.legend(['holes amount = 50', 'holes amount = 100', 'holes amount = 200'],
# bbox_to_anchor=(1.05, 1), loc=2,
# borderaxespad=0.)
plt.savefig("samples/pathological_cases/path_results.png", dpi=500)
# plot_full_ice()
# for size in [50, 100, 200]:
# generate_holes(size)
# plot_holes()
# generate_spots()
# plot_spots()
# generate_noise()
# plot_noise()
# plot_path_cases()
plot_full_ice()