workspace / experiments /config.py
AntonioJun's picture
Add files using upload-large-folder tool
8e80498 verified
Raw
History Blame Contribute Delete
3.43 kB
"""Configuration and safe path construction for geometry experiments."""
from __future__ import annotations
from pathlib import Path
from encoder import config as encoder_config
EXPERIMENT_ROOT = Path(__file__).resolve().parent
HYPOTHESES_ROOT = EXPERIMENT_ROOT / "hypotheses"
CACHES_ROOT = EXPERIMENT_ROOT / "caches"
RESULTS_ROOT = EXPERIMENT_ROOT / "results"
# Same two schemas symbolic/adapters.py supports -- a hypothesis's build_spatial_code() may
# produce either the "explicit" answer-oriented shape or the "compact" oriented-box/time/
# floor-polygon primitive shape (adapted at scoring time). Every on-disk path below carries
# this as its own bottom-most segment, exactly like the real spatial-code layout under
# data/spatial codes/<model>/<depth>/<tracking>/<input>/<frames>/<format>/ -- so an "explicit"
# and a "compact" run of the SAME hypothesis name never collide on disk.
SPATIAL_CODE_FORMATS = ("explicit", "compact")
def normalize_hypothesis(name: str) -> str:
"""Return a safe hypothesis stem without silently changing its display name."""
value = name[:-3] if name.endswith(".py") else name
if not value or value in {".", ".."} or Path(value).name != value:
raise ValueError(f"invalid hypothesis name: {name!r}")
return value
def validate_spatial_code_format(spatial_code_format: str) -> str:
if spatial_code_format not in SPATIAL_CODE_FORMATS:
raise ValueError(
f"unknown spatial-code format {spatial_code_format!r}; "
f"expected {SPATIAL_CODE_FORMATS}"
)
return spatial_code_format
def hypothesis_path(name: str) -> Path:
return HYPOTHESES_ROOT / f"{normalize_hypothesis(name)}.py"
def spatial_code_directory(
hypothesis: str,
depth: str,
tracking: str,
input_selection: str,
frame_count: int,
spatial_code_format: str = "explicit",
) -> Path:
encoder_config._validate_dimensions(depth, input_selection, tracking, frame_count)
return (
CACHES_ROOT
/ "spatial codes"
/ depth
/ tracking
/ input_selection
/ normalize_hypothesis(hypothesis)
/ str(frame_count)
/ validate_spatial_code_format(spatial_code_format)
)
def spatial_code_path(
scene: str,
hypothesis: str,
depth: str,
tracking: str,
input_selection: str,
frame_count: int,
spatial_code_format: str = "explicit",
) -> Path:
if not scene or Path(scene).name != scene:
raise ValueError(f"invalid scene name: {scene!r}")
return (
spatial_code_directory(
hypothesis,
depth,
tracking,
input_selection,
frame_count,
spatial_code_format,
)
/ f"{scene}.json"
)
def result_directory(
hypothesis: str,
evaluator: str,
depth: str,
tracking: str,
input_selection: str,
frame_count: int,
spatial_code_format: str = "explicit",
) -> Path:
encoder_config._validate_dimensions(depth, input_selection, tracking, frame_count)
if not evaluator or Path(evaluator).name != evaluator:
raise ValueError(f"invalid evaluator name: {evaluator!r}")
return (
RESULTS_ROOT
/ evaluator
/ depth
/ tracking
/ input_selection
/ normalize_hypothesis(hypothesis)
/ str(frame_count)
/ validate_spatial_code_format(spatial_code_format)
)