Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial version with dict-based annotations-segments #1633

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions pyannote/audio/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,31 @@ def setup(self, stage=None):
f"does not correspond to the cached one ({self.prepared_data['protocol']})"
)

# prepare annotations-segments into dict-like format, since it can't be stored in a cache .npy file like that
annotations = self.prepared_data['annotations-segments']
annotations_dict = defaultdict(list)
file_ids = []
for annotation in annotations:
file_id = annotation[0]
file_ids.append(file_id)
annotations_dict[file_id].append(annotation)

segment_dtype = [
(
"file_id",
get_dtype(max(a[0] for a in annotations)),
),
("start", "f"),
("end", "f"),
("file_label_idx", get_dtype(max(a[3] for a in annotations))),
("database_label_idx", get_dtype(max(a[4] for a in annotations))),
("global_label_idx", get_dtype(max(a[5] for a in annotations))),
]

for file_id in file_ids:
annotations_dict[file_id] = np.array(annotations_dict[file_id], dtype=segment_dtype)
self.prepared_data['annotations-segments'] = annotations_dict

@property
def specifications(self) -> Union[Specifications, Tuple[Specifications]]:
# setup metadata on-demand the first time specifications are requested and missing
Expand Down
5 changes: 2 additions & 3 deletions pyannote/audio/tasks/segmentation/multilabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,9 @@ def prepare_chunk(self, file_id: int, start_time: float, duration: float):

sample = dict()
sample["X"], _ = self.model.audio.crop(file, chunk, duration=duration)

# gather all annotations of current file
annotations = self.prepared_data["annotations-segments"][
self.prepared_data["annotations-segments"]["file_id"] == file_id
]
annotations = self.prepared_data["annotations-segments"][file_id]

# gather all annotations with non-empty intersection with current chunk
chunk_annotations = annotations[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ def prepare_chunk(self, file_id: int, start_time: float, duration: float):
sample["X"], _ = self.model.audio.crop(file, chunk, duration=duration)

# gather all annotations of current file
annotations = self.prepared_data["annotations-segments"][
self.prepared_data["annotations-segments"]["file_id"] == file_id
]
annotations = self.prepared_data["annotations-segments"][file_id]

# gather all annotations with non-empty intersection with current chunk
chunk_annotations = annotations[
Expand Down
4 changes: 1 addition & 3 deletions pyannote/audio/tasks/segmentation/speaker_diarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ def prepare_chunk(self, file_id: int, start_time: float, duration: float):
sample["X"], _ = self.model.audio.crop(file, chunk, duration=duration)

# gather all annotations of current file
annotations = self.prepared_data["annotations-segments"][
self.prepared_data["annotations-segments"]["file_id"] == file_id
]
annotations = self.prepared_data["annotations-segments"][file_id]

# gather all annotations with non-empty intersection with current chunk
chunk_annotations = annotations[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ def prepare_chunk(self, file_id: int, start_time: float, duration: float):
sample["X"], _ = self.model.audio.crop(file, chunk, duration=duration)

# gather all annotations of current file
annotations = self.prepared_data["annotations-segments"][
self.prepared_data["annotations-segments"]["file_id"] == file_id
]
annotations = self.prepared_data["annotations-segments"][file_id]

# gather all annotations with non-empty intersection with current chunk
chunk_annotations = annotations[
Expand Down
Loading