Allow enabling/disabling filtering and transforms during data loading

This commit is contained in:
mbsantiago 2026-03-28 20:27:04 +00:00
parent 548cd366cd
commit 716b3a3778
2 changed files with 24 additions and 2 deletions

View File

@ -137,6 +137,22 @@ def summary(
"matching names will be excluded from the output."
),
)
@click.option(
"--apply-transforms/--no-apply-transforms",
default=True,
help=(
"Apply any configured sound event transforms to the annotations. "
"Defaults to True."
),
)
@click.option(
"--apply-filters/--no-apply-filters",
default=True,
help=(
"Apply any configured sound event filters to the annotations. "
"Defaults to True."
),
)
def convert(
dataset_config: Path,
field: str | None = None,
@ -146,6 +162,8 @@ def convert(
add_source_tag: bool = True,
include_sources: list[str] | None = None,
exclude_sources: list[str] | None = None,
apply_transforms: bool = True,
apply_filters: bool = True,
):
"""Convert a dataset config into soundevent annotation-set format.
@ -166,6 +184,8 @@ def convert(
add_source_tag=add_source_tag,
include_sources=include_sources,
exclude_sources=exclude_sources,
apply_transforms=apply_transforms,
apply_filters=apply_filters,
)
annotation_set = data.AnnotationSet(

View File

@ -81,6 +81,8 @@ def load_dataset(
add_source_tag: bool = True,
include_sources: list[str] | None = None,
exclude_sources: list[str] | None = None,
apply_transforms: bool = True,
apply_filters: bool = True,
) -> Dataset:
"""Load all clip annotations from the sources defined in a DatasetConfig."""
clip_annotations = []
@ -121,13 +123,13 @@ def load_dataset(
if add_source_tag:
clip_annotation = insert_source_tag(clip_annotation, source)
if condition is not None:
if condition is not None and apply_filters:
clip_annotation = filter_clip_annotation(
clip_annotation,
condition,
)
if transform is not None:
if transform is not None and apply_transforms:
clip_annotation = transform_clip_annotation(
clip_annotation,
transform,