|
|
|
|
@ -10,7 +10,7 @@ import os
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _render_plot(values, figsize=(16, 16), dpi=16):
|
|
|
|
|
def _render_signal_channel(values, figsize=(16, 16), dpi=16, resize=(256, 256)):
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
fig = plt.figure(figsize=figsize)
|
|
|
|
|
@ -30,6 +30,34 @@ def _render_plot(values, figsize=(16, 16), dpi=16):
|
|
|
|
|
if img is None:
|
|
|
|
|
raise RuntimeError("failed to decode plot image")
|
|
|
|
|
|
|
|
|
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
|
|
|
|
if resize is not None:
|
|
|
|
|
img = cv2.resize(img, resize)
|
|
|
|
|
|
|
|
|
|
plt.clf()
|
|
|
|
|
plt.cla()
|
|
|
|
|
plt.close()
|
|
|
|
|
plt.close(fig)
|
|
|
|
|
|
|
|
|
|
return img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _render_training_png(image):
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
fig = plt.figure()
|
|
|
|
|
plt.imshow(image)
|
|
|
|
|
|
|
|
|
|
buf = io.BytesIO()
|
|
|
|
|
fig.savefig(buf, format="png")
|
|
|
|
|
buf.seek(0)
|
|
|
|
|
img_arr = np.frombuffer(buf.getvalue(), dtype=np.uint8)
|
|
|
|
|
buf.close()
|
|
|
|
|
|
|
|
|
|
img = cv2.imdecode(img_arr, 1)
|
|
|
|
|
if img is None:
|
|
|
|
|
raise RuntimeError("failed to decode training-style image")
|
|
|
|
|
|
|
|
|
|
plt.clf()
|
|
|
|
|
plt.cla()
|
|
|
|
|
plt.close()
|
|
|
|
|
@ -85,8 +113,8 @@ def pre_func_ensemble(data=None, src="", ind_inference=0):
|
|
|
|
|
imag = np.asarray(data[1], dtype=np.float32)
|
|
|
|
|
signal = real + 1j * imag
|
|
|
|
|
|
|
|
|
|
img_real = _render_plot(signal.real)
|
|
|
|
|
img_mag = _render_plot(np.abs(signal))
|
|
|
|
|
img_real = _render_training_png(_render_signal_channel(signal.real))
|
|
|
|
|
img_mag = _render_training_png(_render_signal_channel(np.abs(signal)))
|
|
|
|
|
|
|
|
|
|
cv2.destroyAllWindows()
|
|
|
|
|
gc.collect()
|
|
|
|
|
|