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

Expose keep_excessive_supervision parameter #1077

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion lhotse/cut/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ def plot_alignment(self, alignment_type: str = "word"):
def trim_to_supervisions(
self,
keep_overlapping: bool = True,
keep_excessive_supervisions: bool = True,
min_duration: Optional[Seconds] = None,
context_direction: Literal["center", "left", "right", "random"] = "center",
keep_all_channels: bool = False,
Expand Down Expand Up @@ -440,6 +441,8 @@ def trim_to_supervisions(
:param keep_overlapping: when ``False``, it will discard parts of other supervisions that overlap with the
main supervision. In the illustration above, it would discard ``Sup2`` in ``Cut1`` and ``Sup1`` in ``Cut2``.
In this mode, we guarantee that there will always be exactly one supervision per cut.
:param keep_excessive_supervisions: when ``False``, it will discard supervisions which are longer than cuts.
Can result in cuts without supervisions.
:param min_duration: An optional duration in seconds; specifying this argument will extend the cuts
that would have been shorter than ``min_duration`` with actual acoustic context in the recording/features.
If there are supervisions present in the context, they are kept when ``keep_overlapping`` is true.
Expand Down Expand Up @@ -473,7 +476,7 @@ def trim_to_supervisions(
trimmed = self.truncate(
offset=new_start,
duration=new_duration,
keep_excessive_supervisions=keep_overlapping,
keep_excessive_supervisions=keep_excessive_supervisions,
_supervisions_index=supervisions_index,
)

Expand All @@ -485,6 +488,11 @@ def trim_to_supervisions(
# For MixedCut, we can't change the channels since it is defined by the
# number of channels in underlying tracks.

# Ensure that there are supervisions.
assert (len(trimmed.supervisions) > 0), (
"Trimmed cut has no supervisions. Make sure that supervisions "
"are not filtered out. Consider `keep_excessive_supervisions=True`."
)
# Ensure that all supervisions have the same channel.
assert (
len(set(to_hashable(s.channel) for s in trimmed.supervisions)) == 1
Expand Down