Spaces:
Runtime error
Runtime error
new demo
Browse files- app.py +38 -84
- colormaps.py +349 -0
- helper.py +6 -3
- requirements.txt +2 -1
- texts.toml +11 -23
app.py
CHANGED
@@ -10,6 +10,7 @@ import gradio as gr
|
|
10 |
import matplotlib
|
11 |
import matplotlib.pyplot as plt
|
12 |
from huggingface_hub import hf_hub_download
|
|
|
13 |
|
14 |
matplotlib.use("Agg")
|
15 |
logger = logging.basicConfig(level=logging.ERROR)
|
@@ -48,106 +49,59 @@ def install_deepest():
|
|
48 |
return
|
49 |
|
50 |
|
51 |
-
def make_plots(
|
52 |
idx -= 1
|
53 |
-
|
54 |
-
|
55 |
-
fig_data = make_dataplot(data)
|
56 |
-
fig_param = make_parameterplot(estim, truth)
|
57 |
-
|
58 |
-
return fig_data, fig_param
|
59 |
-
|
60 |
-
def make_dataplot(x: np.ndarray):
|
61 |
plt.close()
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
return
|
78 |
|
79 |
-
def load_numpy(file_obj) -> None | np.ndarray:
|
80 |
-
if file_obj is None:
|
81 |
-
# no file given
|
82 |
-
return None
|
83 |
-
|
84 |
-
file = file_obj.name
|
85 |
-
if not(os.path.splitext(file)[1] in [".npy", ".npz"]):
|
86 |
-
# no numpy file
|
87 |
-
return None
|
88 |
-
|
89 |
-
data = np.load(file)
|
90 |
-
if len(data.shape) != 3:
|
91 |
-
# not in proper shape
|
92 |
-
return None
|
93 |
-
|
94 |
-
return data
|
95 |
-
|
96 |
-
def process_user_input(file_obj):
|
97 |
-
data = load_numpy(file_obj)
|
98 |
-
if data is None:
|
99 |
-
return None
|
100 |
-
|
101 |
-
return gr.update(minimum=1, step=1, maximum=len(data), visible=True, value=1)
|
102 |
-
|
103 |
-
def make_user_plot(file_obj, idx: int):
|
104 |
-
idx -= 1
|
105 |
-
data = load_numpy(file_obj)
|
106 |
-
|
107 |
-
estim = RUNNER.fit(data[idx][None,])
|
108 |
-
bg_data = np.rot90(10*np.log10(np.abs(np.fft.fftn(data[idx], norm="ortho"))), k=-1)
|
109 |
-
fig_estim = make_parameterplot(estim=estim[0], bg=bg_data, extent=[0,1,0,1], cmap="viridis")
|
110 |
-
|
111 |
-
return fig_estim
|
112 |
-
|
113 |
|
114 |
def demo():
|
|
|
115 |
with gr.Blocks() as demo:
|
116 |
gr.Markdown(
|
117 |
TEXTS.introduction
|
118 |
)
|
119 |
|
120 |
-
with gr.Column():
|
121 |
-
snr = gr.Radio(choices=["0", "10", "20", "30"], type="index", value="0", label="SNR [dB]")
|
122 |
-
|
123 |
with gr.Row():
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
with gr.Row():
|
128 |
slider = gr.Slider(1, N, 1, label="Sample Index")
|
129 |
|
130 |
# update callbacks
|
131 |
-
slider.change(make_plots, [
|
132 |
-
snr.change(make_plots, [snr, slider], [data, result])
|
133 |
-
|
134 |
-
with gr.Column():
|
135 |
-
gr.Markdown(
|
136 |
-
TEXTS.try_your_own
|
137 |
-
)
|
138 |
-
|
139 |
-
with gr.Row():
|
140 |
-
with gr.Column():
|
141 |
-
user_file = gr.File(file_count="single", type="file", interactive=True)
|
142 |
-
run_btn = gr.Button("Run Inference")
|
143 |
-
|
144 |
-
user_plot = gr.Plot(label="Results")
|
145 |
-
|
146 |
-
with gr.Column():
|
147 |
-
user_slider = gr.Slider(visible=False, label="Sample Index")
|
148 |
-
|
149 |
-
run_btn.click(process_user_input, [user_file], [user_slider], show_progress=True)
|
150 |
-
user_slider.change(make_user_plot, [user_file, user_slider], [user_plot])
|
151 |
|
152 |
gr.Markdown(
|
153 |
TEXTS.acknowledgements
|
@@ -162,7 +116,7 @@ def demo():
|
|
162 |
def main():
|
163 |
for dd, snr in enumerate(SNRS.values()):
|
164 |
DATA[dd], TRUTH[dd], ESTIM[dd] = RUNNER.run(snr=snr)
|
165 |
-
|
166 |
demo()
|
167 |
|
168 |
|
|
|
10 |
import matplotlib
|
11 |
import matplotlib.pyplot as plt
|
12 |
from huggingface_hub import hf_hub_download
|
13 |
+
from colormaps import tol_cmap
|
14 |
|
15 |
matplotlib.use("Agg")
|
16 |
logger = logging.basicConfig(level=logging.ERROR)
|
|
|
49 |
return
|
50 |
|
51 |
|
52 |
+
def make_plots(idx: int):
|
53 |
idx -= 1
|
54 |
+
figs = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
plt.close()
|
56 |
+
for snr in range(4):
|
57 |
+
data, truth, estim = DATA[snr][idx], TRUTH[snr][idx], ESTIM[snr][idx]
|
58 |
+
x = np.fft.fftn(data, s=[4*x for x in DATA_SHAPE])
|
59 |
+
x /= np.linalg.norm(x, axis=(0,1))
|
60 |
+
x = np.rot90(10*np.log10(np.abs(x)**2), k=-1)
|
61 |
+
|
62 |
+
fig, ax = plt.subplots(1,2, gridspec_kw={"width_ratios": [10,0.5]})
|
63 |
+
ax[0].scatter(truth[0, :], truth[1, :], marker="o", facecolors="none", edgecolors="#000000", s=200, linewidth=2, label="groundtruth")
|
64 |
+
ax[0].scatter(estim[0, :], estim[1, :], marker="o", facecolors="none", edgecolors="#0077bb", s=200, linewidth=2, label="estimate")
|
65 |
+
cm = ax[0].imshow(x, extent=[0,1,0,1], cmap=tol_cmap("YlOrBr"), vmin=-80, vmax=0)
|
66 |
+
ax[0].set_xlim(0,1)
|
67 |
+
ax[0].set_ylim(0,1)
|
68 |
+
ax[0].set_xlabel("Norm. Delay")
|
69 |
+
ax[0].set_ylabel("Norm. Doppler")
|
70 |
+
ax[0].legend(
|
71 |
+
loc="upper center",
|
72 |
+
bbox_to_anchor=(0.5, 1.1),
|
73 |
+
fancybox=True,
|
74 |
+
shadow=True,
|
75 |
+
ncol=5,
|
76 |
+
)
|
77 |
+
fig.colorbar(cm, cax=ax[1], orientation='vertical', label="Magnitude [dB]", pad=-0.5)
|
78 |
+
fig.tight_layout()
|
79 |
+
figs.append(fig)
|
80 |
|
81 |
+
return figs
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
def demo():
|
85 |
+
fig_0, fig_10, fig_20, fig_30 = make_plots(0)
|
86 |
with gr.Blocks() as demo:
|
87 |
gr.Markdown(
|
88 |
TEXTS.introduction
|
89 |
)
|
90 |
|
|
|
|
|
|
|
91 |
with gr.Row():
|
92 |
+
with gr.Column():
|
93 |
+
result_0 = gr.Plot(value=fig_0, label="SNR 0 dB")
|
94 |
+
result_20 = gr.Plot(value=fig_10, label="SNR 20 dB")
|
95 |
+
|
96 |
+
with gr.Column():
|
97 |
+
result_10 = gr.Plot(value=fig_20, label="SNR 10 dB")
|
98 |
+
result_30 = gr.Plot(value=fig_30, label="SNR 30 dB")
|
99 |
|
100 |
with gr.Row():
|
101 |
slider = gr.Slider(1, N, 1, label="Sample Index")
|
102 |
|
103 |
# update callbacks
|
104 |
+
slider.change(make_plots, [slider], [result_0, result_10, result_20, result_30])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
gr.Markdown(
|
107 |
TEXTS.acknowledgements
|
|
|
116 |
def main():
|
117 |
for dd, snr in enumerate(SNRS.values()):
|
118 |
DATA[dd], TRUTH[dd], ESTIM[dd] = RUNNER.run(snr=snr)
|
119 |
+
|
120 |
demo()
|
121 |
|
122 |
|
colormaps.py
ADDED
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Definition of colour schemes for lines and maps that also work for colour-blind
|
3 |
+
people. See https://personal.sron.nl/~pault/ for background information and
|
4 |
+
best usage of the schemes.
|
5 |
+
|
6 |
+
Copyright (c) 2022, Paul Tol
|
7 |
+
All rights reserved.
|
8 |
+
|
9 |
+
License: Standard 3-clause BSD
|
10 |
+
Reference: https://personal.sron.nl/~pault
|
11 |
+
"""
|
12 |
+
import numpy as np
|
13 |
+
from matplotlib.colors import LinearSegmentedColormap, to_rgba_array
|
14 |
+
|
15 |
+
__version__ = "2022.10"
|
16 |
+
|
17 |
+
|
18 |
+
def discretemap(colormap, hexclrs):
|
19 |
+
"""
|
20 |
+
Produce a colormap from a list of discrete colors without interpolation.
|
21 |
+
"""
|
22 |
+
clrs = to_rgba_array(hexclrs)
|
23 |
+
clrs = np.vstack([clrs[0], clrs, clrs[-1]])
|
24 |
+
cdict = {}
|
25 |
+
for ki, key in enumerate(('red','green','blue')):
|
26 |
+
cdict[key] = [ (i/(len(clrs)-2.), clrs[i, ki], clrs[i+1, ki]) for i in range(len(clrs)-1) ]
|
27 |
+
return LinearSegmentedColormap(colormap, cdict)
|
28 |
+
|
29 |
+
|
30 |
+
class TOLcmaps(object):
|
31 |
+
"""
|
32 |
+
Class TOLcmaps definition.
|
33 |
+
"""
|
34 |
+
def __init__(self):
|
35 |
+
"""
|
36 |
+
"""
|
37 |
+
self.cmap = None
|
38 |
+
self.cname = None
|
39 |
+
self.namelist = (
|
40 |
+
'sunset_discrete', 'sunset', 'nightfall_discrete', 'nightfall',
|
41 |
+
'BuRd_discrete', 'BuRd', 'PRGn_discrete', 'PRGn',
|
42 |
+
'YlOrBr_discrete', 'YlOrBr', 'WhOrBr', 'iridescent',
|
43 |
+
'rainbow_PuRd', 'rainbow_PuBr', 'rainbow_WhRd', 'rainbow_WhBr',
|
44 |
+
'rainbow_discrete')
|
45 |
+
|
46 |
+
self.funcdict = dict(
|
47 |
+
zip(self.namelist,
|
48 |
+
(self.__sunset_discrete, self.__sunset,
|
49 |
+
self.__nightfall_discrete, self.__nightfall,
|
50 |
+
self.__BuRd_discrete, self.__BuRd, self.__PRGn_discrete,
|
51 |
+
self.__PRGn, self.__YlOrBr_discrete, self.__YlOrBr,
|
52 |
+
self.__WhOrBr, self.__iridescent, self.__rainbow_PuRd,
|
53 |
+
self.__rainbow_PuBr, self.__rainbow_WhRd, self.__rainbow_WhBr,
|
54 |
+
self.__rainbow_discrete)))
|
55 |
+
|
56 |
+
def __sunset_discrete(self):
|
57 |
+
"""
|
58 |
+
Define colormap 'sunset_discrete'.
|
59 |
+
"""
|
60 |
+
clrs = ['#364B9A', '#4A7BB7', '#6EA6CD', '#98CAE1', '#C2E4EF',
|
61 |
+
'#EAECCC', '#FEDA8B', '#FDB366', '#F67E4B', '#DD3D2D',
|
62 |
+
'#A50026']
|
63 |
+
self.cmap = discretemap(self.cname, clrs)
|
64 |
+
self.cmap.set_bad('#FFFFFF')
|
65 |
+
|
66 |
+
def __sunset(self):
|
67 |
+
"""
|
68 |
+
Define colormap 'sunset'.
|
69 |
+
"""
|
70 |
+
clrs = ['#364B9A', '#4A7BB7', '#6EA6CD', '#98CAE1', '#C2E4EF',
|
71 |
+
'#EAECCC', '#FEDA8B', '#FDB366', '#F67E4B', '#DD3D2D',
|
72 |
+
'#A50026']
|
73 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
74 |
+
self.cmap.set_bad('#FFFFFF')
|
75 |
+
|
76 |
+
def __nightfall_discrete(self):
|
77 |
+
"""
|
78 |
+
Define colormap 'nighfall_discrete'.
|
79 |
+
"""
|
80 |
+
clrs = ['#125A56', '#238F9D', '#60BCE9', '#C6DBED', '#ECEADA',
|
81 |
+
'#F9D576', '#FD9A44', '#E94C1F', '#A01813']
|
82 |
+
self.cmap = discretemap(self.cname, clrs)
|
83 |
+
self.cmap.set_bad('#FFFFFF')
|
84 |
+
|
85 |
+
def __nightfall(self):
|
86 |
+
"""
|
87 |
+
Define colormap 'nightfall'.
|
88 |
+
"""
|
89 |
+
clrs = ['#125A56', '#00767B', '#238F9D', '#42A7C6', '#60BCE9',
|
90 |
+
'#9DCCEF', '#C6DBED', '#DEE6E7', '#ECEADA', '#F0E6B2',
|
91 |
+
'#F9D576', '#FFB954', '#FD9A44', '#F57634', '#E94C1F',
|
92 |
+
'#D11807', '#A01813']
|
93 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
94 |
+
self.cmap.set_bad('#FFFFFF')
|
95 |
+
|
96 |
+
def __BuRd_discrete(self):
|
97 |
+
"""
|
98 |
+
Define colormap 'BuRd_discrete'.
|
99 |
+
"""
|
100 |
+
clrs = ['#2166AC', '#4393C3', '#92C5DE', '#D1E5F0', '#F7F7F7',
|
101 |
+
'#FDDBC7', '#F4A582', '#D6604D', '#B2182B']
|
102 |
+
self.cmap = discretemap(self.cname, clrs)
|
103 |
+
self.cmap.set_bad('#FFEE99')
|
104 |
+
|
105 |
+
def __BuRd(self):
|
106 |
+
"""
|
107 |
+
Define colormap 'BuRd'.
|
108 |
+
"""
|
109 |
+
clrs = ['#2166AC', '#4393C3', '#92C5DE', '#D1E5F0', '#F7F7F7',
|
110 |
+
'#FDDBC7', '#F4A582', '#D6604D', '#B2182B']
|
111 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
112 |
+
self.cmap.set_bad('#FFEE99')
|
113 |
+
|
114 |
+
def __PRGn_discrete(self):
|
115 |
+
"""
|
116 |
+
Define colormap 'PRGn_discrete'.
|
117 |
+
"""
|
118 |
+
clrs = ['#762A83', '#9970AB', '#C2A5CF', '#E7D4E8', '#F7F7F7',
|
119 |
+
'#D9F0D3', '#ACD39E', '#5AAE61', '#1B7837']
|
120 |
+
self.cmap = discretemap(self.cname, clrs)
|
121 |
+
self.cmap.set_bad('#FFEE99')
|
122 |
+
|
123 |
+
def __PRGn(self):
|
124 |
+
"""
|
125 |
+
Define colormap 'PRGn'.
|
126 |
+
"""
|
127 |
+
clrs = ['#762A83', '#9970AB', '#C2A5CF', '#E7D4E8', '#F7F7F7',
|
128 |
+
'#D9F0D3', '#ACD39E', '#5AAE61', '#1B7837']
|
129 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
130 |
+
self.cmap.set_bad('#FFEE99')
|
131 |
+
|
132 |
+
def __YlOrBr_discrete(self):
|
133 |
+
"""
|
134 |
+
Define colormap 'YlOrBr_discrete'.
|
135 |
+
"""
|
136 |
+
clrs = ['#FFFFE5', '#FFF7BC', '#FEE391', '#FEC44F', '#FB9A29',
|
137 |
+
'#EC7014', '#CC4C02', '#993404', '#662506']
|
138 |
+
self.cmap = discretemap(self.cname, clrs)
|
139 |
+
self.cmap.set_bad('#888888')
|
140 |
+
|
141 |
+
def __YlOrBr(self):
|
142 |
+
"""
|
143 |
+
Define colormap 'YlOrBr'.
|
144 |
+
"""
|
145 |
+
clrs = ['#FFFFE5', '#FFF7BC', '#FEE391', '#FEC44F', '#FB9A29',
|
146 |
+
'#EC7014', '#CC4C02', '#993404', '#662506']
|
147 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
148 |
+
self.cmap.set_bad('#888888')
|
149 |
+
|
150 |
+
def __WhOrBr(self):
|
151 |
+
"""
|
152 |
+
Define colormap 'WhOrBr'.
|
153 |
+
"""
|
154 |
+
clrs = ['#FFFFFF', '#FFF7BC', '#FEE391', '#FEC44F', '#FB9A29',
|
155 |
+
'#EC7014', '#CC4C02', '#993404', '#662506']
|
156 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
157 |
+
self.cmap.set_bad('#888888')
|
158 |
+
|
159 |
+
def __iridescent(self):
|
160 |
+
"""
|
161 |
+
Define colormap 'iridescent'.
|
162 |
+
"""
|
163 |
+
clrs = ['#FEFBE9', '#FCF7D5', '#F5F3C1', '#EAF0B5', '#DDECBF',
|
164 |
+
'#D0E7CA', '#C2E3D2', '#B5DDD8', '#A8D8DC', '#9BD2E1',
|
165 |
+
'#8DCBE4', '#81C4E7', '#7BBCE7', '#7EB2E4', '#88A5DD',
|
166 |
+
'#9398D2', '#9B8AC4', '#9D7DB2', '#9A709E', '#906388',
|
167 |
+
'#805770', '#684957', '#46353A']
|
168 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
169 |
+
self.cmap.set_bad('#999999')
|
170 |
+
|
171 |
+
def __rainbow_PuRd(self):
|
172 |
+
"""
|
173 |
+
Define colormap 'rainbow_PuRd'.
|
174 |
+
"""
|
175 |
+
clrs = ['#6F4C9B', '#6059A9', '#5568B8', '#4E79C5', '#4D8AC6',
|
176 |
+
'#4E96BC', '#549EB3', '#59A5A9', '#60AB9E', '#69B190',
|
177 |
+
'#77B77D', '#8CBC68', '#A6BE54', '#BEBC48', '#D1B541',
|
178 |
+
'#DDAA3C', '#E49C39', '#E78C35', '#E67932', '#E4632D',
|
179 |
+
'#DF4828', '#DA2222']
|
180 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
181 |
+
self.cmap.set_bad('#FFFFFF')
|
182 |
+
|
183 |
+
def __rainbow_PuBr(self):
|
184 |
+
"""
|
185 |
+
Define colormap 'rainbow_PuBr'.
|
186 |
+
"""
|
187 |
+
clrs = ['#6F4C9B', '#6059A9', '#5568B8', '#4E79C5', '#4D8AC6',
|
188 |
+
'#4E96BC', '#549EB3', '#59A5A9', '#60AB9E', '#69B190',
|
189 |
+
'#77B77D', '#8CBC68', '#A6BE54', '#BEBC48', '#D1B541',
|
190 |
+
'#DDAA3C', '#E49C39', '#E78C35', '#E67932', '#E4632D',
|
191 |
+
'#DF4828', '#DA2222', '#B8221E', '#95211B', '#721E17',
|
192 |
+
'#521A13']
|
193 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
194 |
+
self.cmap.set_bad('#FFFFFF')
|
195 |
+
|
196 |
+
def __rainbow_WhRd(self):
|
197 |
+
"""
|
198 |
+
Define colormap 'rainbow_WhRd'.
|
199 |
+
"""
|
200 |
+
clrs = ['#E8ECFB', '#DDD8EF', '#D1C1E1', '#C3A8D1', '#B58FC2',
|
201 |
+
'#A778B4', '#9B62A7', '#8C4E99', '#6F4C9B', '#6059A9',
|
202 |
+
'#5568B8', '#4E79C5', '#4D8AC6', '#4E96BC', '#549EB3',
|
203 |
+
'#59A5A9', '#60AB9E', '#69B190', '#77B77D', '#8CBC68',
|
204 |
+
'#A6BE54', '#BEBC48', '#D1B541', '#DDAA3C', '#E49C39',
|
205 |
+
'#E78C35', '#E67932', '#E4632D', '#DF4828', '#DA2222']
|
206 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
207 |
+
self.cmap.set_bad('#666666')
|
208 |
+
|
209 |
+
def __rainbow_WhBr(self):
|
210 |
+
"""
|
211 |
+
Define colormap 'rainbow_WhBr'.
|
212 |
+
"""
|
213 |
+
clrs = ['#E8ECFB', '#DDD8EF', '#D1C1E1', '#C3A8D1', '#B58FC2',
|
214 |
+
'#A778B4', '#9B62A7', '#8C4E99', '#6F4C9B', '#6059A9',
|
215 |
+
'#5568B8', '#4E79C5', '#4D8AC6', '#4E96BC', '#549EB3',
|
216 |
+
'#59A5A9', '#60AB9E', '#69B190', '#77B77D', '#8CBC68',
|
217 |
+
'#A6BE54', '#BEBC48', '#D1B541', '#DDAA3C', '#E49C39',
|
218 |
+
'#E78C35', '#E67932', '#E4632D', '#DF4828', '#DA2222',
|
219 |
+
'#B8221E', '#95211B', '#721E17', '#521A13']
|
220 |
+
self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
|
221 |
+
self.cmap.set_bad('#666666')
|
222 |
+
|
223 |
+
def __rainbow_discrete(self, lut=None):
|
224 |
+
"""
|
225 |
+
Define colormap 'rainbow_discrete'.
|
226 |
+
"""
|
227 |
+
clrs = ['#E8ECFB', '#D9CCE3', '#D1BBD7', '#CAACCB', '#BA8DB4',
|
228 |
+
'#AE76A3', '#AA6F9E', '#994F88', '#882E72', '#1965B0',
|
229 |
+
'#437DBF', '#5289C7', '#6195CF', '#7BAFDE', '#4EB265',
|
230 |
+
'#90C987', '#CAE0AB', '#F7F056', '#F7CB45', '#F6C141',
|
231 |
+
'#F4A736', '#F1932D', '#EE8026', '#E8601C', '#E65518',
|
232 |
+
'#DC050C', '#A5170E', '#72190E', '#42150A']
|
233 |
+
indexes = [[9], [9, 25], [9, 17, 25], [9, 14, 17, 25], [9, 13, 14, 17,
|
234 |
+
25], [9, 13, 14, 16, 17, 25], [8, 9, 13, 14, 16, 17, 25], [8,
|
235 |
+
9, 13, 14, 16, 17, 22, 25], [8, 9, 13, 14, 16, 17, 22, 25, 27],
|
236 |
+
[8, 9, 13, 14, 16, 17, 20, 23, 25, 27], [8, 9, 11, 13, 14, 16,
|
237 |
+
17, 20, 23, 25, 27], [2, 5, 8, 9, 11, 13, 14, 16, 17, 20, 23,
|
238 |
+
25], [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 20, 23, 25], [2, 5,
|
239 |
+
8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25], [2, 5, 8, 9, 11,
|
240 |
+
13, 14, 15, 16, 17, 19, 21, 23, 25, 27], [2, 4, 6, 8, 9, 11,
|
241 |
+
13, 14, 15, 16, 17, 19, 21, 23, 25, 27], [2, 4, 6, 7, 8, 9, 11,
|
242 |
+
13, 14, 15, 16, 17, 19, 21, 23, 25, 27], [2, 4, 6, 7, 8, 9, 11,
|
243 |
+
13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27], [1, 3, 4, 6, 7, 8,
|
244 |
+
9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27], [1, 3, 4,
|
245 |
+
6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26,
|
246 |
+
27], [1, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 20,
|
247 |
+
22, 24, 25, 26, 27], [1, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15,
|
248 |
+
16, 17, 18, 20, 22, 24, 25, 26, 27, 28], [0, 1, 3, 4, 6, 7, 8,
|
249 |
+
9, 10, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 25, 26, 27, 28]]
|
250 |
+
if lut is None or lut < 1 or lut > 23:
|
251 |
+
lut = 22
|
252 |
+
self.cmap = discretemap(self.cname, [ clrs[i] for i in indexes[lut-1] ])
|
253 |
+
if lut == 23:
|
254 |
+
self.cmap.set_bad('#777777')
|
255 |
+
else:
|
256 |
+
self.cmap.set_bad('#FFFFFF')
|
257 |
+
|
258 |
+
def show(self):
|
259 |
+
"""
|
260 |
+
List names of defined colormaps.
|
261 |
+
"""
|
262 |
+
print(' '.join(repr(n) for n in self.namelist))
|
263 |
+
|
264 |
+
def get(self, cname='rainbow_PuRd', lut=None):
|
265 |
+
"""
|
266 |
+
Return requested colormap, default is 'rainbow_PuRd'.
|
267 |
+
"""
|
268 |
+
self.cname = cname
|
269 |
+
if cname == 'rainbow_discrete':
|
270 |
+
self.__rainbow_discrete(lut)
|
271 |
+
else:
|
272 |
+
self.funcdict[cname]()
|
273 |
+
return self.cmap
|
274 |
+
|
275 |
+
|
276 |
+
def tol_cmap(colormap=None, lut=None):
|
277 |
+
"""
|
278 |
+
Continuous and discrete color sets for ordered data.
|
279 |
+
|
280 |
+
Return a matplotlib colormap.
|
281 |
+
Parameter lut is ignored for all colormaps except 'rainbow_discrete'.
|
282 |
+
"""
|
283 |
+
obj = TOLcmaps()
|
284 |
+
if colormap is None:
|
285 |
+
return obj.namelist
|
286 |
+
if colormap not in obj.namelist:
|
287 |
+
colormap = 'rainbow_PuRd'
|
288 |
+
print('*** Warning: requested colormap not defined,',
|
289 |
+
'known colormaps are {}.'.format(obj.namelist),
|
290 |
+
'Using {}.'.format(colormap))
|
291 |
+
return obj.get(colormap, lut)
|
292 |
+
|
293 |
+
|
294 |
+
def tol_cset(colorset=None):
|
295 |
+
"""
|
296 |
+
Discrete color sets for qualitative data.
|
297 |
+
|
298 |
+
Define a namedtuple instance with the colors.
|
299 |
+
Examples for: cset = tol_cset(<scheme>)
|
300 |
+
- cset.red and cset[1] give the same color (in default 'bright' colorset)
|
301 |
+
- cset._fields gives a tuple with all color names
|
302 |
+
- list(cset) gives a list with all colors
|
303 |
+
"""
|
304 |
+
from collections import namedtuple
|
305 |
+
|
306 |
+
namelist = ('bright', 'high-contrast', 'vibrant', 'muted', 'medium-contrast', 'light')
|
307 |
+
if colorset is None:
|
308 |
+
return namelist
|
309 |
+
if colorset not in namelist:
|
310 |
+
colorset = 'bright'
|
311 |
+
print('*** Warning: requested colorset not defined,',
|
312 |
+
'known colorsets are {}.'.format(namelist),
|
313 |
+
'Using {}.'.format(colorset))
|
314 |
+
|
315 |
+
if colorset == 'bright':
|
316 |
+
cset = namedtuple('Bcset',
|
317 |
+
'blue red green yellow cyan purple grey black')
|
318 |
+
return cset('#4477AA', '#EE6677', '#228833', '#CCBB44', '#66CCEE',
|
319 |
+
'#AA3377', '#BBBBBB', '#000000')
|
320 |
+
|
321 |
+
if colorset == 'high-contrast':
|
322 |
+
cset = namedtuple('Hcset',
|
323 |
+
'blue yellow red black')
|
324 |
+
return cset('#004488', '#DDAA33', '#BB5566', '#000000')
|
325 |
+
|
326 |
+
if colorset == 'vibrant':
|
327 |
+
cset = namedtuple('Vcset',
|
328 |
+
'orange blue cyan magenta red teal grey black')
|
329 |
+
return cset('#EE7733', '#0077BB', '#33BBEE', '#EE3377', '#CC3311',
|
330 |
+
'#009988', '#BBBBBB', '#000000')
|
331 |
+
|
332 |
+
if colorset == 'muted':
|
333 |
+
cset = namedtuple('Mcset',
|
334 |
+
'rose indigo sand green cyan wine teal olive purple pale_grey black')
|
335 |
+
return cset('#CC6677', '#332288', '#DDCC77', '#117733', '#88CCEE',
|
336 |
+
'#882255', '#44AA99', '#999933', '#AA4499', '#DDDDDD',
|
337 |
+
'#000000')
|
338 |
+
|
339 |
+
if colorset == 'medium-contrast':
|
340 |
+
cset = namedtuple('Mcset',
|
341 |
+
'light_blue dark_blue light_yellow dark_red dark_yellow light_red black')
|
342 |
+
return cset('#6699CC', '#004488', '#EECC66', '#994455', '#997700',
|
343 |
+
'#EE99AA', '#000000')
|
344 |
+
|
345 |
+
if colorset == 'light':
|
346 |
+
cset = namedtuple('Lcset',
|
347 |
+
'light_blue orange light_yellow pink light_cyan mint pear olive pale_grey black')
|
348 |
+
return cset('#77AADD', '#EE8866', '#EEDD88', '#FFAABB', '#99DDFF',
|
349 |
+
'#44BB99', '#BBCC33', '#AAAA00', '#DDDDDD', '#000000')
|
helper.py
CHANGED
@@ -3,10 +3,12 @@ from deepest.modules import Parameter2dNet
|
|
3 |
from deepest.datasets import InferenceDelayDataset
|
4 |
from deepest.metrics import match_components
|
5 |
import numpy as np
|
|
|
6 |
|
7 |
class Runner:
|
8 |
def __init__(self, model: str, dataset: str, bs: int, num_worker: int):
|
9 |
-
self.
|
|
|
10 |
self.dataset_config = self.module.get_datasetconfig()
|
11 |
self.dataset = InferenceDelayDataset(path=dataset, **self.dataset_config)
|
12 |
self.bs = bs
|
@@ -45,7 +47,7 @@ class Runner:
|
|
45 |
|
46 |
data[idx_range] = x.cpu().numpy()
|
47 |
truth[idx_range] = z.cpu().numpy()
|
48 |
-
estim[idx_range] = self.module.fit(x)[:, :2, :]
|
49 |
|
50 |
estim, truth = match_components(estim, truth)
|
51 |
|
@@ -56,4 +58,5 @@ class Runner:
|
|
56 |
return x[:, :2, :]
|
57 |
|
58 |
def __len__(self):
|
59 |
-
return len(self.dataset)
|
|
|
|
3 |
from deepest.datasets import InferenceDelayDataset
|
4 |
from deepest.metrics import match_components
|
5 |
import numpy as np
|
6 |
+
import torch
|
7 |
|
8 |
class Runner:
|
9 |
def __init__(self, model: str, dataset: str, bs: int, num_worker: int):
|
10 |
+
self.device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
11 |
+
self.module = Parameter2dNet.from_file(f"{model}").to(self.device)
|
12 |
self.dataset_config = self.module.get_datasetconfig()
|
13 |
self.dataset = InferenceDelayDataset(path=dataset, **self.dataset_config)
|
14 |
self.bs = bs
|
|
|
47 |
|
48 |
data[idx_range] = x.cpu().numpy()
|
49 |
truth[idx_range] = z.cpu().numpy()
|
50 |
+
estim[idx_range] = self.module.fit(x.to(self.device))[:, :2, :]
|
51 |
|
52 |
estim, truth = match_components(estim, truth)
|
53 |
|
|
|
58 |
return x[:, :2, :]
|
59 |
|
60 |
def __len__(self):
|
61 |
+
return len(self.dataset)
|
62 |
+
|
requirements.txt
CHANGED
@@ -12,4 +12,5 @@ tqdm
|
|
12 |
joblib
|
13 |
matplotlib
|
14 |
huggingface-hub
|
15 |
-
gradio
|
|
|
|
12 |
joblib
|
13 |
matplotlib
|
14 |
huggingface-hub
|
15 |
+
gradio==3.9
|
16 |
+
httpx==0.24.1
|
texts.toml
CHANGED
@@ -1,40 +1,28 @@
|
|
1 |
introduction = """
|
2 |
-
#
|
3 |
-
|
4 |
The corresponding paper can be found on [arxiv](https://arxiv.org/abs/2211.04846).
|
5 |
|
6 |
-
This applet lets you explore
|
7 |
-
|
8 |
-
"""
|
9 |
-
|
10 |
-
try_your_own = """
|
11 |
-
## Try with your own data.
|
12 |
-
Good news everyone! If you want to try `deepest` with your own data, here is your chance.
|
13 |
-
But keep in mind that slight deviations from the training-data distribution might throw off `deepest`.
|
14 |
-
Its a Neural Network after all.
|
15 |
-
You can upload a `numpy` file (both `*.npy` and `*.npz` work) with your test data.
|
16 |
-
Ensure the data meets the requirements, such that you get good results.
|
17 |
-
|
18 |
-
### Requirements
|
19 |
-
- complex-valued baseband data for the time-variant Channel transfer function $H(f,t)$ (e.g. from a channel-sounding campaign)
|
20 |
-
- array shape must be `batch_size x f_bins x t_bins`
|
21 |
-
- ideally `f_bins`=64 and `t_bins`=64, otherwise the data will be downsampled by the 2D-DFT, which might not be ideal in all scenarios.
|
22 |
-
|
23 |
-
**Important** This demo runs on Huggingface. You are responsible for the data you upload. Do not upload any data that is confidential or unsuitable in this context.
|
24 |
"""
|
25 |
|
26 |
acknowledgements = """
|
27 |
## Acknowledgements
|
28 |
-
The authors acknowledge the financial support by the Federal Ministry of Education and Research of Germany in the project “Open6GHub” (grant number: 16KISK015).
|
29 |
|
30 |
-
|
31 |
"""
|
32 |
|
33 |
contact = """
|
34 |
## Contact
|
35 |
-
If you have
|
36 |
You can either
|
37 |
- write a me an email to [[email protected]](mailto:[email protected])
|
38 |
- or start a new discussion in the [Community Tab](https://huggingface.co/spaces/EMS-TU-Ilmenau/deepest-demo/discussions)
|
39 |
|
|
|
|
|
|
|
|
|
40 |
"""
|
|
|
1 |
introduction = """
|
2 |
+
# Grid-free Harmonic Retrieval and Model Order Selection using Convolutional Neural Networks
|
3 |
+
This app is a demo for our paper "Grid-free Harmonic Retrieval and Model Order Selection using Convolutional Neural Networks".
|
4 |
The corresponding paper can be found on [arxiv](https://arxiv.org/abs/2211.04846).
|
5 |
|
6 |
+
This applet lets you explore our CNN with data from the validationset by using the **slider below the plots** to explore the data and results for different SNRs: 0, 10, 20, and 30 dB.
|
7 |
+
The groundtruth parameters are at the center of the black circle and the estimates are at the center of the blue circles, while the magnitude is displayed in the background (DFT-upsampled 4x).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
"""
|
9 |
|
10 |
acknowledgements = """
|
11 |
## Acknowledgements
|
12 |
+
The authors acknowledge the financial support by the Federal Ministry of Education and Research of Germany in the project “Open6GHub” (grant number: 16KISK015), “KOMSENS-6G” (grant number: 16KISK125), and DFG project HoPaDyn with Grant-No. TH 494/30-1.
|
13 |
|
14 |
+
Furthermore, the authors give special thanks to Henning Schwanbeck (HPC team leader) of the TU Ilmenau Computer Center for his valuable support.
|
15 |
"""
|
16 |
|
17 |
contact = """
|
18 |
## Contact
|
19 |
+
If you have questions or encounter any issues in the use of this applet, please let me know.
|
20 |
You can either
|
21 |
- write a me an email to [[email protected]](mailto:[email protected])
|
22 |
- or start a new discussion in the [Community Tab](https://huggingface.co/spaces/EMS-TU-Ilmenau/deepest-demo/discussions)
|
23 |
|
24 |
+
|
25 |
+
## Links
|
26 |
+
- Paper on Arxiv [https://arxiv.org/abs/2211.04846](https://arxiv.org/abs/2211.04846)
|
27 |
+
- Blog Article [https://www.steffenschieler.xyz/blog/2024/intro/](https://www.steffenschieler.xyz/blog/2024/intro/)
|
28 |
"""
|