Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pyannote/audio/pipelines/speaker_diarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,14 @@ def iter_waveform_and_mask():
mask_batch = torch.vstack(masks)
# (batch_size, num_frames) torch.Tensor

embedding_batch: np.ndarray = self._embedding(
waveform_batch, masks=mask_batch
)
# remove items from batch which have all zero masks, only compute embeddings for the rest
embedding_batch = np.zeros((mask_batch.shape[0],256), dtype=np.float32)
nonzero_masks = np.where(np.linalg.norm(mask_batch, axis=1) > 0)
if nonzero_masks[0].shape[0] > 0:
embedding_batch_reduced: np.ndarray = self._embedding(
waveform_batch[nonzero_masks], masks=mask_batch[nonzero_masks]
)
embedding_batch[nonzero_masks] = embedding_batch_reduced
# (batch_size, dimension) np.ndarray

embedding_batches.append(embedding_batch)
Expand Down