Add files using upload-large-folder tool
Browse files- backup.py +198 -0
- encoder/render.py +2 -2
- symbolic/__pycache__/launch.cpython-311.pyc +0 -0
- symbolic/__pycache__/run.cpython-311.pyc +0 -0
- tests/test_A/__pycache__/__init__.cpython-311.pyc +0 -0
- tests/test_encoder/.pytest_cache/.gitignore +2 -0
- tests/test_encoder/.pytest_cache/CACHEDIR.TAG +4 -0
- tests/test_encoder/.pytest_cache/README.md +8 -0
- tests/test_encoder/.pytest_cache/v/cache/nodeids +1 -0
- tests/test_encoder/__pycache__/conftest.cpython-311-pytest-9.1.1.pyc +0 -0
- tests/test_encoder/__pycache__/test_config.cpython-311-pytest-8.3.5.pyc +0 -0
- tests/test_encoder/__pycache__/test_encoder.cpython-311-pytest-8.3.5.pyc +0 -0
- tests/test_encoder/__pycache__/test_geometric.cpython-311-pytest-8.3.5.pyc +0 -0
- tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-8.3.5.pyc +0 -0
- tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc +0 -0
- tests/test_encoder/__pycache__/test_run.cpython-311-pytest-8.3.5.pyc +0 -0
- tests/test_encoder/__pycache__/test_run.cpython-311-pytest-9.1.1.pyc +0 -0
- tests/test_encoder/test_adapters.py +3 -1
- tests/test_encoder/test_config.py +18 -1
- tests/test_encoder/test_encoder.py +3 -0
- tests/test_encoder/test_ground_truth.py +289 -0
- tests/test_encoder/test_render.py +2 -0
- tests/test_encoder/test_run.py +2 -0
- tests/test_inference/__pycache__/conftest.cpython-311-pytest-8.3.5.pyc +0 -0
- tests/test_inference/__pycache__/conftest.cpython-311-pytest-9.1.1.pyc +0 -0
- tests/test_inference/__pycache__/test_adapters.cpython-311-pytest-8.3.5.pyc +0 -0
- tests/test_inference/__pycache__/test_adapters.cpython-311-pytest-9.1.1.pyc +0 -0
- tests/test_inference/__pycache__/test_inference.cpython-311-pytest-8.3.5.pyc +0 -0
- tests/test_inference/__pycache__/test_inference.cpython-311-pytest-9.1.1.pyc +0 -0
- tests/test_inference/__pycache__/test_run.cpython-311-pytest-9.1.1.pyc +0 -0
- tests/test_inference/test_adapters.py +2 -0
- tests/test_inference/test_launch.py +2 -0
backup.py
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Back up this workspace -- results, spatial codes, AND the code/setup itself -- to a
|
| 3 |
+
Hugging Face dataset repo.
|
| 4 |
+
|
| 5 |
+
Every "target" maps to one or more self-contained local paths (directories or single
|
| 6 |
+
files), each uploaded with the exact same relative path it has in the workspace
|
| 7 |
+
(results/A/... stays results/A/... in the repo, backup.py stays backup.py). That's what
|
| 8 |
+
makes this safe to call repeatedly, once per plan, without ever overwriting or deleting
|
| 9 |
+
anything outside the target you asked for:
|
| 10 |
+
|
| 11 |
+
- Each target's --allow-patterns scope is disjoint from every other target's (results/A
|
| 12 |
+
vs results/B vs ... vs "data/spatial codes" vs "code"'s own paths), so backing up B can
|
| 13 |
+
never touch what A already uploaded.
|
| 14 |
+
- huggingface_hub's upload_large_folder() only ever adds or updates the files it's given
|
| 15 |
+
-- it never deletes anything else already in the repo (no delete_patterns is passed
|
| 16 |
+
here, ever), so re-running the same target later (more scenes finished, --rebuild
|
| 17 |
+
reran a config, source files edited) just adds/updates those files' remote copies.
|
| 18 |
+
- "symbolic" covers BOTH results/symbolic/<depth>/... (production) and
|
| 19 |
+
results/symbolic/ground truth/... in one call, since the latter is already nested
|
| 20 |
+
under the former; "spatial-codes" likewise covers both encoder-perceived
|
| 21 |
+
("data/spatial codes/<model>/...") and ground-truth ("data/spatial codes/ground
|
| 22 |
+
truth/...") codes in one call, satisfying "upload after the regenerate spatial code
|
| 23 |
+
parts" without a separate target for it.
|
| 24 |
+
- "code" covers every source directory (harness, symbolic, analysis, encoder,
|
| 25 |
+
inference, tests) plus the top-level README.md, backup.py, and setup.sh -- everything
|
| 26 |
+
needed to reproduce or re-run the experiment, not just its output. Deliberately
|
| 27 |
+
excludes data/ and results/ (covered by their own targets already) and experiments/
|
| 28 |
+
(a separate, concluded track, not part of the reproducible pipeline).
|
| 29 |
+
|
| 30 |
+
Usage:
|
| 31 |
+
python backup.py --repo-id <you>/<repo> --target A
|
| 32 |
+
python backup.py --repo-id <you>/<repo> --target all
|
| 33 |
+
HF_TOKEN=hf_xxx python backup.py --repo-id <you>/<repo> --target spatial-codes
|
| 34 |
+
python backup.py --repo-id <you>/<repo> --target D --dry-run # no token/network needed
|
| 35 |
+
python backup.py # fully interactive
|
| 36 |
+
|
| 37 |
+
Run after each plan finishes:
|
| 38 |
+
Plan A done -> python backup.py --repo-id <you>/<repo> --target A
|
| 39 |
+
spatial codes regen'd -> python backup.py --repo-id <you>/<repo> --target spatial-codes
|
| 40 |
+
Plan B done -> python backup.py --repo-id <you>/<repo> --target B
|
| 41 |
+
Plan C done -> python backup.py --repo-id <you>/<repo> --target C
|
| 42 |
+
Plan D done -> python backup.py --repo-id <you>/<repo> --target D
|
| 43 |
+
symbolic runs done -> python backup.py --repo-id <you>/<repo> --target symbolic
|
| 44 |
+
code/setup changed -> python backup.py --repo-id <you>/<repo> --target code
|
| 45 |
+
|
| 46 |
+
--repo-id, --target, and the Hugging Face token are all prompted for interactively
|
| 47 |
+
(the token hidden) when not supplied via flag or $HF_TOKEN -- no separate shell wrapper
|
| 48 |
+
needed to get that interactive setup.sh-style experience.
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
from __future__ import annotations
|
| 52 |
+
|
| 53 |
+
import argparse
|
| 54 |
+
import getpass
|
| 55 |
+
import os
|
| 56 |
+
import sys
|
| 57 |
+
from pathlib import Path
|
| 58 |
+
|
| 59 |
+
WORKSPACE_ROOT = Path(__file__).resolve().parent
|
| 60 |
+
|
| 61 |
+
# name -> list of paths (directories or single files, relative to WORKSPACE_ROOT)
|
| 62 |
+
TARGETS = {
|
| 63 |
+
"A": ["results/A"],
|
| 64 |
+
"B": ["results/B"],
|
| 65 |
+
"C": ["results/C"],
|
| 66 |
+
"D": ["results/D"],
|
| 67 |
+
"symbolic": ["results/symbolic"],
|
| 68 |
+
"spatial-codes": ["data/spatial codes"],
|
| 69 |
+
"code": [
|
| 70 |
+
"README.md",
|
| 71 |
+
"backup.py",
|
| 72 |
+
"setup.sh",
|
| 73 |
+
"harness",
|
| 74 |
+
"symbolic",
|
| 75 |
+
"analysis",
|
| 76 |
+
"encoder",
|
| 77 |
+
"inference",
|
| 78 |
+
"tests",
|
| 79 |
+
],
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _resolve_targets(target):
|
| 84 |
+
if target == "all":
|
| 85 |
+
return list(TARGETS)
|
| 86 |
+
if target in TARGETS:
|
| 87 |
+
return [target]
|
| 88 |
+
raise ValueError(f"unknown target {target!r}; expected one of {list(TARGETS) + ['all']}")
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def _has_content(local_path):
|
| 92 |
+
"""True if this path is a real file, or a directory containing at least one file."""
|
| 93 |
+
if local_path.is_file():
|
| 94 |
+
return True
|
| 95 |
+
if local_path.is_dir():
|
| 96 |
+
return any(p.is_file() for p in local_path.rglob("*"))
|
| 97 |
+
return False
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _allow_pattern(path):
|
| 101 |
+
"""A directory needs a /** glob to sweep its contents; a single file's own relative
|
| 102 |
+
path already IS the exact pattern upload_large_folder needs."""
|
| 103 |
+
return f"{path}/**" if (WORKSPACE_ROOT / path).is_dir() else path
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def backup(repo_id, target, token=None, private=False, dry_run=False):
|
| 107 |
+
"""Upload one (or every) target's paths to repo_id, preserving their exact relative
|
| 108 |
+
workspace paths. Returns the list of target names actually uploaded (skips any whose
|
| 109 |
+
local paths don't exist yet or are empty)."""
|
| 110 |
+
names = _resolve_targets(target)
|
| 111 |
+
|
| 112 |
+
pending = []
|
| 113 |
+
for name in names:
|
| 114 |
+
paths = TARGETS[name]
|
| 115 |
+
if not any(_has_content(WORKSPACE_ROOT / p) for p in paths):
|
| 116 |
+
print(f"[{name}] skipped -- nothing found at {', '.join(paths)}")
|
| 117 |
+
continue
|
| 118 |
+
pending.append(name)
|
| 119 |
+
|
| 120 |
+
if not pending:
|
| 121 |
+
return []
|
| 122 |
+
|
| 123 |
+
if dry_run:
|
| 124 |
+
for name in pending:
|
| 125 |
+
for path in TARGETS[name]:
|
| 126 |
+
print(f"[{name}] would upload {WORKSPACE_ROOT / path} -> {repo_id}:{path}")
|
| 127 |
+
return pending
|
| 128 |
+
|
| 129 |
+
from huggingface_hub import HfApi
|
| 130 |
+
|
| 131 |
+
api = HfApi(token=token)
|
| 132 |
+
api.create_repo(repo_id=repo_id, repo_type="dataset", private=private, exist_ok=True)
|
| 133 |
+
|
| 134 |
+
for name in pending:
|
| 135 |
+
patterns = [_allow_pattern(p) for p in TARGETS[name]]
|
| 136 |
+
print(f"[{name}] uploading {', '.join(TARGETS[name])} -> {repo_id} ...")
|
| 137 |
+
api.upload_large_folder(
|
| 138 |
+
repo_id=repo_id,
|
| 139 |
+
repo_type="dataset",
|
| 140 |
+
folder_path=str(WORKSPACE_ROOT),
|
| 141 |
+
allow_patterns=patterns,
|
| 142 |
+
)
|
| 143 |
+
print(f"[{name}] done")
|
| 144 |
+
return pending
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def main():
|
| 148 |
+
parser = argparse.ArgumentParser()
|
| 149 |
+
parser.add_argument(
|
| 150 |
+
"--repo-id", default=None, help="e.g. yourname/vsi-spatial-code-results"
|
| 151 |
+
)
|
| 152 |
+
parser.add_argument("--target", default=None, choices=list(TARGETS) + ["all"])
|
| 153 |
+
parser.add_argument(
|
| 154 |
+
"--token", default=None, help="defaults to $HF_TOKEN, then a cached hf login"
|
| 155 |
+
)
|
| 156 |
+
parser.add_argument("--private", action="store_true", help="create the repo private if new")
|
| 157 |
+
parser.add_argument(
|
| 158 |
+
"--dry-run", action="store_true",
|
| 159 |
+
help="print what would be uploaded and exit -- no token or network needed",
|
| 160 |
+
)
|
| 161 |
+
args = parser.parse_args()
|
| 162 |
+
|
| 163 |
+
repo_id = args.repo_id or input(
|
| 164 |
+
"Hugging Face dataset repo to back up to (e.g. yourname/vsi-spatial-code-results): "
|
| 165 |
+
).strip()
|
| 166 |
+
if not repo_id:
|
| 167 |
+
parser.error("no repo given")
|
| 168 |
+
|
| 169 |
+
target = args.target
|
| 170 |
+
if target is None:
|
| 171 |
+
target = input(f"Target [{'|'.join(list(TARGETS) + ['all'])}]: ").strip()
|
| 172 |
+
if target not in TARGETS and target != "all":
|
| 173 |
+
parser.error(f"unknown target {target!r}; expected one of {list(TARGETS) + ['all']}")
|
| 174 |
+
|
| 175 |
+
token = args.token or os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
| 176 |
+
if not args.dry_run and token is None:
|
| 177 |
+
print(f"Hugging Face token needed to upload to {repo_id} (write access)")
|
| 178 |
+
print("Create one at https://huggingface.co/settings/tokens")
|
| 179 |
+
token = getpass.getpass("HF token (input hidden): ").strip()
|
| 180 |
+
if not args.dry_run and not token:
|
| 181 |
+
parser.error(
|
| 182 |
+
"no Hugging Face token given -- pass --token, set $HF_TOKEN, or run "
|
| 183 |
+
"`huggingface-cli login` first (not needed for --dry-run)"
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
uploaded = backup(
|
| 187 |
+
repo_id, target, token=token, private=args.private, dry_run=args.dry_run
|
| 188 |
+
)
|
| 189 |
+
if not uploaded:
|
| 190 |
+
print("nothing to upload")
|
| 191 |
+
sys.exit(1)
|
| 192 |
+
print(f"\n{'would upload' if args.dry_run else 'uploaded'} target(s): {', '.join(uploaded)}")
|
| 193 |
+
if not args.dry_run:
|
| 194 |
+
print(f"https://huggingface.co/datasets/{repo_id}")
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
if __name__ == "__main__":
|
| 198 |
+
main()
|
encoder/render.py
CHANGED
|
@@ -16,7 +16,7 @@ def build_spatial_code_for(
|
|
| 16 |
tracking,
|
| 17 |
frame_count=config.FRAMES_PER_VIDEO,
|
| 18 |
rebuild=False,
|
| 19 |
-
spatial_code_format="
|
| 20 |
):
|
| 21 |
"""Build a spatial code from cached or newly adapted scene geometry."""
|
| 22 |
spatial_code_format = perceive.adapters.validate_spatial_code_format(
|
|
@@ -36,7 +36,7 @@ def write_spatial_code_for(
|
|
| 36 |
tracking,
|
| 37 |
frame_count=config.FRAMES_PER_VIDEO,
|
| 38 |
rebuild=False,
|
| 39 |
-
spatial_code_format="
|
| 40 |
):
|
| 41 |
"""Build and write one scene's spatial-code JSON."""
|
| 42 |
code, how = build_spatial_code_for(
|
|
|
|
| 16 |
tracking,
|
| 17 |
frame_count=config.FRAMES_PER_VIDEO,
|
| 18 |
rebuild=False,
|
| 19 |
+
spatial_code_format="explicit",
|
| 20 |
):
|
| 21 |
"""Build a spatial code from cached or newly adapted scene geometry."""
|
| 22 |
spatial_code_format = perceive.adapters.validate_spatial_code_format(
|
|
|
|
| 36 |
tracking,
|
| 37 |
frame_count=config.FRAMES_PER_VIDEO,
|
| 38 |
rebuild=False,
|
| 39 |
+
spatial_code_format="explicit",
|
| 40 |
):
|
| 41 |
"""Build and write one scene's spatial-code JSON."""
|
| 42 |
code, how = build_spatial_code_for(
|
symbolic/__pycache__/launch.cpython-311.pyc
CHANGED
|
Binary files a/symbolic/__pycache__/launch.cpython-311.pyc and b/symbolic/__pycache__/launch.cpython-311.pyc differ
|
|
|
symbolic/__pycache__/run.cpython-311.pyc
CHANGED
|
Binary files a/symbolic/__pycache__/run.cpython-311.pyc and b/symbolic/__pycache__/run.cpython-311.pyc differ
|
|
|
tests/test_A/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (144 Bytes). View file
|
|
|
tests/test_encoder/.pytest_cache/.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Created by pytest automatically.
|
| 2 |
+
*
|
tests/test_encoder/.pytest_cache/CACHEDIR.TAG
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Signature: 8a477f597d28d172789f06886806bc55
|
| 2 |
+
# This file is a cache directory tag created by pytest.
|
| 3 |
+
# For information about cache directory tags, see:
|
| 4 |
+
# https://bford.info/cachedir/spec.html
|
tests/test_encoder/.pytest_cache/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# pytest cache directory #
|
| 2 |
+
|
| 3 |
+
This directory contains data from the pytest's cache plugin,
|
| 4 |
+
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
|
| 5 |
+
|
| 6 |
+
**Do not** commit this to version control.
|
| 7 |
+
|
| 8 |
+
See [the docs](https://docs.pytest.org/en/stable/how-to/cache.html) for more information.
|
tests/test_encoder/.pytest_cache/v/cache/nodeids
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
[]
|
tests/test_encoder/__pycache__/conftest.cpython-311-pytest-9.1.1.pyc
ADDED
|
Binary file (1 kB). View file
|
|
|
tests/test_encoder/__pycache__/test_config.cpython-311-pytest-8.3.5.pyc
CHANGED
|
Binary files a/tests/test_encoder/__pycache__/test_config.cpython-311-pytest-8.3.5.pyc and b/tests/test_encoder/__pycache__/test_config.cpython-311-pytest-8.3.5.pyc differ
|
|
|
tests/test_encoder/__pycache__/test_encoder.cpython-311-pytest-8.3.5.pyc
CHANGED
|
Binary files a/tests/test_encoder/__pycache__/test_encoder.cpython-311-pytest-8.3.5.pyc and b/tests/test_encoder/__pycache__/test_encoder.cpython-311-pytest-8.3.5.pyc differ
|
|
|
tests/test_encoder/__pycache__/test_geometric.cpython-311-pytest-8.3.5.pyc
CHANGED
|
Binary files a/tests/test_encoder/__pycache__/test_geometric.cpython-311-pytest-8.3.5.pyc and b/tests/test_encoder/__pycache__/test_geometric.cpython-311-pytest-8.3.5.pyc differ
|
|
|
tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-8.3.5.pyc
CHANGED
|
Binary files a/tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-8.3.5.pyc and b/tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-8.3.5.pyc differ
|
|
|
tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc
ADDED
|
Binary file (1.47 kB). View file
|
|
|
tests/test_encoder/__pycache__/test_run.cpython-311-pytest-8.3.5.pyc
CHANGED
|
Binary files a/tests/test_encoder/__pycache__/test_run.cpython-311-pytest-8.3.5.pyc and b/tests/test_encoder/__pycache__/test_run.cpython-311-pytest-8.3.5.pyc differ
|
|
|
tests/test_encoder/__pycache__/test_run.cpython-311-pytest-9.1.1.pyc
ADDED
|
Binary file (1.75 kB). View file
|
|
|
tests/test_encoder/test_adapters.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import gzip
|
| 2 |
import pickle
|
| 3 |
import sys
|
|
@@ -289,7 +291,7 @@ def test_native_sam3_decodes_lossless_tracking_cache(monkeypatch):
|
|
| 289 |
|
| 290 |
def test_spatial_code_format_validation():
|
| 291 |
assert adapters.validate_spatial_code_format("compact") == "compact"
|
| 292 |
-
assert adapters.validate_spatial_code_format("
|
| 293 |
with pytest.raises(ValueError, match="unknown spatial-code format"):
|
| 294 |
adapters.validate_spatial_code_format("unknown")
|
| 295 |
|
|
|
|
| 1 |
+
"""Tests for encoder/adapters.py -- model-output adapters and canonical geometry validation."""
|
| 2 |
+
|
| 3 |
import gzip
|
| 4 |
import pickle
|
| 5 |
import sys
|
|
|
|
| 291 |
|
| 292 |
def test_spatial_code_format_validation():
|
| 293 |
assert adapters.validate_spatial_code_format("compact") == "compact"
|
| 294 |
+
assert adapters.validate_spatial_code_format("explicit") == "explicit"
|
| 295 |
with pytest.raises(ValueError, match="unknown spatial-code format"):
|
| 296 |
adapters.validate_spatial_code_format("unknown")
|
| 297 |
|
tests/test_encoder/test_config.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import pytest
|
| 2 |
|
| 3 |
from encoder import config
|
|
@@ -14,7 +16,7 @@ def test_encoder_paths_mirror_all_dimensions(tmp_path, monkeypatch):
|
|
| 14 |
).endswith("depth-anything-3/relative/uniform/32/scene.pkl")
|
| 15 |
assert config.spatial_code_path(
|
| 16 |
"scene", "metric", "selective", "tracking", 64
|
| 17 |
-
).endswith("metric/tracking/selective/64/
|
| 18 |
assert config.spatial_code_path(
|
| 19 |
"scene", "relative", "uniform", "no tracking", 96, "compact"
|
| 20 |
).endswith("relative/no tracking/uniform/96/compact/scene.json")
|
|
@@ -25,3 +27,18 @@ def test_encoder_paths_reject_unknown_spatial_code_format():
|
|
| 25 |
config.spatial_code_path(
|
| 26 |
"scene", "metric", "uniform", "tracking", 32, "unknown"
|
| 27 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for encoder/config.py -- cache and spatial-code path helpers."""
|
| 2 |
+
|
| 3 |
import pytest
|
| 4 |
|
| 5 |
from encoder import config
|
|
|
|
| 16 |
).endswith("depth-anything-3/relative/uniform/32/scene.pkl")
|
| 17 |
assert config.spatial_code_path(
|
| 18 |
"scene", "metric", "selective", "tracking", 64
|
| 19 |
+
).endswith("metric/tracking/selective/64/explicit/scene.json")
|
| 20 |
assert config.spatial_code_path(
|
| 21 |
"scene", "relative", "uniform", "no tracking", 96, "compact"
|
| 22 |
).endswith("relative/no tracking/uniform/96/compact/scene.json")
|
|
|
|
| 27 |
config.spatial_code_path(
|
| 28 |
"scene", "metric", "uniform", "tracking", 32, "unknown"
|
| 29 |
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def test_ground_truth_paths_have_no_depth_tracking_input_frames_axis(tmp_path, monkeypatch):
|
| 33 |
+
monkeypatch.setattr(config, "CODES_ROOT", tmp_path / "codes")
|
| 34 |
+
assert config.ground_truth_spatial_code_path("scene", "explicit").endswith(
|
| 35 |
+
"codes/ground truth/explicit/scene.json"
|
| 36 |
+
)
|
| 37 |
+
assert config.ground_truth_spatial_code_path("scene", "compact").endswith(
|
| 38 |
+
"codes/ground truth/compact/scene.json"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def test_ground_truth_paths_reject_unknown_spatial_code_format():
|
| 43 |
+
with pytest.raises(ValueError, match="unknown spatial-code format"):
|
| 44 |
+
config.ground_truth_spatial_code_path("scene", "unknown")
|
tests/test_encoder/test_encoder.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import pytest
|
| 3 |
|
|
|
|
| 1 |
+
"""Tests for encoder/geometric.py's low-level geometry primitives (backprojection,
|
| 2 |
+
direction/turn classification, distance, centroid/extent math)."""
|
| 3 |
+
|
| 4 |
import numpy as np
|
| 5 |
import pytest
|
| 6 |
|
tests/test_encoder/test_ground_truth.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for encoder/ground_truth.py -- spatial codes built from dataset annotations."""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import math
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
+
from encoder import config, geometric
|
| 10 |
+
from encoder import ground_truth as gt
|
| 11 |
+
|
| 12 |
+
IDENTITY_AXES = [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _instance(centroid, dims, axes=None):
|
| 16 |
+
return {
|
| 17 |
+
"centroid": list(centroid),
|
| 18 |
+
"axesLengths": list(dims),
|
| 19 |
+
"normalizedAxes": list(axes if axes is not None else IDENTITY_AXES),
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _write_meta_info(tmp_path, scannet=None, arkitscenes=None, scannetpp=None):
|
| 24 |
+
meta_dir = tmp_path / "thinking-in-space" / "data" / "meta_info"
|
| 25 |
+
meta_dir.mkdir(parents=True)
|
| 26 |
+
for dataset, records in (
|
| 27 |
+
("scannet", scannet or {}),
|
| 28 |
+
("arkitscenes", arkitscenes or {}),
|
| 29 |
+
("scannetpp", scannetpp or {}),
|
| 30 |
+
):
|
| 31 |
+
with open(meta_dir / f"{dataset}_meta_info_val.json", "w") as stream:
|
| 32 |
+
json.dump(records, stream)
|
| 33 |
+
return meta_dir
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@pytest.fixture(autouse=True)
|
| 37 |
+
def _clear_ground_truth_caches():
|
| 38 |
+
gt.load_meta_info.cache_clear()
|
| 39 |
+
gt._appearance_order_ranks_by_scene.cache_clear()
|
| 40 |
+
yield
|
| 41 |
+
gt.load_meta_info.cache_clear()
|
| 42 |
+
gt._appearance_order_ranks_by_scene.cache_clear()
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def test_load_meta_info_merges_all_three_datasets_and_tags_dataset(tmp_path, monkeypatch):
|
| 46 |
+
_write_meta_info(
|
| 47 |
+
tmp_path,
|
| 48 |
+
scannet={"scene0001_00": {"room_size": 10.0, "object_bbox": {}}},
|
| 49 |
+
arkitscenes={"41000000": {"room_size": 12.0, "object_bbox": {}}},
|
| 50 |
+
scannetpp={"abc123": {"room_size": 14.0, "object_bbox": {}}},
|
| 51 |
+
)
|
| 52 |
+
monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info")
|
| 53 |
+
merged = gt.load_meta_info()
|
| 54 |
+
assert merged["scene0001_00"]["dataset"] == "scannet"
|
| 55 |
+
assert merged["41000000"]["dataset"] == "arkitscenes"
|
| 56 |
+
assert merged["abc123"]["dataset"] == "scannetpp"
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def test_floor_level_is_the_lowest_box_support_across_every_instance():
|
| 60 |
+
object_bbox = {
|
| 61 |
+
"chair": [_instance([0, 0, 1.0], [1, 1, 0.4])], # spans z in [0.8, 1.2]
|
| 62 |
+
"table": [_instance([0, 0, 0.5], [1, 1, 1.0])], # spans z in [0.0, 1.0]
|
| 63 |
+
}
|
| 64 |
+
# table reaches lower (0.0) than chair (0.8) -> floor_level should be 0.0
|
| 65 |
+
assert gt._floor_level(object_bbox) == pytest.approx(0.0)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_floor_level_accounts_for_tilted_box_support():
|
| 69 |
+
# a box tilted 45 degrees around x has a lower support than its centroid_z - half_z
|
| 70 |
+
# would suggest if you ignored orientation.
|
| 71 |
+
axes = [
|
| 72 |
+
[1, 0, 0],
|
| 73 |
+
[0, math.cos(math.pi / 4), math.sin(math.pi / 4)],
|
| 74 |
+
[0, -math.sin(math.pi / 4), math.cos(math.pi / 4)],
|
| 75 |
+
]
|
| 76 |
+
flat_axes = [v for row in axes for v in row]
|
| 77 |
+
object_bbox = {"box": [_instance([0, 0, 1.0], [1, 2, 2], axes=flat_axes)]}
|
| 78 |
+
half_extent_z = (1 / 2) * abs(0) + (2 / 2) * abs(math.sin(math.pi / 4)) + (
|
| 79 |
+
2 / 2
|
| 80 |
+
) * abs(math.cos(math.pi / 4))
|
| 81 |
+
assert gt._floor_level(object_bbox) == pytest.approx(1.0 - half_extent_z)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def test_floor_level_defaults_to_zero_for_empty_scene():
|
| 85 |
+
assert gt._floor_level({}) == 0.0
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def test_gt_oriented_box_rebases_height_above_floor_and_passes_xy_through():
|
| 89 |
+
instance = _instance([1.234, -2.345, 3.456], [1.0, 2.0, 3.0])
|
| 90 |
+
box = gt._gt_oriented_box(instance, floor_level=1.0)
|
| 91 |
+
center = box["3D oriented bounding box center coordinates"]
|
| 92 |
+
assert center == [1.23, -2.35, 2.46]
|
| 93 |
+
assert box["3D oriented bounding box dimensions"] == [1.0, 2.0, 3.0]
|
| 94 |
+
assert box["3D oriented bounding box orientation unit vectors"] == [
|
| 95 |
+
[1.0, 0.0, 0.0],
|
| 96 |
+
[0.0, 1.0, 0.0],
|
| 97 |
+
[0.0, 0.0, 1.0],
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def test_gt_oriented_box_renormalizes_orientation_vectors():
|
| 102 |
+
axes = [2, 0, 0, 0, 2, 0, 0, 0, 2] # not unit length
|
| 103 |
+
instance = _instance([0, 0, 0], [1, 1, 1], axes=axes)
|
| 104 |
+
box = gt._gt_oriented_box(instance, floor_level=0.0)
|
| 105 |
+
for row in box["3D oriented bounding box orientation unit vectors"]:
|
| 106 |
+
assert np.linalg.norm(row) == pytest.approx(1.0)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def test_gt_floor_boundary_polygon_area_matches_room_size():
|
| 110 |
+
polygons = gt._gt_floor_boundary_polygons(room_size=16.0, room_center=[3.0, -2.0, 0.0])
|
| 111 |
+
assert len(polygons) == 1
|
| 112 |
+
area = geometric._compact_polygon_area(polygons[0]["outer boundary coordinates"])
|
| 113 |
+
assert area == pytest.approx(16.0, abs=0.01)
|
| 114 |
+
assert polygons[0]["interior hole boundary coordinates"] == []
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def test_appearance_order_ranks_topological_across_multiple_questions(tmp_path, monkeypatch):
|
| 118 |
+
jsonl_path = tmp_path / "test.jsonl"
|
| 119 |
+
questions = [
|
| 120 |
+
{
|
| 121 |
+
"scene_name": "scene1",
|
| 122 |
+
"question_type": "obj_appearance_order",
|
| 123 |
+
"ground_truth": "A",
|
| 124 |
+
"options": ["A. chair, table, lamp", "B. lamp, table, chair"],
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"scene_name": "scene1",
|
| 128 |
+
"question_type": "obj_appearance_order",
|
| 129 |
+
"ground_truth": "A",
|
| 130 |
+
"options": ["A. table, sofa", "B. sofa, table"],
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"scene_name": "scene2",
|
| 134 |
+
"question_type": "object_counting",
|
| 135 |
+
"ground_truth": "3",
|
| 136 |
+
"options": None,
|
| 137 |
+
},
|
| 138 |
+
]
|
| 139 |
+
with open(jsonl_path, "w") as stream:
|
| 140 |
+
for question in questions:
|
| 141 |
+
stream.write(json.dumps(question) + "\n")
|
| 142 |
+
monkeypatch.setattr(config, "JSONL", jsonl_path)
|
| 143 |
+
|
| 144 |
+
ranks = gt._appearance_order_ranks_by_scene()
|
| 145 |
+
assert "scene2" not in ranks
|
| 146 |
+
scene1 = ranks["scene1"]
|
| 147 |
+
assert scene1["chair"] < scene1["table"] < scene1["lamp"]
|
| 148 |
+
assert scene1["table"] < scene1["sofa"]
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def test_build_compact_ground_truth_spatial_code_uses_ranks_and_nulls_unranked(
|
| 152 |
+
tmp_path, monkeypatch
|
| 153 |
+
):
|
| 154 |
+
_write_meta_info(
|
| 155 |
+
tmp_path,
|
| 156 |
+
scannet={
|
| 157 |
+
"scene1": {
|
| 158 |
+
"room_size": 9.0,
|
| 159 |
+
"room_center": [0.0, 0.0, 0.0],
|
| 160 |
+
"object_bbox": {
|
| 161 |
+
"chair": [_instance([0, 0, 0.5], [1, 1, 1])],
|
| 162 |
+
"lamp": [_instance([1, 1, 0.5], [0.2, 0.2, 0.2])],
|
| 163 |
+
},
|
| 164 |
+
}
|
| 165 |
+
},
|
| 166 |
+
)
|
| 167 |
+
monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info")
|
| 168 |
+
jsonl_path = tmp_path / "test.jsonl"
|
| 169 |
+
with open(jsonl_path, "w") as stream:
|
| 170 |
+
stream.write(
|
| 171 |
+
json.dumps(
|
| 172 |
+
{
|
| 173 |
+
"scene_name": "scene1",
|
| 174 |
+
"question_type": "obj_appearance_order",
|
| 175 |
+
"ground_truth": "A",
|
| 176 |
+
"options": ["A. chair, lamp"],
|
| 177 |
+
}
|
| 178 |
+
)
|
| 179 |
+
+ "\n"
|
| 180 |
+
)
|
| 181 |
+
monkeypatch.setattr(config, "JSONL", jsonl_path)
|
| 182 |
+
|
| 183 |
+
code = gt.build_compact_ground_truth_spatial_code("scene1")
|
| 184 |
+
assert code["spatial code schema"] is geometric.COMPACT_SPATIAL_CODE_SCHEMA
|
| 185 |
+
assert code["objects"]["chair"][0]["first visible time"] == 0.0
|
| 186 |
+
assert code["objects"]["lamp"][0]["first visible time"] == 1.0
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def test_build_compact_ground_truth_spatial_code_nulls_untimed_classes(tmp_path, monkeypatch):
|
| 190 |
+
_write_meta_info(
|
| 191 |
+
tmp_path,
|
| 192 |
+
scannet={
|
| 193 |
+
"scene1": {
|
| 194 |
+
"room_size": 9.0,
|
| 195 |
+
"room_center": [0.0, 0.0, 0.0],
|
| 196 |
+
"object_bbox": {"chair": [_instance([0, 0, 0.5], [1, 1, 1])]},
|
| 197 |
+
}
|
| 198 |
+
},
|
| 199 |
+
)
|
| 200 |
+
monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info")
|
| 201 |
+
monkeypatch.setattr(config, "JSONL", tmp_path / "empty.jsonl")
|
| 202 |
+
(tmp_path / "empty.jsonl").write_text("")
|
| 203 |
+
|
| 204 |
+
code = gt.build_compact_ground_truth_spatial_code("scene1")
|
| 205 |
+
assert code["objects"]["chair"][0]["first visible time"] is None
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_build_compact_ground_truth_spatial_code_raises_for_unknown_scene(tmp_path, monkeypatch):
|
| 209 |
+
_write_meta_info(tmp_path)
|
| 210 |
+
monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info")
|
| 211 |
+
monkeypatch.setattr(config, "JSONL", tmp_path / "empty.jsonl")
|
| 212 |
+
(tmp_path / "empty.jsonl").write_text("")
|
| 213 |
+
with pytest.raises(KeyError):
|
| 214 |
+
gt.build_compact_ground_truth_spatial_code("nonexistent")
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
def test_build_explicit_ground_truth_spatial_code_is_derived_from_compact(monkeypatch):
|
| 218 |
+
compact_code = {
|
| 219 |
+
"spatial code schema": geometric.COMPACT_SPATIAL_CODE_SCHEMA,
|
| 220 |
+
"objects": {
|
| 221 |
+
"chair": [
|
| 222 |
+
{
|
| 223 |
+
"3D oriented bounding box": {
|
| 224 |
+
"3D oriented bounding box center coordinates": [0, 0, 0.5],
|
| 225 |
+
"3D oriented bounding box dimensions": [1, 1, 1],
|
| 226 |
+
"3D oriented bounding box orientation unit vectors": [
|
| 227 |
+
[1, 0, 0],
|
| 228 |
+
[0, 1, 0],
|
| 229 |
+
[0, 0, 1],
|
| 230 |
+
],
|
| 231 |
+
},
|
| 232 |
+
"first visible time": 0.0,
|
| 233 |
+
}
|
| 234 |
+
]
|
| 235 |
+
},
|
| 236 |
+
"room": {"floor boundary polygons": []},
|
| 237 |
+
}
|
| 238 |
+
monkeypatch.setattr(gt, "build_compact_ground_truth_spatial_code", lambda scene: compact_code)
|
| 239 |
+
explicit_code = gt.build_explicit_ground_truth_spatial_code("scene1")
|
| 240 |
+
assert explicit_code["spatial code schema"] is geometric.EXPLICIT_SPATIAL_CODE_SCHEMA
|
| 241 |
+
assert explicit_code["objects"]["chair"]["count"] == 1
|
| 242 |
+
assert explicit_code["appearance order"] == ["chair"]
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def test_build_ground_truth_spatial_code_dispatches_by_format(monkeypatch):
|
| 246 |
+
monkeypatch.setattr(gt, "build_compact_ground_truth_spatial_code", lambda scene: "compact-code")
|
| 247 |
+
monkeypatch.setattr(gt, "build_explicit_ground_truth_spatial_code", lambda scene: "explicit-code")
|
| 248 |
+
assert gt.build_ground_truth_spatial_code("scene1", "compact") == "compact-code"
|
| 249 |
+
assert gt.build_ground_truth_spatial_code("scene1", "explicit") == "explicit-code"
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def test_build_ground_truth_spatial_code_rejects_unknown_format():
|
| 253 |
+
with pytest.raises(ValueError, match="unknown spatial-code format"):
|
| 254 |
+
gt.build_ground_truth_spatial_code("scene1", "unknown")
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def test_build_and_write_writes_to_the_ground_truth_path(tmp_path, monkeypatch):
|
| 258 |
+
monkeypatch.setattr(config, "CODES_ROOT", tmp_path / "codes")
|
| 259 |
+
monkeypatch.setattr(gt, "build_ground_truth_spatial_code", lambda scene, fmt: {"objects": {}})
|
| 260 |
+
path = gt.build_and_write("scene1", "explicit")
|
| 261 |
+
assert path.endswith("codes/ground truth/explicit/scene1.json")
|
| 262 |
+
assert json.loads(open(path).read()) == {"objects": {}}
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
def test_scenes_returns_sorted_meta_info_keys(tmp_path, monkeypatch):
|
| 266 |
+
_write_meta_info(
|
| 267 |
+
tmp_path,
|
| 268 |
+
scannet={"scene0002_00": {}, "scene0001_00": {}},
|
| 269 |
+
arkitscenes={"41000000": {}},
|
| 270 |
+
)
|
| 271 |
+
monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info")
|
| 272 |
+
assert gt.scenes() == ["41000000", "scene0001_00", "scene0002_00"]
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def test_build_all_writes_every_scene_and_format(tmp_path, monkeypatch):
|
| 276 |
+
monkeypatch.setattr(config, "CODES_ROOT", tmp_path / "codes")
|
| 277 |
+
monkeypatch.setattr(gt, "scenes", lambda: ["scene1", "scene2"])
|
| 278 |
+
monkeypatch.setattr(gt, "build_ground_truth_spatial_code", lambda scene, fmt: {"objects": {}})
|
| 279 |
+
written = gt.build_all()
|
| 280 |
+
assert len(written) == 4
|
| 281 |
+
assert (tmp_path / "codes" / "ground truth" / "explicit" / "scene1.json").exists()
|
| 282 |
+
assert (tmp_path / "codes" / "ground truth" / "compact" / "scene2.json").exists()
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def test_build_all_respects_explicit_scene_list_and_formats(tmp_path, monkeypatch):
|
| 286 |
+
monkeypatch.setattr(config, "CODES_ROOT", tmp_path / "codes")
|
| 287 |
+
monkeypatch.setattr(gt, "build_ground_truth_spatial_code", lambda scene, fmt: {"objects": {}})
|
| 288 |
+
written = gt.build_all(spatial_code_formats=("compact",), scene_list=["scene9"])
|
| 289 |
+
assert written == [str(tmp_path / "codes" / "ground truth" / "compact" / "scene9.json")]
|
tests/test_encoder/test_render.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from encoder import render
|
| 2 |
|
| 3 |
def test_render_exposes_tracking_and_format_dimensions():
|
|
|
|
| 1 |
+
"""Tests for encoder/render.py -- spatial-code rendering entry point."""
|
| 2 |
+
|
| 3 |
from encoder import render
|
| 4 |
|
| 5 |
def test_render_exposes_tracking_and_format_dimensions():
|
tests/test_encoder/test_run.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from encoder import run
|
| 2 |
|
| 3 |
def test_cache_or_load_exposes_explicit_dimensions():
|
|
|
|
| 1 |
+
"""Tests for encoder/run.py -- combined cache loading and source provenance."""
|
| 2 |
+
|
| 3 |
from encoder import run
|
| 4 |
|
| 5 |
def test_cache_or_load_exposes_explicit_dimensions():
|
tests/test_inference/__pycache__/conftest.cpython-311-pytest-8.3.5.pyc
CHANGED
|
Binary files a/tests/test_inference/__pycache__/conftest.cpython-311-pytest-8.3.5.pyc and b/tests/test_inference/__pycache__/conftest.cpython-311-pytest-8.3.5.pyc differ
|
|
|
tests/test_inference/__pycache__/conftest.cpython-311-pytest-9.1.1.pyc
ADDED
|
Binary file (1 kB). View file
|
|
|
tests/test_inference/__pycache__/test_adapters.cpython-311-pytest-8.3.5.pyc
CHANGED
|
Binary files a/tests/test_inference/__pycache__/test_adapters.cpython-311-pytest-8.3.5.pyc and b/tests/test_inference/__pycache__/test_adapters.cpython-311-pytest-8.3.5.pyc differ
|
|
|
tests/test_inference/__pycache__/test_adapters.cpython-311-pytest-9.1.1.pyc
ADDED
|
Binary file (25.5 kB). View file
|
|
|
tests/test_inference/__pycache__/test_inference.cpython-311-pytest-8.3.5.pyc
CHANGED
|
Binary files a/tests/test_inference/__pycache__/test_inference.cpython-311-pytest-8.3.5.pyc and b/tests/test_inference/__pycache__/test_inference.cpython-311-pytest-8.3.5.pyc differ
|
|
|
tests/test_inference/__pycache__/test_inference.cpython-311-pytest-9.1.1.pyc
ADDED
|
Binary file (5.77 kB). View file
|
|
|
tests/test_inference/__pycache__/test_run.cpython-311-pytest-9.1.1.pyc
ADDED
|
Binary file (5.39 kB). View file
|
|
|
tests/test_inference/test_adapters.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import pytest
|
| 3 |
|
|
|
|
| 1 |
+
"""Tests for inference/adapters.py -- inference backend registry and adapter dispatch."""
|
| 2 |
+
|
| 3 |
import numpy as np
|
| 4 |
import pytest
|
| 5 |
|
tests/test_inference/test_launch.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from inference import launch
|
| 2 |
|
| 3 |
def test_launcher_imports():
|
|
|
|
| 1 |
+
"""Tests for inference/launch.py -- multi-GPU/CPU batch driver."""
|
| 2 |
+
|
| 3 |
from inference import launch
|
| 4 |
|
| 5 |
def test_launcher_imports():
|