Spaces:
Sleeping
Sleeping
Delete plotting_utils.py
Browse files- plotting_utils.py +0 -83
plotting_utils.py
DELETED
@@ -1,83 +0,0 @@
|
|
1 |
-
import matplotlib
|
2 |
-
matplotlib.use("Agg")
|
3 |
-
import matplotlib.pylab as plt
|
4 |
-
import numpy as np
|
5 |
-
|
6 |
-
|
7 |
-
def save_figure_to_numpy(fig):
|
8 |
-
# save it to a numpy array.
|
9 |
-
data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
|
10 |
-
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
|
11 |
-
return data
|
12 |
-
|
13 |
-
|
14 |
-
def plot_alignment_to_numpy(alignment, info=None):
|
15 |
-
fig, ax = plt.subplots(figsize=(6, 4))
|
16 |
-
im = ax.imshow(alignment, aspect='auto', origin='lower',
|
17 |
-
interpolation='none')
|
18 |
-
fig.colorbar(im, ax=ax)
|
19 |
-
xlabel = 'Decoder timestep'
|
20 |
-
if info is not None:
|
21 |
-
xlabel += '\n\n' + info
|
22 |
-
plt.xlabel(xlabel)
|
23 |
-
plt.ylabel('Encoder timestep')
|
24 |
-
plt.tight_layout()
|
25 |
-
|
26 |
-
fig.canvas.draw()
|
27 |
-
data = save_figure_to_numpy(fig)
|
28 |
-
plt.close()
|
29 |
-
data = data.transpose(2, 0, 1)
|
30 |
-
return data
|
31 |
-
|
32 |
-
|
33 |
-
def plot_gst_scores_to_numpy(gst_scores, info=None):
|
34 |
-
fig, ax = plt.subplots(figsize=(6, 4))
|
35 |
-
im = ax.imshow(gst_scores, aspect='auto', origin='lower',
|
36 |
-
interpolation='none')
|
37 |
-
fig.colorbar(im, ax=ax)
|
38 |
-
xlabel = 'Validation samples'
|
39 |
-
if info is not None:
|
40 |
-
xlabel += '\n\n' + info
|
41 |
-
plt.xlabel(xlabel)
|
42 |
-
plt.ylabel('Style Tokens')
|
43 |
-
plt.tight_layout()
|
44 |
-
|
45 |
-
fig.canvas.draw()
|
46 |
-
data = save_figure_to_numpy(fig)
|
47 |
-
plt.close()
|
48 |
-
data = data.transpose(2, 0, 1)
|
49 |
-
return data
|
50 |
-
|
51 |
-
|
52 |
-
def plot_spectrogram_to_numpy(spectrogram):
|
53 |
-
fig, ax = plt.subplots(figsize=(12, 3))
|
54 |
-
im = ax.imshow(spectrogram, aspect="auto", origin="lower",
|
55 |
-
interpolation='none')
|
56 |
-
plt.colorbar(im, ax=ax)
|
57 |
-
plt.xlabel("Frames")
|
58 |
-
plt.ylabel("Channels")
|
59 |
-
plt.tight_layout()
|
60 |
-
|
61 |
-
fig.canvas.draw()
|
62 |
-
data = save_figure_to_numpy(fig)
|
63 |
-
plt.close()
|
64 |
-
data = data.transpose(2, 0, 1)
|
65 |
-
return data
|
66 |
-
|
67 |
-
|
68 |
-
def plot_gate_outputs_to_numpy(gate_targets, gate_outputs):
|
69 |
-
fig, ax = plt.subplots(figsize=(12, 3))
|
70 |
-
ax.scatter(range(len(gate_targets)), gate_targets, alpha=0.5,
|
71 |
-
color='green', marker='+', s=1, label='target')
|
72 |
-
ax.scatter(range(len(gate_outputs)), gate_outputs, alpha=0.5,
|
73 |
-
color='red', marker='.', s=1, label='predicted')
|
74 |
-
|
75 |
-
plt.xlabel("Frames (Green target, Red predicted)")
|
76 |
-
plt.ylabel("Gate State")
|
77 |
-
plt.tight_layout()
|
78 |
-
|
79 |
-
fig.canvas.draw()
|
80 |
-
data = save_figure_to_numpy(fig)
|
81 |
-
plt.close()
|
82 |
-
data = data.transpose(2, 0, 1)
|
83 |
-
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|