Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import numpy as np
|
|
7 |
import matplotlib.pyplot as plt
|
8 |
from matplotlib.colors import Normalize
|
9 |
from io import BytesIO
|
|
|
10 |
|
11 |
# Images path
|
12 |
path_main = 'Data/'
|
@@ -16,40 +17,119 @@ images_file = path_main + 'Scennarios init/Scennarios W'
|
|
16 |
modelo_1ap = load_model(path_main + 'Models/modelo_1ap_app.keras')
|
17 |
modelo_2ap = load_model(path_main + 'Models/modelo_2ap_app.keras')
|
18 |
|
19 |
-
plt.rc('font', family='Times New Roman')
|
20 |
fontsize_t = 15
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def coordinates_process(texto, interference):
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
coordinates = texto.split("), ")
|
24 |
|
25 |
resultado = []
|
26 |
for coord in coordinates:
|
27 |
try:
|
28 |
-
coord = coord.replace("(", "").replace(")", "")
|
29 |
-
x, y = map(int, coord.split(","))
|
30 |
-
|
31 |
if 0 <= x <= 255 and 0 <= y <= 255:
|
32 |
resultado.append((x, y))
|
33 |
else:
|
34 |
-
|
35 |
except ValueError:
|
36 |
-
|
|
|
|
|
|
|
37 |
|
38 |
while len(resultado) < 3 and interference == True:
|
39 |
resultado.append((0, 0))
|
40 |
-
|
41 |
while len(resultado) < 5 and interference == False:
|
42 |
resultado.append((0, 0))
|
43 |
|
44 |
-
|
|
|
45 |
|
46 |
# plan images path
|
47 |
def plan_images_list():
|
48 |
return [file_ for file_ in os.listdir(images_file) if file_.endswith((".JPG", ".jpg", ".jpeg", ".png", ".PNG"))]
|
49 |
|
50 |
# MAIN FUNCTION ****************************************************************
|
51 |
-
def main_function(plan_name, interference, aps_int, aps_coor,
|
52 |
-
apch1, apch6, apch11, coord1, coord6, coord11):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
# **************************************************************************
|
55 |
imagencober = {}
|
@@ -58,8 +138,9 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
58 |
|
59 |
for k in range(5):
|
60 |
plt.imshow(prediction_rgb, cmap='gray')
|
61 |
-
plt.title(f'No coverage', fontsize=fontsize_t + 2
|
62 |
plt.axis("off")
|
|
|
63 |
|
64 |
buf = BytesIO()
|
65 |
plt.savefig(buf, format='png')
|
@@ -82,7 +163,7 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
82 |
dimension = 256
|
83 |
|
84 |
if interference:
|
85 |
-
|
86 |
channels = 3
|
87 |
num_APs = np.zeros(channels, dtype=int)
|
88 |
num_APs[0] = apch1
|
@@ -100,7 +181,7 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
100 |
|
101 |
if not interference:
|
102 |
channels = aps_int
|
103 |
-
aps_chs = np.zeros((dimension, dimension,
|
104 |
coordinates = coordinates_process(aps_coor, interference)
|
105 |
|
106 |
for att, (x, y) in enumerate(coordinates):
|
@@ -147,16 +228,24 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
147 |
|
148 |
if np.all(prediction == 0):
|
149 |
plt.imshow(prediction_rgb, cmap='gray')
|
150 |
-
plt.title(f'No coverage', fontsize=fontsize_t
|
151 |
plt.axis("off")
|
|
|
152 |
else:
|
153 |
plt.imshow(prediction_rgb, cmap='jet')
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
plt.axis("off")
|
|
|
160 |
|
161 |
# Save the plot to a buffer
|
162 |
buf = BytesIO()
|
@@ -167,9 +256,6 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
167 |
# Convert buffer to an image
|
168 |
imagencober[k] = Image.open(buf)
|
169 |
|
170 |
-
# Cell map estimation
|
171 |
-
layer_indices.append(np.argmax(prediction, axis=0))
|
172 |
-
|
173 |
# Final coverage
|
174 |
if deep_coverage:
|
175 |
deep_coverage = np.array(deep_coverage)
|
@@ -180,10 +266,15 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
180 |
|
181 |
plt.imshow(resultado_rgb, cmap='jet')
|
182 |
cbar = plt.colorbar(ticks=np.linspace(0, 1, num=6))
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
186 |
plt.axis("off")
|
|
|
187 |
|
188 |
# Save the plot to a buffer
|
189 |
buf = BytesIO()
|
@@ -195,16 +286,17 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
195 |
imagen3 = Image.open(buf)
|
196 |
|
197 |
# **************************************************************************
|
198 |
-
|
199 |
-
if num_APs[0] > 0 and num_APs[1] > 0 and num_APs[2] > 0
|
200 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green'])
|
201 |
plt.imshow(celdas, cmap=cmap)
|
202 |
cbar = plt.colorbar()
|
203 |
cbar.set_ticks([0, 1, 2])
|
204 |
cbar.set_ticklabels(['1', '6', '11'])
|
205 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
206 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
207 |
plt.axis("off")
|
|
|
208 |
|
209 |
# Save the plot to a buffer
|
210 |
buf = BytesIO()
|
@@ -215,15 +307,16 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
215 |
# Convert buffer to an image
|
216 |
imagen4 = Image.open(buf)
|
217 |
|
218 |
-
|
219 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
|
220 |
plt.imshow(celdas, cmap=cmap)
|
221 |
cbar = plt.colorbar()
|
222 |
cbar.set_ticks([0, 1])
|
223 |
cbar.set_ticklabels(['1', '6'])
|
224 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
225 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
226 |
plt.axis("off")
|
|
|
227 |
|
228 |
# Save the plot to a buffer
|
229 |
buf = BytesIO()
|
@@ -234,15 +327,16 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
234 |
# Convert buffer to an image
|
235 |
imagen4 = Image.open(buf)
|
236 |
|
237 |
-
|
238 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
|
239 |
plt.imshow(celdas, cmap=cmap)
|
240 |
cbar = plt.colorbar()
|
241 |
cbar.set_ticks([0, 1])
|
242 |
cbar.set_ticklabels(['1', '11'])
|
243 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
244 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
245 |
plt.axis("off")
|
|
|
246 |
|
247 |
# Save the plot to a buffer
|
248 |
buf = BytesIO()
|
@@ -253,15 +347,16 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
253 |
# Convert buffer to an image
|
254 |
imagen4 = Image.open(buf)
|
255 |
|
256 |
-
|
257 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
|
258 |
plt.imshow(celdas, cmap=cmap)
|
259 |
cbar = plt.colorbar()
|
260 |
cbar.set_ticks([0, 1])
|
261 |
cbar.set_ticklabels(['6', '11'])
|
262 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
263 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
264 |
plt.axis("off")
|
|
|
265 |
|
266 |
# Save the plot to a buffer
|
267 |
buf = BytesIO()
|
@@ -272,35 +367,16 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
272 |
# Convert buffer to an image
|
273 |
imagen4 = Image.open(buf)
|
274 |
|
275 |
-
|
276 |
-
cmap = plt.cm.colors.ListedColormap(['blue'])
|
277 |
-
plt.imshow(celdas, cmap=cmap)
|
278 |
-
cbar = plt.colorbar()
|
279 |
-
cbar.set_ticks([0])
|
280 |
-
cbar.set_ticklabels(['1'])
|
281 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t, fontname='Times New Roman')
|
282 |
-
cbar.ax.tick_params(labelsize=fontsize_t, labelfontfamily = 'Times New Roman')
|
283 |
-
plt.axis("off")
|
284 |
-
|
285 |
-
if num_APs[0] == 0 and num_APs[1] > 0 and num_APs[2] == 0 and interference == True:
|
286 |
-
cmap = plt.cm.colors.ListedColormap(['blue'])
|
287 |
-
plt.imshow(celdas, cmap=cmap)
|
288 |
-
cbar = plt.colorbar()
|
289 |
-
cbar.set_ticks([0])
|
290 |
-
cbar.set_ticklabels(['1'])
|
291 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t, fontname='Times New Roman')
|
292 |
-
cbar.ax.tick_params(labelsize=fontsize_t, labelfontfamily = 'Times New Roman')
|
293 |
-
plt.axis("off")
|
294 |
-
|
295 |
-
if num_APs[0] == 0 and num_APs[1] == 0 and num_APs[2] > 0 and interference == True:
|
296 |
cmap = plt.cm.colors.ListedColormap(['blue'])
|
297 |
plt.imshow(celdas, cmap=cmap)
|
298 |
cbar = plt.colorbar()
|
299 |
cbar.set_ticks([0])
|
300 |
cbar.set_ticklabels(['1'])
|
301 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
302 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
303 |
plt.axis("off")
|
|
|
304 |
|
305 |
# Save the plot to a buffer
|
306 |
buf = BytesIO()
|
@@ -313,15 +389,17 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
313 |
|
314 |
# **************************************************************************
|
315 |
|
316 |
-
|
317 |
-
|
|
|
318 |
plt.imshow(celdas, cmap=cmap)
|
319 |
cbar = plt.colorbar()
|
320 |
-
cbar.set_ticks([0, 1, 2])
|
321 |
cbar.set_ticklabels(['1', '2', '3', '4', '5'])
|
322 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
323 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
324 |
plt.axis("off")
|
|
|
325 |
|
326 |
# Save the plot to a buffer
|
327 |
buf = BytesIO()
|
@@ -332,15 +410,16 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
332 |
# Convert buffer to an image
|
333 |
imagen4 = Image.open(buf)
|
334 |
|
335 |
-
|
336 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green', 'yellow'])
|
337 |
plt.imshow(celdas, cmap=cmap)
|
338 |
cbar = plt.colorbar()
|
339 |
-
cbar.set_ticks([0, 1, 2])
|
340 |
cbar.set_ticklabels(['1', '2', '3', '4'])
|
341 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
342 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
343 |
plt.axis("off")
|
|
|
344 |
|
345 |
# Save the plot to a buffer
|
346 |
buf = BytesIO()
|
@@ -351,15 +430,16 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
351 |
# Convert buffer to an image
|
352 |
imagen4 = Image.open(buf)
|
353 |
|
354 |
-
|
355 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green'])
|
356 |
plt.imshow(celdas, cmap=cmap)
|
357 |
cbar = plt.colorbar()
|
358 |
cbar.set_ticks([0, 1, 2])
|
359 |
-
cbar.set_ticklabels(['1', '2', '3'
|
360 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
361 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
362 |
plt.axis("off")
|
|
|
363 |
|
364 |
# Save the plot to a buffer
|
365 |
buf = BytesIO()
|
@@ -370,15 +450,16 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
370 |
# Convert buffer to an image
|
371 |
imagen4 = Image.open(buf)
|
372 |
|
373 |
-
|
374 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
|
375 |
plt.imshow(celdas, cmap=cmap)
|
376 |
cbar = plt.colorbar()
|
377 |
-
cbar.set_ticks([0, 1
|
378 |
cbar.set_ticklabels(['1', '2'])
|
379 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
380 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
381 |
plt.axis("off")
|
|
|
382 |
|
383 |
# Save the plot to a buffer
|
384 |
buf = BytesIO()
|
@@ -389,15 +470,16 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
389 |
# Convert buffer to an image
|
390 |
imagen4 = Image.open(buf)
|
391 |
|
392 |
-
|
393 |
cmap = plt.cm.colors.ListedColormap(['blue'])
|
394 |
plt.imshow(celdas, cmap=cmap)
|
395 |
cbar = plt.colorbar()
|
396 |
-
cbar.set_ticks([0
|
397 |
cbar.set_ticklabels(['1'])
|
398 |
-
cbar.set_label('Cell ID', fontsize=fontsize_t
|
399 |
-
cbar.ax.tick_params(labelsize=fontsize_t
|
400 |
plt.axis("off")
|
|
|
401 |
|
402 |
# Save the plot to a buffer
|
403 |
buf = BytesIO()
|
@@ -412,48 +494,6 @@ def main_function(plan_name, interference, aps_int, aps_coor,
|
|
412 |
|
413 |
return [imagencober[0], imagencober[1], imagencober[2], imagencober[3], imagencober[4], imagen3, imagen4]
|
414 |
|
415 |
-
# Plan visualization
|
416 |
-
def load_plan_vi(mapa_seleccionado, uploaded_file):
|
417 |
-
|
418 |
-
if mapa_seleccionado == "Upload your own image":
|
419 |
-
plan_image = Image.open(uploaded_file.name)
|
420 |
-
else:
|
421 |
-
image_plan_path1 = os.path.join(images_file, mapa_seleccionado)
|
422 |
-
plan_image = Image.open(image_plan_path1)
|
423 |
-
|
424 |
-
plan_n = np.array(plan_image.convert('RGB'))
|
425 |
-
|
426 |
-
plt.imshow(plan_n)
|
427 |
-
plt.xticks(np.arange(0, 256, 50), fontsize=fontsize_t, fontname='Times New Roman')
|
428 |
-
plt.yticks(np.arange(0, 256, 50), fontsize=fontsize_t, fontname='Times New Roman')
|
429 |
-
plt.xlabel("X Coordinate [Pixels]", fontsize=fontsize_t, fontname='Times New Roman')
|
430 |
-
plt.ylabel("Y Coordinate [Pixels]", fontsize=fontsize_t, fontname='Times New Roman')
|
431 |
-
|
432 |
-
buf = BytesIO()
|
433 |
-
plt.savefig(buf, format='png')
|
434 |
-
buf.seek(0)
|
435 |
-
plt.close()
|
436 |
-
|
437 |
-
plan_im = Image.open(buf)
|
438 |
-
|
439 |
-
tick_positions = np.linspace(0, 256, 15)
|
440 |
-
tick_labels = np.linspace(0, 20, 15, dtype=int)
|
441 |
-
|
442 |
-
buf = BytesIO()
|
443 |
-
plt.imshow(plan_n)
|
444 |
-
plt.xticks(tick_positions, tick_labels, fontsize=fontsize_t, fontname='Times New Roman')
|
445 |
-
plt.yticks(tick_positions, tick_labels, fontsize=fontsize_t, fontname='Times New Roman')
|
446 |
-
plt.xlabel("X Coordinate [meters]", fontsize=fontsize_t, fontname='Times New Roman')
|
447 |
-
plt.ylabel("Y Coordinate [meters]", fontsize=fontsize_t, fontname='Times New Roman')
|
448 |
-
|
449 |
-
plt.savefig(buf, format='png')
|
450 |
-
buf.seek(0)
|
451 |
-
plt.close()
|
452 |
-
|
453 |
-
plan_im_meters = Image.open(buf)
|
454 |
-
|
455 |
-
return plan_im, plan_im_meters
|
456 |
-
|
457 |
def update_interface(enable_interference):
|
458 |
if enable_interference:
|
459 |
return {
|
@@ -471,7 +511,9 @@ def update_interface(enable_interference):
|
|
471 |
image_ap2 : gr.update(visible=False),
|
472 |
image_ch1 : gr.update(visible=True),
|
473 |
image_ch6 : gr.update(visible=True),
|
474 |
-
image_ch11 : gr.update(visible=True)
|
|
|
|
|
475 |
}
|
476 |
else:
|
477 |
return {
|
@@ -495,7 +537,17 @@ def update_interface(enable_interference):
|
|
495 |
with gr.Blocks() as demo:
|
496 |
gr.Markdown("""
|
497 |
## Fast Indoor Radio Propagation Prediction using Deep Learning
|
498 |
-
This app uses deep learning models for radio map estimation (RME). RME
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
""")
|
500 |
|
501 |
enable_interference = gr.Checkbox(label="Enable Interference Analysis", value=True)
|
@@ -504,15 +556,15 @@ with gr.Blocks() as demo:
|
|
504 |
with gr.Column(scale=1):
|
505 |
map_dropdown = gr.Dropdown(choices=plan_images_list() + ["Upload your own image"], label="Select indoor plan")
|
506 |
upload_image = gr.File(label="Or upload your own image", file_types=[".JPG", ".jpg", ".jpeg", ".png", ".PNG"])
|
507 |
-
ch1_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 1")
|
508 |
-
ch6_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 6")
|
509 |
-
ch11_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 11")
|
510 |
coords_ch1_input = gr.Textbox(label="Coordinate CH 1", placeholder="Format (Pixels): (x1, y1), (x2, y2)")
|
511 |
coords_ch6_input = gr.Textbox(label="Coordinate CH 6", placeholder="Format (Pixels): (x1, y1), (x2, y2)")
|
512 |
coords_ch11_input = gr.Textbox(label="Coordinate CH 11", placeholder="Format (Pixels): (x1, y1), (x2, y2)")
|
513 |
|
514 |
simple_dropdown = gr.Dropdown(choices=[str(i) for i in range(1, 6)], label="Select APs number", visible=False)
|
515 |
-
simple_coords = gr.Textbox(label="Enter APs coordinates", placeholder="Format (Pixels): (x1, y1), (x1, y1)...", visible=False)
|
516 |
|
517 |
button1 = gr.Button("Load plan")
|
518 |
button2 = gr.Button("Predict coverage")
|
|
|
7 |
import matplotlib.pyplot as plt
|
8 |
from matplotlib.colors import Normalize
|
9 |
from io import BytesIO
|
10 |
+
import re
|
11 |
|
12 |
# Images path
|
13 |
path_main = 'Data/'
|
|
|
17 |
modelo_1ap = load_model(path_main + 'Models/modelo_1ap_app.keras')
|
18 |
modelo_2ap = load_model(path_main + 'Models/modelo_2ap_app.keras')
|
19 |
|
|
|
20 |
fontsize_t = 15
|
21 |
|
22 |
+
# Plan visualization
|
23 |
+
def load_plan_vi(mapa_seleccionado, uploaded_file):
|
24 |
+
|
25 |
+
if mapa_seleccionado == "Upload your own image" and uploaded_file is not None:
|
26 |
+
plan_image = Image.open(uploaded_file.name)
|
27 |
+
elif mapa_seleccionado == "Upload your own image" and uploaded_file is None:
|
28 |
+
image_plan_path1 = os.path.join(images_file, "100.JPG")
|
29 |
+
plan_image = Image.open(image_plan_path1)
|
30 |
+
else:
|
31 |
+
image_plan_path1 = os.path.join(images_file, mapa_seleccionado)
|
32 |
+
plan_image = Image.open(image_plan_path1)
|
33 |
+
|
34 |
+
plan_n = np.array(plan_image.convert('RGB'))
|
35 |
+
|
36 |
+
plt.imshow(plan_n)
|
37 |
+
plt.xticks(np.arange(0, 256, 50), fontsize=fontsize_t)
|
38 |
+
plt.yticks(np.arange(0, 256, 50), fontsize=fontsize_t)
|
39 |
+
plt.xlabel("X Coordinate [Pixels]", fontsize=fontsize_t)
|
40 |
+
plt.ylabel("Y Coordinate [Pixels]", fontsize=fontsize_t)
|
41 |
+
plt.show()
|
42 |
+
|
43 |
+
buf = BytesIO()
|
44 |
+
plt.savefig(buf, format='png')
|
45 |
+
buf.seek(0)
|
46 |
+
plt.close()
|
47 |
+
|
48 |
+
plan_im = Image.open(buf)
|
49 |
+
|
50 |
+
tick_positions = np.linspace(0, 256, 15)
|
51 |
+
tick_labels = np.linspace(0, 20, 15, dtype=int)
|
52 |
+
|
53 |
+
buf = BytesIO()
|
54 |
+
plt.imshow(plan_n)
|
55 |
+
plt.xticks(tick_positions, tick_labels, fontsize=fontsize_t)
|
56 |
+
plt.yticks(tick_positions, tick_labels, fontsize=fontsize_t)
|
57 |
+
plt.xlabel("X Coordinate [meters]", fontsize=fontsize_t)
|
58 |
+
plt.ylabel("Y Coordinate [meters]", fontsize=fontsize_t)
|
59 |
+
plt.show()
|
60 |
+
|
61 |
+
plt.savefig(buf, format='png')
|
62 |
+
buf.seek(0)
|
63 |
+
plt.close()
|
64 |
+
|
65 |
+
plan_im_meters = Image.open(buf)
|
66 |
+
|
67 |
+
return plan_im, plan_im_meters
|
68 |
+
|
69 |
+
def validate_coords(num_aps, coords):
|
70 |
+
matches = re.findall(r"\(\s*\d+\s*,\s*\d+\s*\)", coords)
|
71 |
+
|
72 |
+
if len(matches) > int(num_aps):
|
73 |
+
new_coords = ", ".join(matches[:int(num_aps)])
|
74 |
+
return new_coords
|
75 |
+
return coords
|
76 |
+
|
77 |
def coordinates_process(texto, interference):
|
78 |
+
a = False
|
79 |
+
|
80 |
+
texto = re.sub(r'\s*,\s*', ', ', texto)
|
81 |
+
texto = re.sub(r'\)\s*,\s*\(', '), (', texto)
|
82 |
+
texto = texto.strip()
|
83 |
+
|
84 |
coordinates = texto.split("), ")
|
85 |
|
86 |
resultado = []
|
87 |
for coord in coordinates:
|
88 |
try:
|
89 |
+
coord = coord.replace("(", "").replace(")", "")
|
90 |
+
x, y = map(int, coord.split(","))
|
91 |
+
|
92 |
if 0 <= x <= 255 and 0 <= y <= 255:
|
93 |
resultado.append((x, y))
|
94 |
else:
|
95 |
+
a = True
|
96 |
except ValueError:
|
97 |
+
a = True
|
98 |
+
|
99 |
+
if a:
|
100 |
+
resultado = [(0, 0), (0, 0), (0, 0)]
|
101 |
|
102 |
while len(resultado) < 3 and interference == True:
|
103 |
resultado.append((0, 0))
|
|
|
104 |
while len(resultado) < 5 and interference == False:
|
105 |
resultado.append((0, 0))
|
106 |
|
107 |
+
resultado_str = ", ".join([f"({x}, {y})" for x, y in resultado])
|
108 |
+
return resultado_str
|
109 |
|
110 |
# plan images path
|
111 |
def plan_images_list():
|
112 |
return [file_ for file_ in os.listdir(images_file) if file_.endswith((".JPG", ".jpg", ".jpeg", ".png", ".PNG"))]
|
113 |
|
114 |
# MAIN FUNCTION ****************************************************************
|
115 |
+
def main_function(plan_name, interference = True, aps_int = 0, aps_coor = '(0,0)',
|
116 |
+
apch1 = 0, apch6 = 0, apch11 = 0, coord1 = '(0,0)', coord6 = '(0,0)', coord11 = '(0,0)'):
|
117 |
+
|
118 |
+
plan_name = str(plan_name)
|
119 |
+
interference = bool(interference)
|
120 |
+
aps_int = int(aps_int)
|
121 |
+
aps_coor = str(aps_coor)
|
122 |
+
apch1 = int(apch1)
|
123 |
+
apch6 = int(apch6)
|
124 |
+
apch11 = int(apch11)
|
125 |
+
coord1 = str(coord1)
|
126 |
+
coord6 = str(coord6)
|
127 |
+
coord11 = str(coord11)
|
128 |
+
|
129 |
+
aps_coor = validate_coords(aps_int, aps_coor)
|
130 |
+
coord1 = validate_coords(apch1, coord1)
|
131 |
+
coord6 = validate_coords(apch6, coord6)
|
132 |
+
coord11 = validate_coords(apch11, coord11)
|
133 |
|
134 |
# **************************************************************************
|
135 |
imagencober = {}
|
|
|
138 |
|
139 |
for k in range(5):
|
140 |
plt.imshow(prediction_rgb, cmap='gray')
|
141 |
+
plt.title(f'No coverage', fontsize=fontsize_t + 2)
|
142 |
plt.axis("off")
|
143 |
+
# plt.show()
|
144 |
|
145 |
buf = BytesIO()
|
146 |
plt.savefig(buf, format='png')
|
|
|
163 |
dimension = 256
|
164 |
|
165 |
if interference:
|
166 |
+
channels_c = [1, 6 , 11]
|
167 |
channels = 3
|
168 |
num_APs = np.zeros(channels, dtype=int)
|
169 |
num_APs[0] = apch1
|
|
|
181 |
|
182 |
if not interference:
|
183 |
channels = aps_int
|
184 |
+
aps_chs = np.zeros((dimension, dimension, 5)) # Crear la matriz
|
185 |
coordinates = coordinates_process(aps_coor, interference)
|
186 |
|
187 |
for att, (x, y) in enumerate(coordinates):
|
|
|
228 |
|
229 |
if np.all(prediction == 0):
|
230 |
plt.imshow(prediction_rgb, cmap='gray')
|
231 |
+
plt.title(f'No coverage', fontsize=fontsize_t)
|
232 |
plt.axis("off")
|
233 |
+
plt.show()
|
234 |
else:
|
235 |
plt.imshow(prediction_rgb, cmap='jet')
|
236 |
+
if interference:
|
237 |
+
plt.title(f'Coverage CH {channels_c[k]}', fontsize=fontsize_t)
|
238 |
+
cbar = plt.colorbar(ticks=np.linspace(0, 1, num=6),)
|
239 |
+
cbar.set_label('SINR [dB]', fontsize=fontsize_t)
|
240 |
+
cbar.set_ticklabels(['-3.01', '20.29', '43.60', '66.90', '90.20', '113.51'])
|
241 |
+
if not interference:
|
242 |
+
plt.title(f'Coverage AP {k}', fontsize=fontsize_t)
|
243 |
+
cbar = plt.colorbar(ticks=np.linspace(0, 1, num=6),)
|
244 |
+
cbar.set_label('Power [dBm]', fontsize=fontsize_t)
|
245 |
+
cbar.set_ticklabels(['-94.94', '-70.75', '-46.56', '-22.38', '1.81', '26.00'])
|
246 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
247 |
plt.axis("off")
|
248 |
+
plt.show()
|
249 |
|
250 |
# Save the plot to a buffer
|
251 |
buf = BytesIO()
|
|
|
256 |
# Convert buffer to an image
|
257 |
imagencober[k] = Image.open(buf)
|
258 |
|
|
|
|
|
|
|
259 |
# Final coverage
|
260 |
if deep_coverage:
|
261 |
deep_coverage = np.array(deep_coverage)
|
|
|
266 |
|
267 |
plt.imshow(resultado_rgb, cmap='jet')
|
268 |
cbar = plt.colorbar(ticks=np.linspace(0, 1, num=6))
|
269 |
+
if interference:
|
270 |
+
cbar.set_label('SINR [dB]', fontsize=fontsize_t)
|
271 |
+
cbar.set_ticklabels(['-3.01', '20.29', '43.60', '66.90', '90.20', '113.51'])
|
272 |
+
if not interference:
|
273 |
+
cbar.set_label('Power [dBm]', fontsize=fontsize_t)
|
274 |
+
cbar.set_ticklabels(['-94.94', '-70.75', '-46.56', '-22.38', '1.81', '26.00'])
|
275 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
276 |
plt.axis("off")
|
277 |
+
plt.show()
|
278 |
|
279 |
# Save the plot to a buffer
|
280 |
buf = BytesIO()
|
|
|
286 |
imagen3 = Image.open(buf)
|
287 |
|
288 |
# **************************************************************************
|
289 |
+
if interference == True:
|
290 |
+
if num_APs[0] > 0 and num_APs[1] > 0 and num_APs[2] > 0:
|
291 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green'])
|
292 |
plt.imshow(celdas, cmap=cmap)
|
293 |
cbar = plt.colorbar()
|
294 |
cbar.set_ticks([0, 1, 2])
|
295 |
cbar.set_ticklabels(['1', '6', '11'])
|
296 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
297 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
298 |
plt.axis("off")
|
299 |
+
plt.show()
|
300 |
|
301 |
# Save the plot to a buffer
|
302 |
buf = BytesIO()
|
|
|
307 |
# Convert buffer to an image
|
308 |
imagen4 = Image.open(buf)
|
309 |
|
310 |
+
elif num_APs[0] > 0 and num_APs[1] > 0:
|
311 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
|
312 |
plt.imshow(celdas, cmap=cmap)
|
313 |
cbar = plt.colorbar()
|
314 |
cbar.set_ticks([0, 1])
|
315 |
cbar.set_ticklabels(['1', '6'])
|
316 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
317 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
318 |
plt.axis("off")
|
319 |
+
plt.show()
|
320 |
|
321 |
# Save the plot to a buffer
|
322 |
buf = BytesIO()
|
|
|
327 |
# Convert buffer to an image
|
328 |
imagen4 = Image.open(buf)
|
329 |
|
330 |
+
elif num_APs[0] > 0 and num_APs[2] > 0:
|
331 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
|
332 |
plt.imshow(celdas, cmap=cmap)
|
333 |
cbar = plt.colorbar()
|
334 |
cbar.set_ticks([0, 1])
|
335 |
cbar.set_ticklabels(['1', '11'])
|
336 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
337 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
338 |
plt.axis("off")
|
339 |
+
plt.show()
|
340 |
|
341 |
# Save the plot to a buffer
|
342 |
buf = BytesIO()
|
|
|
347 |
# Convert buffer to an image
|
348 |
imagen4 = Image.open(buf)
|
349 |
|
350 |
+
elif num_APs[1] > 0 and num_APs[2] > 0:
|
351 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
|
352 |
plt.imshow(celdas, cmap=cmap)
|
353 |
cbar = plt.colorbar()
|
354 |
cbar.set_ticks([0, 1])
|
355 |
cbar.set_ticklabels(['6', '11'])
|
356 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
357 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
358 |
plt.axis("off")
|
359 |
+
plt.show()
|
360 |
|
361 |
# Save the plot to a buffer
|
362 |
buf = BytesIO()
|
|
|
367 |
# Convert buffer to an image
|
368 |
imagen4 = Image.open(buf)
|
369 |
|
370 |
+
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
cmap = plt.cm.colors.ListedColormap(['blue'])
|
372 |
plt.imshow(celdas, cmap=cmap)
|
373 |
cbar = plt.colorbar()
|
374 |
cbar.set_ticks([0])
|
375 |
cbar.set_ticklabels(['1'])
|
376 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
377 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
378 |
plt.axis("off")
|
379 |
+
plt.show()
|
380 |
|
381 |
# Save the plot to a buffer
|
382 |
buf = BytesIO()
|
|
|
389 |
|
390 |
# **************************************************************************
|
391 |
|
392 |
+
if interference == False:
|
393 |
+
if aps_int == 5:
|
394 |
+
cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green', 'yellow', 'violet'])
|
395 |
plt.imshow(celdas, cmap=cmap)
|
396 |
cbar = plt.colorbar()
|
397 |
+
cbar.set_ticks([0, 1, 2, 3, 4])
|
398 |
cbar.set_ticklabels(['1', '2', '3', '4', '5'])
|
399 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
400 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
401 |
plt.axis("off")
|
402 |
+
plt.show()
|
403 |
|
404 |
# Save the plot to a buffer
|
405 |
buf = BytesIO()
|
|
|
410 |
# Convert buffer to an image
|
411 |
imagen4 = Image.open(buf)
|
412 |
|
413 |
+
elif aps_int == 4:
|
414 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green', 'yellow'])
|
415 |
plt.imshow(celdas, cmap=cmap)
|
416 |
cbar = plt.colorbar()
|
417 |
+
cbar.set_ticks([0, 1, 2, 3])
|
418 |
cbar.set_ticklabels(['1', '2', '3', '4'])
|
419 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
420 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
421 |
plt.axis("off")
|
422 |
+
plt.show()
|
423 |
|
424 |
# Save the plot to a buffer
|
425 |
buf = BytesIO()
|
|
|
430 |
# Convert buffer to an image
|
431 |
imagen4 = Image.open(buf)
|
432 |
|
433 |
+
elif aps_int == 3:
|
434 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red', 'green'])
|
435 |
plt.imshow(celdas, cmap=cmap)
|
436 |
cbar = plt.colorbar()
|
437 |
cbar.set_ticks([0, 1, 2])
|
438 |
+
cbar.set_ticklabels(['1', '2', '3'])
|
439 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
440 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
441 |
plt.axis("off")
|
442 |
+
plt.show()
|
443 |
|
444 |
# Save the plot to a buffer
|
445 |
buf = BytesIO()
|
|
|
450 |
# Convert buffer to an image
|
451 |
imagen4 = Image.open(buf)
|
452 |
|
453 |
+
elif aps_int == 2:
|
454 |
cmap = plt.cm.colors.ListedColormap(['blue', 'red'])
|
455 |
plt.imshow(celdas, cmap=cmap)
|
456 |
cbar = plt.colorbar()
|
457 |
+
cbar.set_ticks([0, 1])
|
458 |
cbar.set_ticklabels(['1', '2'])
|
459 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
460 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
461 |
plt.axis("off")
|
462 |
+
plt.show()
|
463 |
|
464 |
# Save the plot to a buffer
|
465 |
buf = BytesIO()
|
|
|
470 |
# Convert buffer to an image
|
471 |
imagen4 = Image.open(buf)
|
472 |
|
473 |
+
else:
|
474 |
cmap = plt.cm.colors.ListedColormap(['blue'])
|
475 |
plt.imshow(celdas, cmap=cmap)
|
476 |
cbar = plt.colorbar()
|
477 |
+
cbar.set_ticks([0])
|
478 |
cbar.set_ticklabels(['1'])
|
479 |
+
cbar.set_label('Cell ID', fontsize=fontsize_t)
|
480 |
+
cbar.ax.tick_params(labelsize=fontsize_t)
|
481 |
plt.axis("off")
|
482 |
+
plt.show()
|
483 |
|
484 |
# Save the plot to a buffer
|
485 |
buf = BytesIO()
|
|
|
494 |
|
495 |
return [imagencober[0], imagencober[1], imagencober[2], imagencober[3], imagencober[4], imagen3, imagen4]
|
496 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
def update_interface(enable_interference):
|
498 |
if enable_interference:
|
499 |
return {
|
|
|
511 |
image_ap2 : gr.update(visible=False),
|
512 |
image_ch1 : gr.update(visible=True),
|
513 |
image_ch6 : gr.update(visible=True),
|
514 |
+
image_ch11 : gr.update(visible=True),
|
515 |
+
simple_dropdown: gr.update(visible=False),
|
516 |
+
simple_coords: gr.update(visible=False)
|
517 |
}
|
518 |
else:
|
519 |
return {
|
|
|
537 |
with gr.Blocks() as demo:
|
538 |
gr.Markdown("""
|
539 |
## Fast Indoor Radio Propagation Prediction using Deep Learning
|
540 |
+
This app uses deep learning models for radio map estimation (RME) with and without interference, simulating 2.4 GHz and 5 GHz bands. RME involves estimating the received RF power based on spatial information maps.
|
541 |
+
|
542 |
+
Instructions for use:
|
543 |
+
|
544 |
+
- A predefined list of indoor floor plans is available for use.
|
545 |
+
- You can upload your own indoor floor plan.
|
546 |
+
- A maximum image size of 255x255 pixels is allowed.
|
547 |
+
- Negative numbers are not allowed.
|
548 |
+
- The established format for the coordinates of each access point (AP) must be followed.
|
549 |
+
- A maximum of 2 APs per channel is allowed for the interference case.
|
550 |
+
- A maximum of 5 APs is allowed for the non-interference case.
|
551 |
""")
|
552 |
|
553 |
enable_interference = gr.Checkbox(label="Enable Interference Analysis", value=True)
|
|
|
556 |
with gr.Column(scale=1):
|
557 |
map_dropdown = gr.Dropdown(choices=plan_images_list() + ["Upload your own image"], label="Select indoor plan")
|
558 |
upload_image = gr.File(label="Or upload your own image", file_types=[".JPG", ".jpg", ".jpeg", ".png", ".PNG"])
|
559 |
+
ch1_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 1", value=0)
|
560 |
+
ch6_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 6", value=0)
|
561 |
+
ch11_input = gr.Dropdown(choices=[i for i in range(0, 3)], label="Select APs CH 11", value=0)
|
562 |
coords_ch1_input = gr.Textbox(label="Coordinate CH 1", placeholder="Format (Pixels): (x1, y1), (x2, y2)")
|
563 |
coords_ch6_input = gr.Textbox(label="Coordinate CH 6", placeholder="Format (Pixels): (x1, y1), (x2, y2)")
|
564 |
coords_ch11_input = gr.Textbox(label="Coordinate CH 11", placeholder="Format (Pixels): (x1, y1), (x2, y2)")
|
565 |
|
566 |
simple_dropdown = gr.Dropdown(choices=[str(i) for i in range(1, 6)], label="Select APs number", visible=False)
|
567 |
+
simple_coords = gr.Textbox(label="Enter APs coordinates", placeholder="Format (Pixels): (x1, y1), (x1, y1)...", visible=False,)
|
568 |
|
569 |
button1 = gr.Button("Load plan")
|
570 |
button2 = gr.Button("Predict coverage")
|