From db418ab9f309d6c5cbbbdcc93409992687431861 Mon Sep 17 00:00:00 2001 From: Dmitry Lipatov Date: Sun, 14 Jan 2024 23:31:07 +0300 Subject: [PATCH 1/2] Fix chunksize in utils.py when batch is less than ncpu value --- openwakeword/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openwakeword/utils.py b/openwakeword/utils.py index c032c5a..6572e23 100644 --- a/openwakeword/utils.py +++ b/openwakeword/utils.py @@ -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() @@ -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] From e3f1046ebbfdb78ccbaa21cda0912ab56dc754b2 Mon Sep 17 00:00:00 2001 From: dscripka Date: Thu, 18 Jan 2024 20:16:41 -0500 Subject: [PATCH 2/2] fix flake8 issue --- openwakeword/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openwakeword/utils.py b/openwakeword/utils.py index 6572e23..8da8048 100644 --- a/openwakeword/utils.py +++ b/openwakeword/utils.py @@ -269,7 +269,7 @@ 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 + chunksize = batch.shape[0]//ncpu if batch.shape[0] >= ncpu else 1 result = np.array(pool.map(self._get_melspectrogram, batch, chunksize=chunksize)) @@ -331,7 +331,7 @@ 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 + chunksize = batch.shape[0]//ncpu if batch.shape[0] >= ncpu else 1 result = np.array(pool.map(self._get_embeddings_from_melspec, batch, chunksize=chunksize))