Add targets to data summary command

This commit is contained in:
mbsantiago 2025-11-10 19:27:31 +00:00
parent 110432bd40
commit efc996a0db

View File

@ -22,6 +22,11 @@ def data(): ...
type=str, type=str,
help="If the dataset info is in a nested field please specify here.", help="If the dataset info is in a nested field please specify here.",
) )
@click.option(
"--targets",
"targets_path",
type=click.Path(exists=True),
)
@click.option( @click.option(
"--base-dir", "--base-dir",
type=click.Path(exists=True), type=click.Path(exists=True),
@ -30,9 +35,11 @@ def data(): ...
def summary( def summary(
dataset_config: Path, dataset_config: Path,
field: Optional[str] = None, field: Optional[str] = None,
targets_path: Optional[Path] = None,
base_dir: Optional[Path] = None, base_dir: Optional[Path] = None,
): ):
from batdetect2.data import load_dataset_from_config from batdetect2.data import compute_class_summary, load_dataset_from_config
from batdetect2.targets import load_targets
base_dir = base_dir or Path.cwd() base_dir = base_dir or Path.cwd()
@ -44,6 +51,15 @@ def summary(
print(f"Number of annotated clips: {len(dataset)}") print(f"Number of annotated clips: {len(dataset)}")
if targets_path is None:
return
targets = load_targets(targets_path)
summary = compute_class_summary(dataset, targets)
print(summary.to_markdown())
@data.command() @data.command()
@click.argument( @click.argument(
@ -78,15 +94,9 @@ def convert(
base_dir = base_dir or Path.cwd() base_dir = base_dir or Path.cwd()
config = load_dataset_config( config = load_dataset_config(dataset_config, field=field)
dataset_config,
field=field,
)
dataset = load_dataset( dataset = load_dataset(config, base_dir=base_dir)
config,
base_dir=base_dir,
)
annotation_set = data.AnnotationSet( annotation_set = data.AnnotationSet(
clip_annotations=list(dataset), clip_annotations=list(dataset),