Skip to content

Commit 7df3f9c

Browse files
committed
Managing to actually use sparse matrices
Now 2x real-time!
1 parent 5c366b7 commit 7df3f9c

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/dump_lpcnet.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,19 @@ def printSparseVector(f, A, name):
6767
A[:,N:2*N] = A[:,N:2*N] - np.diag(np.diag(A[:,N:2*N]))
6868
A[:,2*N:] = A[:,2*N:] - np.diag(np.diag(A[:,2*N:]))
6969
printVector(f, diag, name + '_diag')
70+
idx = np.zeros((0,), dtype='int')
7071
for i in range(3*N//16):
72+
pos = idx.shape[0]
73+
idx = np.append(idx, -1)
74+
nb_nonzero = 0
7175
for j in range(N):
72-
W = np.concatenate([W, A[j, i*16:(i+1)*16]])
76+
if np.sum(np.abs(A[j, i*16:(i+1)*16])) > 1e-10:
77+
nb_nonzero = nb_nonzero + 1
78+
idx = np.append(idx, j)
79+
W = np.concatenate([W, A[j, i*16:(i+1)*16]])
80+
idx[pos] = nb_nonzero
7381
printVector(f, W, name)
74-
idx = np.tile(np.concatenate([np.array([N]), np.arange(N)]), 3*N//16)
82+
#idx = np.tile(np.concatenate([np.array([N]), np.arange(N)]), 3*N//16)
7583
printVector(f, idx, name + '_idx', dtype='int')
7684
return;
7785

src/lpcnet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def on_batch_end(self, batch, logs=None):
5757
pass
5858
else:
5959
#print("constrain");
60-
layer = self.model.get_layer('cu_dnngru_1')
60+
layer = self.model.get_layer('gru_a')
6161
w = layer.get_weights()
6262
p = w[1]
6363
nb = p.shape[1]//p.shape[0]
@@ -72,13 +72,15 @@ def on_batch_end(self, batch, logs=None):
7272
for k in range(nb):
7373
A = p[:, k*N:(k+1)*N]
7474
A = A - np.diag(np.diag(A))
75+
A = np.transpose(A, (1, 0))
7576
L=np.reshape(A, (N, N//16, 16))
7677
S=np.sum(L*L, axis=-1)
7778
SS=np.sort(np.reshape(S, (-1,)))
7879
thresh = SS[round(N*N//16*(1-density))]
7980
mask = (S>=thresh).astype('float32');
8081
mask = np.repeat(mask, 16, axis=1)
8182
mask = np.minimum(1, mask + np.diag(np.ones((N,))))
83+
mask = np.transpose(mask, (1, 0))
8284
p[:, k*N:(k+1)*N] = p[:, k*N:(k+1)*N]*mask
8385
#print(thresh, np.mean(mask))
8486
w[1] = p

src/train_lpcnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
in_data = np.concatenate([in_data, pred], axis=-1)
140140

141141
# dump models to disk as we go
142-
checkpoint = ModelCheckpoint('lpcnet9_384_10_G16_{epoch:02d}.h5')
142+
checkpoint = ModelCheckpoint('lpcnet9b_384_10_G16_{epoch:02d}.h5')
143143

144144
#model.load_weights('wavenet4f2_30.h5')
145145
model.compile(optimizer=Adam(0.001, amsgrad=True, decay=5e-5), loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])

0 commit comments

Comments
 (0)