-
Notifications
You must be signed in to change notification settings - Fork 223
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
optimize save_audios() #1131
Merged
pzelasko
merged 2 commits into
lhotse-speech:master
from
KarelVesely84:optimize_save_audios
Sep 5, 2023
Merged
optimize save_audios() #1131
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
|
||
from lhotse.audio import RecordingSet, null_result_on_audio_loading_error | ||
from lhotse.augmentation import AugmentFn | ||
from lhotse.caching import is_caching_enabled | ||
from lhotse.cut.base import Cut | ||
from lhotse.cut.data import DataCut | ||
from lhotse.cut.mixed import MixedCut, MixTrack | ||
|
@@ -1413,6 +1414,17 @@ def combine_same_recording_channels(self) -> "CutSet": | |
groups = groupby(lambda cut: (cut.recording.id, cut.start, cut.end), self) | ||
return CutSet.from_cuts(MultiCut.from_mono(*cuts) for cuts in groups.values()) | ||
|
||
def sort_by_recording_id(self, ascending: bool = True) -> "CutSet": | ||
""" | ||
Sort the CutSet alphabetically according to 'recording_id'. Ascending by default. | ||
This is advantageous before caling `save_audios()` on a `trim_to_supervision()` | ||
processed `CutSet`, also make sure that `set_caching_enabled(True)` was called. | ||
""" | ||
return CutSet.from_cuts( | ||
sorted(self, key=(lambda cut: cut.recording.id), reverse=not ascending) | ||
) | ||
|
||
def sort_by_duration(self, ascending: bool = False) -> "CutSet": | ||
""" | ||
Sort the CutSet according to cuts duration and return the result. Descending by default. | ||
|
@@ -2326,6 +2338,7 @@ def save_audios( | |
executor: Optional[Executor] = None, | ||
augment_fn: Optional[AugmentFn] = None, | ||
progress_bar: bool = True, | ||
shuffle_on_split: bool = True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This option is undocumented |
||
) -> "CutSet": | ||
""" | ||
Store waveforms of all cuts as audio recordings to disk. | ||
|
@@ -2355,6 +2368,8 @@ def save_audios( | |
https://lhotse.readthedocs.io/en/latest/parallelism.html | ||
:param progress_bar: Should a progress bar be displayed (automatically turned off | ||
for parallel computation). | ||
:param shuffle_on_split: Shuffle the ``CutSet`` before splitting it for the parallel workers. | ||
It is active only when `num_jobs > 1`. The default is True. | ||
:return: Returns a new ``CutSet``. | ||
""" | ||
from cytoolz import identity | ||
|
@@ -2401,14 +2416,17 @@ def file_storage_path(cut: Cut, storage_path: Pathlike) -> Path: | |
) | ||
|
||
# Parallel execution: prepare the CutSet splits | ||
cut_sets = self.split(num_jobs, shuffle=True) | ||
cut_sets = self.split(num_jobs, shuffle=shuffle_on_split) | ||
|
||
# Initialize the default executor if None was given | ||
if executor is None: | ||
import multiprocessing | ||
|
||
# The `is_caching_enabled()` state gets transfered to | ||
# the spawned sub-processes implictly (checked). | ||
executor = ProcessPoolExecutor( | ||
num_jobs, mp_context=multiprocessing.get_context("spawn") | ||
max_workers=num_jobs, | ||
mp_context=multiprocessing.get_context("spawn"), | ||
) | ||
|
||
# Submit the chunked tasks to parallel workers. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a unit test to cover this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to that.
I found a similar unit-test test_cut_set_sort_by_duration().
Could you point me to the place, where this test is called ?
I did not find any code calling
test_cut_set_sort_by_duration()
in the/test
folder and there are some arguments necessary to be filled...
Thx, Karel