2026-05-20 13:42:48 +02:00
|
|
|
from dataclasses import dataclass, field
|
|
|
|
|
from pathlib import Path
|
2026-05-20 13:26:03 +02:00
|
|
|
|
2026-05-20 13:42:48 +02:00
|
|
|
import yaml
|
2026-05-20 13:26:03 +02:00
|
|
|
|
2026-05-20 13:42:48 +02:00
|
|
|
|
2026-05-20 14:00:11 +02:00
|
|
|
@dataclass
|
|
|
|
|
class FilenameConfig:
|
|
|
|
|
video_in_zip: str = "left.mp4"
|
|
|
|
|
video_tmp_suffix: str = ".mp4"
|
|
|
|
|
zip_extension: str = ".zip"
|
|
|
|
|
mask: str = "mask.png"
|
|
|
|
|
metadata: str = "metadata.json"
|
|
|
|
|
frame: str = "frame.png"
|
|
|
|
|
overlay: str = "overlay.png"
|
|
|
|
|
mask_vis: str = "mask_vis.png"
|
|
|
|
|
gif_original_hires: str = "video_original_hires.gif"
|
|
|
|
|
gif_original_lowres: str = "video_original_lowres.gif"
|
|
|
|
|
gif_overlay_hires: str = "video_overlay_hires.gif"
|
|
|
|
|
gif_overlay_lowres: str = "video_overlay_lowres.gif"
|
|
|
|
|
|
|
|
|
|
|
2026-05-20 13:42:48 +02:00
|
|
|
@dataclass
|
|
|
|
|
class AppConfig:
|
2026-05-20 16:15:38 +02:00
|
|
|
storage: str # required: 'local' or 's3'
|
2026-05-20 13:42:48 +02:00
|
|
|
display_max: int = 480
|
|
|
|
|
fps_fallback: int = 25
|
|
|
|
|
max_frames: int = 100
|
|
|
|
|
data_dir: str = "data/clips"
|
|
|
|
|
out_dir: str = "data/annotation_results"
|
|
|
|
|
clips_file: str = "config/clips.txt"
|
2026-05-20 15:13:10 +02:00
|
|
|
optical_flow_config_file: str = ""
|
2026-05-20 13:42:48 +02:00
|
|
|
questions: list = field(default_factory=list)
|
2026-05-20 14:00:11 +02:00
|
|
|
filenames: FilenameConfig = field(default_factory=FilenameConfig)
|
2026-05-20 13:42:48 +02:00
|
|
|
|
|
|
|
|
def get_questions(self):
|
|
|
|
|
return [
|
2026-05-20 13:26:03 +02:00
|
|
|
(
|
2026-05-20 13:42:48 +02:00
|
|
|
s["section"],
|
|
|
|
|
[
|
|
|
|
|
(
|
|
|
|
|
item["key"],
|
|
|
|
|
item["label"],
|
|
|
|
|
[str(o) for o in item["options"]],
|
2026-05-20 14:00:11 +02:00
|
|
|
str(item["default"])
|
|
|
|
|
if item.get("default") is not None
|
|
|
|
|
else None,
|
2026-05-20 13:42:48 +02:00
|
|
|
)
|
|
|
|
|
for item in s["items"]
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
for s in self.questions
|
|
|
|
|
]
|
|
|
|
|
|
2026-05-20 13:26:03 +02:00
|
|
|
|
2026-05-20 15:13:10 +02:00
|
|
|
@dataclass
|
|
|
|
|
class OpticalFlowConfig:
|
|
|
|
|
enabled: bool = False
|
|
|
|
|
norm_squared_threshold: float = 0.3
|
|
|
|
|
gaussian_kernel: tuple[int, int] = (5, 5)
|
|
|
|
|
brightness_range: tuple[int, int] = (20, 235)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_optical_flow_config(path: Path) -> OpticalFlowConfig:
|
|
|
|
|
with open(path) as f:
|
|
|
|
|
data = yaml.safe_load(f)
|
|
|
|
|
data["gaussian_kernel"] = tuple(data["gaussian_kernel"])
|
|
|
|
|
data["brightness_range"] = tuple(data["brightness_range"])
|
|
|
|
|
return OpticalFlowConfig(**data)
|
|
|
|
|
|
|
|
|
|
|
2026-05-20 13:42:48 +02:00
|
|
|
def load_config(path: Path) -> AppConfig:
|
|
|
|
|
with open(path) as f:
|
|
|
|
|
data = yaml.safe_load(f)
|
2026-05-20 16:15:38 +02:00
|
|
|
if "storage" not in data:
|
|
|
|
|
raise ValueError(
|
|
|
|
|
f"{path}: missing required field 'storage'. Set it to 'local' or 's3'."
|
|
|
|
|
)
|
2026-05-20 14:00:11 +02:00
|
|
|
fn_data = data.pop("filenames", {})
|
|
|
|
|
cfg = AppConfig(**data)
|
|
|
|
|
cfg.filenames = FilenameConfig(**fn_data)
|
|
|
|
|
return cfg
|