mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
wip: use hooks in clustering step
This commit is contained in:
1 parent
3f4a22f773
commit
c7581cfa18
2 files changed
+13
-1
No files matched your search
@@ -24,7 +24,7 @@
|
||||
|
||||
import random
|
||||
from enum import Enum
|
||||
from typing import Optional, Tuple
|
||||
from typing import Callable, Optional, Tuple
|
||||
|
||||
import numpy as np
|
||||
from einops import rearrange
|
||||
@@ -209,6 +209,7 @@ class BaseClustering(Pipeline):
|
||||
num_clusters: Optional[int] = None,
|
||||
min_clusters: Optional[int] = None,
|
||||
max_clusters: Optional[int] = None,
|
||||
hook: Optional[Callable] = None,
|
||||
**kwargs,
|
||||
) -> np.ndarray:
|
||||
"""Apply clustering
|
||||
@@ -267,6 +268,7 @@ class BaseClustering(Pipeline):
|
||||
min_clusters=min_clusters,
|
||||
max_clusters=max_clusters,
|
||||
num_clusters=num_clusters,
|
||||
hook=hook,
|
||||
)
|
||||
|
||||
hard_clusters, soft_clusters, centroids = self.assign_embeddings(
|
||||
@@ -326,6 +328,7 @@ class AgglomerativeClustering(BaseClustering):
|
||||
min_clusters: Optional[int] = None,
|
||||
max_clusters: Optional[int] = None,
|
||||
num_clusters: Optional[int] = None,
|
||||
hook: Optional[Callable] = None,
|
||||
):
|
||||
"""
|
||||
|
||||
@@ -374,9 +377,13 @@ class AgglomerativeClustering(BaseClustering):
|
||||
embeddings, method=self.method, metric=self.metric
|
||||
)
|
||||
|
||||
hook("clustering.dendrogram", dendrogram)
|
||||
|
||||
# apply the predefined threshold
|
||||
clusters = fcluster(dendrogram, self.threshold, criterion="distance") - 1
|
||||
|
||||
hook("clustering.fcluster", clusters)
|
||||
|
||||
# split clusters into two categories based on their number of items:
|
||||
# large clusters vs. small clusters
|
||||
cluster_unique, cluster_counts = np.unique(
|
||||
@@ -470,6 +477,7 @@ class AgglomerativeClustering(BaseClustering):
|
||||
|
||||
# re-number clusters from 0 to num_large_clusters
|
||||
_, clusters = np.unique(clusters, return_inverse=True)
|
||||
|
||||
return clusters
|
||||
|
||||
|
||||
|
||||
@@ -553,6 +553,7 @@ class SpeakerDiarization(SpeakerDiarizationMixin, Pipeline):
|
||||
max_clusters=max_speakers,
|
||||
file=file, # <== for oracle clustering
|
||||
frames=self._segmentation.model.receptive_field, # <== for oracle clustering
|
||||
hook=hook,
|
||||
)
|
||||
# hard_clusters: (num_chunks, num_speakers)
|
||||
# centroids: (num_speakers, dimension)
|
||||
@@ -590,6 +591,9 @@ class SpeakerDiarization(SpeakerDiarizationMixin, Pipeline):
|
||||
# shape: (num_chunks, num_speakers)
|
||||
|
||||
hard_clusters[inactive_speakers] = -2
|
||||
|
||||
hook("hard_clusters", hard_clusters)
|
||||
|
||||
discrete_diarization = self.reconstruct(
|
||||
segmentations,
|
||||
hard_clusters,
|
||||
|
||||
Reference in new issue
Block a user