-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
66 lines (44 loc) · 1.93 KB
/
debug.py
File metadata and controls
66 lines (44 loc) · 1.93 KB
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
import os
import numpy as np
import matplotlib.pyplot as plt
PLOTS_PATH = "plots"
def display_images(images, num_frames, filename=None, title=None, nrows=4, show=False, in_db=True):
if not os.path.exists(PLOTS_PATH):
os.makedirs(PLOTS_PATH)
filename = os.path.join(PLOTS_PATH, filename) if filename else None
ncols = int(np.ceil(num_frames / nrows))
fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(16, 8))
axes = np.atleast_1d(axes).flatten()
axes = axes.flatten()
if title:
fig.suptitle(title, fontsize=16)
for i in range(num_frames):
if in_db:
img = 20 * np.log10(np.abs(images[i]) + 1e-8)
else:
img = images[i]
# masked_img = np.ma.masked_where(img == 0, img)
im = axes[i].imshow(img, aspect='auto', origin='lower', cmap='viridis')
axes[i].set_title(f"Image {i+1}")
fig.colorbar(im, ax=axes[i])
plt.tight_layout()
n_empty_plots = nrows * ncols - num_frames
for j in range(n_empty_plots):
fig.delaxes(axes[-(j+1)])
if filename:
plt.savefig(filename)
if show:
plt.show()
# def compute_true_mask(Xq, N, F0, ):
# absql = np.abs(Xq[F0, :, 0, :])
# absNl = np.abs(N[F0, :, 0])
# Tmask = np.argmax(np.concatenate((absql, Gn * absNl[:,:,None]), axis=2),axis=-1)
# Tmask[20 * np.log10(np.abs(Xt[:, :, 0])) <= -10] = Q
# Tmask[:, np.sum(Tmask == Q, axis=0) / (NFFT // 2 + 1) > 0.85] = Q
# def extract_feature_vector(stft_images):
# # Assuming stft_images is a 3D numpy array with shape (num_frames, num_bins, num_channels)
# num_frames, num_bins, num_channels = stft_images.shape
# feature_vector = np.zeros((num_bins, num_channels, num_frames), dtype=np.float64)
# for i in range(num_frames):
# feature_vector[:, :, i] = stft_images[i]
# return feature_vector