File size: 1,030 Bytes
c28ffff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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")