Skip to content

Commit

Permalink
Merge pull request #98 from dlipatov/fix-chunksize
Browse files Browse the repository at this point in the history
Fix chunksize in utils.py when batch is less than ncpu value
  • Loading branch information
dscripka authored Jan 19, 2024
2 parents 17a0f72 + e3f1046 commit dc5a234
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions openwakeword/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ def _get_melspectrogram_batch(self, x, batch_size=128, ncpu=1):
result = self._get_melspectrogram(batch)

elif pool:
chunksize = batch.shape[0]//ncpu if batch.shape[0] >= ncpu else 1
result = np.array(pool.map(self._get_melspectrogram,
batch, chunksize=batch.shape[0]//ncpu))
batch, chunksize=chunksize))

melspecs[i:i+batch_size, :, :] = result.squeeze()

Expand Down Expand Up @@ -330,8 +331,9 @@ def _get_embeddings_batch(self, x, batch_size=128, ncpu=1):
result = self.embedding_model_predict(batch)

elif pool:
chunksize = batch.shape[0]//ncpu if batch.shape[0] >= ncpu else 1
result = np.array(pool.map(self._get_embeddings_from_melspec,
batch, chunksize=batch.shape[0]//ncpu))
batch, chunksize=chunksize))

for j, ndx2 in zip(range(0, result.shape[0], n_frames), ndcs):
embeddings[ndx2, :, :] = result[j:j+n_frames]
Expand Down

0 comments on commit dc5a234

Please sign in to comment.