Skip to content

Commit

Permalink
Fix typing of count.data and possible error due to number of centroid…
Browse files Browse the repository at this point in the history
…s mismatch
  • Loading branch information
flyingleafe committed Aug 10, 2023
1 parent d49f5fe commit 92173d1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pyannote/audio/pipelines/speaker_diarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def apply(
# during counting, we could possibly overcount the number of instantaneous
# speakers due to segmentation errors, so we cap the maximum instantaneous number
# of speakers by the `max_speakers` value
count.data = np.minimum(count.data, max_speakers)
count.data = np.minimum(count.data, max_speakers).astype(np.int8)

# reconstruct discrete diarization from raw hard clusters

Expand Down Expand Up @@ -604,18 +604,21 @@ def apply(
if not return_embeddings:
return diarization

# The number of centroids may be smaller than the number of speakers
# in the annotation. This can happen if the number of active speakers
# obtained from `speaker_count` for some frames is larger than the number
# of clusters obtained from `clustering`. In this case, we append zero embeddings
# for extra speakers
if len(diarization.labels()) > centroids.shape[0]:
centroids = np.pad(centroids, (0, len(diarization.labels()) - centroids.shape[0]))

# re-order centroids so that they match
# the order given by diarization.labels()
inverse_mapping = {label: index for index, label in mapping.items()}
centroids = centroids[
[inverse_mapping[label] for label in diarization.labels()]
]

# FIXME: the number of centroids may be smaller than the number of speakers
# in the annotation. This can happen if the number of active speakers
# obtained from `speaker_count` for some frames is larger than the number
# of clusters obtained from `clustering`. Will be fixed in the future

return diarization, centroids

def get_metric(self) -> GreedyDiarizationErrorRate:
Expand Down

0 comments on commit 92173d1

Please sign in to comment.