"""Helper function to load datasets."""
from __future__ import annotations
import json
from pathlib import Path
from tno.quantum.utils.validation import check_path
from tno.quantum.problems.mot import DetectionSequence, FrameDets
[docs]
def load_dataset(path: Path | None = None) -> DetectionSequence:
"""Helper function to load a detection sequence dataset for MOT.
If a path is provided, the dataset is loaded from that file.
Otherwise, the default built-in benchmark dataset is used.
Args:
path: Path to a JSON file containing the detection sequence. If not provided,
the default built-in dataset is loaded.
Returns:
The detection sequence ready to use in MOT pipelines.
Raises:
FileNotFoundError: If the test dataset can not be found.
"""
if path is None: # Use default dataset
path = Path(__file__).parent / "det_sequence.json"
dataset_path = check_path(
path,
name="dataset path",
must_exist=True,
must_be_file=True,
required_suffix=".json",
)
with dataset_path.open("r") as f:
data = json.load(f)
return DetectionSequence([FrameDets.from_dict(det) for det in data])