File size: 3,434 Bytes
a45b7c9 02cbb89 8e80498 02cbb89 8e80498 02cbb89 8e80498 02cbb89 a45b7c9 02cbb89 a45b7c9 8e80498 a45b7c9 02cbb89 a45b7c9 8e80498 a45b7c9 02cbb89 a45b7c9 8e80498 a45b7c9 02cbb89 a45b7c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | """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)
)
|