mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
fix(task): fix balance option crashing training with KeyError: 'metadata' (#2067)
This commit is contained in:
1 parent
1752fac2bd
commit
ea886e0244
5 files changed
+15
-3
No files matched your search
@@ -4,6 +4,7 @@
|
||||
|
||||
- feat(cli): add `--subfolder` option to `benchmark` command [@antoinelaurent](https://github.com/antoinelaurent)
|
||||
- fix(utils): fix `SpeakerDiarizationMixin.optimal_mapping` `reference` is a mapping [@Kayvan-Zahiri](https://github.com/Kayvan-Zahiri)
|
||||
- fix(task): fix `balance` option crashing training with `KeyError: 'metadata'` [@MohammadHijjawi97](https://github.com/MohammadHijjawi97)
|
||||
|
||||
## Version 4.0.7 (2026-06-30)
|
||||
|
||||
|
||||
@@ -624,6 +624,10 @@ class Task(lightning.LightningDataModule):
|
||||
try:
|
||||
with open(self.cache, "rb") as cache_file:
|
||||
self.prepared_data = dict(np.load(cache_file, allow_pickle=True))
|
||||
# np.savez stores the `metadata-values` dict as a 0-d object array: unwrap it
|
||||
self.prepared_data["metadata-values"] = self.prepared_data[
|
||||
"metadata-values"
|
||||
].item()
|
||||
except FileNotFoundError:
|
||||
print(
|
||||
"Cached data for protocol not found. Ensure that prepare_data() was called",
|
||||
|
||||
@@ -88,7 +88,7 @@ class SegmentationTask(Task):
|
||||
)
|
||||
for key, value in filters.items():
|
||||
training &= self.prepared_data["audio-metadata"][key] == self.prepared_data[
|
||||
"metadata"
|
||||
"metadata-values"
|
||||
][key].index(value)
|
||||
file_ids = np.where(training)[0]
|
||||
|
||||
@@ -163,7 +163,7 @@ class SegmentationTask(Task):
|
||||
# create a subchunk generator for each combination of "balance" keys
|
||||
subchunks = dict()
|
||||
for product in itertools.product(
|
||||
*[self.prepared_data["metadata"][key] for key in balance]
|
||||
*[self.prepared_data["metadata-values"][key] for key in balance]
|
||||
):
|
||||
# we iterate on the cartesian product of the values in metadata_unique_values
|
||||
# eg: for balance=["database", "split"], with 2 databases and 2 splits:
|
||||
|
||||
@@ -503,7 +503,7 @@ class PixIT(SegmentationTask):
|
||||
for key, value in filters.items():
|
||||
split_files &= self.prepared_data["audio-metadata"][
|
||||
key
|
||||
] == self.prepared_data["metadata"][key].index(value)
|
||||
] == self.prepared_data["metadata-values"][key].index(value)
|
||||
file_ids = np.where(split_files)[0]
|
||||
|
||||
# turn annotated duration into a probability distribution
|
||||
|
||||
@@ -76,6 +76,13 @@ def test_train_segmentation(protocol):
|
||||
trainer.fit(model)
|
||||
|
||||
|
||||
def test_train_segmentation_with_balance(protocol):
|
||||
segmentation = SpeakerDiarization(protocol, balance=["database"])
|
||||
model = SimpleSegmentationModel(task=segmentation)
|
||||
trainer = Trainer(fast_dev_run=True, accelerator="cpu")
|
||||
trainer.fit(model)
|
||||
|
||||
|
||||
def test_train_segmentation_with_cached_data_mono_device(protocol, cache):
|
||||
first_task = SpeakerDiarization(protocol, cache=cache)
|
||||
first_model = SimpleSegmentationModel(task=first_task)
|
||||
|
||||
Reference in new issue
Block a user