any2ego / code_support /project_paths.py
diffusion-gif's picture
init: Any2Ego code, README and checkpoint indexes
c28ffff verified
Raw History Blame Contribute Delete
1.03 kB
"""Resolve package-relative resources without machine-specific locations."""
import os
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
def env(name, default=""):
return os.environ.get(name, default)
def project_path(relative):
path = Path(relative)
return str(path if path.is_absolute() else ROOT / path)
def initialize(entrypoint=False):
for relative in ("eval", "diffusion", "data"):
location = project_path(relative)
if location not in sys.path:
sys.path.insert(0, location)
if entrypoint:
os.chdir(ROOT)
os.environ.setdefault("TORCH_HOME", project_path(".cache/torch"))
def seg_mask_root(root=None):
"""External PhiSeg output root; no masks are distributed with the code."""
return project_path(root or os.environ.get("SEG_MASK_ROOT", "data/seg_masks"))
def seg_mask_dir(clip_id, root=None):
"""Same layout as infer_phiseg: <root>/<clip_id>/ego/*.png."""
return str(Path(seg_mask_root(root)) / clip_id / "ego")