Update workspace code without replacing data (part 2)
Browse files- setup.sh +153 -70
- symbolic/launch.py +2 -2
- symbolic/run.py +11 -12
- tests/encoder_tests/conftest.py +2 -3
- tests/encoder_tests/test_adapters.py +83 -1
- tests/encoder_tests/test_config.py +4 -4
- tests/encoder_tests/test_geometric.py +32 -0
- tests/encoder_tests/test_launch.py +2 -2
- tests/encoder_tests/test_render.py +2 -2
- tests/encoder_tests/test_run.py +4 -8
- tests/inference_tests/test_adapter_runtime.py +108 -30
- tests/inference_tests/test_gpu_integration.py +20 -16
- tests/inference_tests/test_inference.py +26 -5
- tests/inference_tests/test_launch_runtime.py +3 -3
- tests/symbolic_tests/test_run.py +3 -1
setup.sh
CHANGED
|
@@ -3,15 +3,32 @@ set -Eeuo pipefail
|
|
| 3 |
|
| 4 |
trap 'echo "ERROR: setup failed at line $LINENO: $BASH_COMMAND" >&2' ERR
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
echo "=== RunPod local-disk setup ==="
|
| 7 |
|
|
|
|
| 8 |
DATA_ROOT="/root/data"
|
| 9 |
MODELS_ROOT="/root/models"
|
| 10 |
HF_CACHE="/root/hf-cache"
|
| 11 |
HF_TMP="/root/hf-tmp"
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
VENV="/root/.venv"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
mkdir -p "$DATA_ROOT" "$MODELS_ROOT" "$HF_CACHE" "$HF_TMP"
|
| 17 |
|
|
@@ -21,6 +38,7 @@ apt-get install -y \
|
|
| 21 |
git \
|
| 22 |
git-lfs \
|
| 23 |
ffmpeg \
|
|
|
|
| 24 |
rsync \
|
| 25 |
python3-pip \
|
| 26 |
python3-venv
|
|
@@ -42,41 +60,86 @@ else
|
|
| 42 |
git -C "$DATA_ROOT/thinking-in-space" pull --ff-only
|
| 43 |
fi
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
else
|
| 57 |
-
echo "
|
|
|
|
|
|
|
| 58 |
fi
|
| 59 |
|
| 60 |
-
if [ ! -d "$
|
| 61 |
-
echo "Cloning
|
| 62 |
git clone \
|
| 63 |
-
https://github.com/
|
| 64 |
-
"$
|
| 65 |
else
|
| 66 |
-
echo "Updating existing
|
| 67 |
-
git -C "$
|
| 68 |
-
git -C "$SEGVGGT_DIR" pull --ff-only
|
| 69 |
-
fi
|
| 70 |
-
|
| 71 |
-
if [ ! -f "$REQUIREMENTS" ]; then
|
| 72 |
-
echo "ERROR: requirements.txt not found at:"
|
| 73 |
-
echo "$REQUIREMENTS"
|
| 74 |
-
exit 1
|
| 75 |
fi
|
| 76 |
|
| 77 |
-
echo "
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
echo "Recreating Python environment..."
|
| 82 |
rm -rf "$VENV"
|
|
@@ -87,62 +150,82 @@ rm -rf "$VENV"
|
|
| 87 |
--upgrade \
|
| 88 |
pip setuptools wheel
|
| 89 |
|
| 90 |
-
echo "Installing SegVGGT PyTorch versions..."
|
| 91 |
-
"$VENV/bin/python" -m pip install \
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
echo "Installing
|
| 97 |
"$VENV/bin/python" -m pip install \
|
| 98 |
--no-cache-dir \
|
| 99 |
-
|
| 100 |
|
| 101 |
-
echo "Verifying packages and CUDA..."
|
|
|
|
| 102 |
"$VENV/bin/python" -m pip check
|
| 103 |
-
"$VENV/bin/python" - <<'VERIFY'
|
| 104 |
-
import torch
|
| 105 |
-
import torchvision
|
| 106 |
import cv2
|
| 107 |
-
import hydra
|
| 108 |
-
import omegaconf
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
print("OpenCV:", cv2.__version__)
|
| 119 |
print("Verification passed.")
|
| 120 |
VERIFY
|
| 121 |
|
| 122 |
-
CHECKPOINT="$SEGVGGT_DIR/checkpoint/segvggt_scannet200.pt"
|
| 123 |
-
|
| 124 |
-
if [ ! -f "$CHECKPOINT" ]; then
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
else
|
| 135 |
-
|
| 136 |
-
fi
|
| 137 |
|
| 138 |
|
| 139 |
echo
|
| 140 |
echo "=== Setup complete ==="
|
| 141 |
echo "thinking-in-space: $DATA_ROOT/thinking-in-space"
|
| 142 |
echo "VSI-Bench: $DATA_ROOT/VSI-Bench"
|
| 143 |
-
echo "
|
| 144 |
-
echo "
|
| 145 |
-
echo "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
echo "Virtual env: $VENV"
|
| 147 |
echo
|
| 148 |
|
|
|
|
| 3 |
|
| 4 |
trap 'echo "ERROR: setup failed at line $LINENO: $BASH_COMMAND" >&2' ERR
|
| 5 |
|
| 6 |
+
if [ "$#" -ne 1 ] || [ -z "$1" ]; then
|
| 7 |
+
echo "Usage: bash setup.sh <HF_TOKEN>" >&2
|
| 8 |
+
exit 2
|
| 9 |
+
fi
|
| 10 |
+
HF_TOKEN="$1"
|
| 11 |
+
export HF_TOKEN
|
| 12 |
+
shift
|
| 13 |
+
|
| 14 |
echo "=== RunPod local-disk setup ==="
|
| 15 |
|
| 16 |
+
WORKSPACE_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
| 17 |
DATA_ROOT="/root/data"
|
| 18 |
MODELS_ROOT="/root/models"
|
| 19 |
HF_CACHE="/root/hf-cache"
|
| 20 |
HF_TMP="/root/hf-tmp"
|
| 21 |
+
DA3_DIR="$MODELS_ROOT/depth-anything-3"
|
| 22 |
+
SAM3_DIR="$MODELS_ROOT/sam3"
|
| 23 |
+
# SEGVGGT_DIR="$MODELS_ROOT/SegVGGT"
|
| 24 |
+
# REQUIREMENTS="$SEGVGGT_DIR/requirements.txt"
|
| 25 |
VENV="/root/.venv"
|
| 26 |
+
WORKSPACE_PACKAGES=(
|
| 27 |
+
numpy
|
| 28 |
+
opencv-contrib-python-headless
|
| 29 |
+
Pillow
|
| 30 |
+
scipy
|
| 31 |
+
)
|
| 32 |
|
| 33 |
mkdir -p "$DATA_ROOT" "$MODELS_ROOT" "$HF_CACHE" "$HF_TMP"
|
| 34 |
|
|
|
|
| 38 |
git \
|
| 39 |
git-lfs \
|
| 40 |
ffmpeg \
|
| 41 |
+
unzip \
|
| 42 |
rsync \
|
| 43 |
python3-pip \
|
| 44 |
python3-venv
|
|
|
|
| 60 |
git -C "$DATA_ROOT/thinking-in-space" pull --ff-only
|
| 61 |
fi
|
| 62 |
|
| 63 |
+
echo "Downloading or updating VSI-Bench..."
|
| 64 |
+
mkdir -p "$DATA_ROOT/VSI-Bench"
|
| 65 |
+
|
| 66 |
+
HF_HOME="$HF_CACHE" \
|
| 67 |
+
TMPDIR="$HF_TMP" \
|
| 68 |
+
HF_HUB_DISABLE_XET=1 \
|
| 69 |
+
hf download nyu-visionx/VSI-Bench \
|
| 70 |
+
--repo-type dataset \
|
| 71 |
+
--local-dir "$DATA_ROOT/VSI-Bench"
|
| 72 |
+
|
| 73 |
+
echo "Extracting VSI-Bench video archives..."
|
| 74 |
+
for dataset in arkitscenes scannet scannetpp; do
|
| 75 |
+
archive="$DATA_ROOT/VSI-Bench/$dataset.zip"
|
| 76 |
+
if [ ! -f "$archive" ]; then
|
| 77 |
+
echo "ERROR: expected VSI-Bench archive not found: $archive" >&2
|
| 78 |
+
exit 1
|
| 79 |
+
fi
|
| 80 |
+
unzip -q -n "$archive" -d "$DATA_ROOT/VSI-Bench"
|
| 81 |
+
done
|
| 82 |
+
|
| 83 |
+
if [ ! -d "$DA3_DIR/.git" ]; then
|
| 84 |
+
echo "Cloning Depth Anything 3..."
|
| 85 |
+
git clone --recurse-submodules \
|
| 86 |
+
https://github.com/bytedance-seed/depth-anything-3.git \
|
| 87 |
+
"$DA3_DIR"
|
| 88 |
else
|
| 89 |
+
echo "Updating existing Depth Anything 3 checkout..."
|
| 90 |
+
git -C "$DA3_DIR" pull --ff-only
|
| 91 |
+
git -C "$DA3_DIR" submodule update --init --recursive
|
| 92 |
fi
|
| 93 |
|
| 94 |
+
if [ ! -d "$SAM3_DIR/.git" ]; then
|
| 95 |
+
echo "Cloning SAM3..."
|
| 96 |
git clone \
|
| 97 |
+
https://github.com/facebookresearch/sam3.git \
|
| 98 |
+
"$SAM3_DIR"
|
| 99 |
else
|
| 100 |
+
echo "Updating existing SAM3 checkout..."
|
| 101 |
+
git -C "$SAM3_DIR" pull --ff-only
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
fi
|
| 103 |
|
| 104 |
+
echo "Downloading Depth Anything 3 checkpoint into the DA3 checkout..."
|
| 105 |
+
mkdir -p "$DA3_DIR/checkpoints/DA3-LARGE-1.1"
|
| 106 |
+
HF_HOME="$HF_CACHE" \
|
| 107 |
+
TMPDIR="$HF_TMP" \
|
| 108 |
+
HF_HUB_DISABLE_XET=1 \
|
| 109 |
+
hf download depth-anything/DA3-LARGE-1.1 \
|
| 110 |
+
--repo-type model \
|
| 111 |
+
--local-dir "$DA3_DIR/checkpoints/DA3-LARGE-1.1"
|
| 112 |
+
|
| 113 |
+
echo "Downloading SAM3 checkpoint into the SAM3 checkout..."
|
| 114 |
+
mkdir -p "$SAM3_DIR/checkpoints"
|
| 115 |
+
HF_HOME="$HF_CACHE" \
|
| 116 |
+
TMPDIR="$HF_TMP" \
|
| 117 |
+
HF_HUB_DISABLE_XET=1 \
|
| 118 |
+
hf download facebook/sam3 \
|
| 119 |
+
sam3.pt config.json \
|
| 120 |
+
--repo-type model \
|
| 121 |
+
--local-dir "$SAM3_DIR/checkpoints"
|
| 122 |
+
|
| 123 |
+
# if [ ! -d "$SEGVGGT_DIR/.git" ]; then
|
| 124 |
+
# echo "Cloning SegVGGT..."
|
| 125 |
+
# git clone \
|
| 126 |
+
# https://github.com/IDEA-Research/SegVGGT.git \
|
| 127 |
+
# "$SEGVGGT_DIR"
|
| 128 |
+
# else
|
| 129 |
+
# echo "Updating existing SegVGGT checkout..."
|
| 130 |
+
# git -C "$SEGVGGT_DIR" fetch origin
|
| 131 |
+
# git -C "$SEGVGGT_DIR" pull --ff-only
|
| 132 |
+
# fi
|
| 133 |
+
|
| 134 |
+
# if [ ! -f "$REQUIREMENTS" ]; then
|
| 135 |
+
# echo "ERROR: requirements.txt not found at:"
|
| 136 |
+
# echo "$REQUIREMENTS"
|
| 137 |
+
# exit 1
|
| 138 |
+
# fi
|
| 139 |
+
|
| 140 |
+
# echo "----- SegVGGT requirements.txt -----"
|
| 141 |
+
# cat "$REQUIREMENTS"
|
| 142 |
+
# echo "------------------------------------"
|
| 143 |
|
| 144 |
echo "Recreating Python environment..."
|
| 145 |
rm -rf "$VENV"
|
|
|
|
| 150 |
--upgrade \
|
| 151 |
pip setuptools wheel
|
| 152 |
|
| 153 |
+
# echo "Installing SegVGGT PyTorch versions..."
|
| 154 |
+
# "$VENV/bin/python" -m pip install \
|
| 155 |
+
# --no-cache-dir \
|
| 156 |
+
# torch==2.3.1 torchvision==0.18.1 \
|
| 157 |
+
# --index-url https://download.pytorch.org/whl/cu121
|
| 158 |
+
|
| 159 |
+
# echo "Installing SegVGGT requirements..."
|
| 160 |
+
# "$VENV/bin/python" -m pip install \
|
| 161 |
+
# --no-cache-dir \
|
| 162 |
+
# -r "$REQUIREMENTS"
|
| 163 |
|
| 164 |
+
echo "Installing workspace and its declared dependencies..."
|
| 165 |
"$VENV/bin/python" -m pip install \
|
| 166 |
--no-cache-dir \
|
| 167 |
+
"${WORKSPACE_PACKAGES[@]}"
|
| 168 |
|
| 169 |
+
# echo "Verifying packages and CUDA..."
|
| 170 |
+
echo "Verifying workspace packages..."
|
| 171 |
"$VENV/bin/python" -m pip check
|
| 172 |
+
PYTHONPATH="$WORKSPACE_ROOT" "$VENV/bin/python" - <<'VERIFY'
|
| 173 |
+
# import torch
|
| 174 |
+
# import torchvision
|
| 175 |
import cv2
|
| 176 |
+
# import hydra
|
| 177 |
+
# import omegaconf
|
| 178 |
+
import scipy
|
| 179 |
+
|
| 180 |
+
import encoder.adapters
|
| 181 |
+
import encoder.config
|
| 182 |
+
import encoder.geometric
|
| 183 |
+
import encoder.render
|
| 184 |
+
import encoder.run
|
| 185 |
+
import inference.adapters
|
| 186 |
+
import inference.launch
|
| 187 |
+
import inference.run
|
| 188 |
+
|
| 189 |
+
# assert torch.__version__.startswith("2.3.1"), torch.__version__
|
| 190 |
+
# assert torchvision.__version__.startswith("0.18.1"), torchvision.__version__
|
| 191 |
+
# assert torch.cuda.is_available(), "CUDA is unavailable"
|
| 192 |
+
#
|
| 193 |
+
# print("Torch:", torch.__version__)
|
| 194 |
+
# print("Torchvision:", torchvision.__version__)
|
| 195 |
+
# print("CUDA:", torch.version.cuda)
|
| 196 |
+
# print("GPU:", torch.cuda.get_device_name(0))
|
| 197 |
print("OpenCV:", cv2.__version__)
|
| 198 |
print("Verification passed.")
|
| 199 |
VERIFY
|
| 200 |
|
| 201 |
+
# CHECKPOINT="$SEGVGGT_DIR/checkpoint/segvggt_scannet200.pt"
|
| 202 |
+
#
|
| 203 |
+
# if [ ! -f "$CHECKPOINT" ]; then
|
| 204 |
+
# echo "Downloading SegVGGT ScanNet200 checkpoint..."
|
| 205 |
+
#
|
| 206 |
+
# HF_HOME="$HF_CACHE" \
|
| 207 |
+
# TMPDIR="$HF_TMP" \
|
| 208 |
+
# HF_HUB_DISABLE_XET=1 \
|
| 209 |
+
# hf download JinyuanQu/SegVGGT \
|
| 210 |
+
# checkpoint/segvggt_scannet200.pt \
|
| 211 |
+
# --repo-type model \
|
| 212 |
+
# --local-dir "$SEGVGGT_DIR"
|
| 213 |
+
# else
|
| 214 |
+
# echo "SegVGGT checkpoint already exists; skipping download."
|
| 215 |
+
# fi
|
| 216 |
|
| 217 |
|
| 218 |
echo
|
| 219 |
echo "=== Setup complete ==="
|
| 220 |
echo "thinking-in-space: $DATA_ROOT/thinking-in-space"
|
| 221 |
echo "VSI-Bench: $DATA_ROOT/VSI-Bench"
|
| 222 |
+
echo "Depth Anything 3: $DA3_DIR"
|
| 223 |
+
echo "DA3 checkpoint: $DA3_DIR/checkpoints/DA3-LARGE-1.1"
|
| 224 |
+
echo "SAM3: $SAM3_DIR"
|
| 225 |
+
echo "SAM3 checkpoint: $SAM3_DIR/checkpoints/sam3.pt"
|
| 226 |
+
# echo "SegVGGT: $SEGVGGT_DIR"
|
| 227 |
+
# echo "Requirements: $REQUIREMENTS"
|
| 228 |
+
# echo "Checkpoint: $CHECKPOINT"
|
| 229 |
echo "Virtual env: $VENV"
|
| 230 |
echo
|
| 231 |
|
symbolic/launch.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""Runs the symbolic engine (via symbolic/run.py's score_scene()) across EVERY scene that has
|
| 2 |
-
a real spatial code on disk under /workspace/data/spatial codes/ -- the multi-scene
|
| 3 |
orchestrator, matching encoder/launch.py's and harness/launch.py's own single-scene-worker vs.
|
| 4 |
multi-scene-orchestrator split (symbolic/run.py stays single-scene only; this file is the only
|
| 5 |
one that loops over more than one scene). This file contains no scoring logic of its own --
|
|
@@ -8,7 +8,7 @@ unmodified vsi_official_eval.py) is symbolic/run.py's score_scene(), called once
|
|
| 8 |
|
| 9 |
Usage:
|
| 10 |
python symbolic/launch.py
|
| 11 |
-
Every scene under /workspace/data/spatial codes/*.json that also has at least one real
|
| 12 |
question in test.jsonl -- runs each one (delegating to symbolic/run.py's score_scene()
|
| 13 |
for the actual work), prints a per-scene report (including the appearance-order
|
| 14 |
diagnostic run.py builds), then one combined aggregate across every scene together.
|
|
|
|
| 1 |
"""Runs the symbolic engine (via symbolic/run.py's score_scene()) across EVERY scene that has
|
| 2 |
+
a real spatial code on disk under /workspace/data/spatial codes/segvggt/ -- the multi-scene
|
| 3 |
orchestrator, matching encoder/launch.py's and harness/launch.py's own single-scene-worker vs.
|
| 4 |
multi-scene-orchestrator split (symbolic/run.py stays single-scene only; this file is the only
|
| 5 |
one that loops over more than one scene). This file contains no scoring logic of its own --
|
|
|
|
| 8 |
|
| 9 |
Usage:
|
| 10 |
python symbolic/launch.py
|
| 11 |
+
Every scene under /workspace/data/spatial codes/segvggt/*.json that also has at least one real
|
| 12 |
question in test.jsonl -- runs each one (delegating to symbolic/run.py's score_scene()
|
| 13 |
for the actual work), prints a per-scene report (including the appearance-order
|
| 14 |
diagnostic run.py builds), then one combined aggregate across every scene together.
|
symbolic/run.py
CHANGED
|
@@ -6,9 +6,8 @@ orchestrator (matches encoder/launch.py's and harness/launch.py's own single-sce
|
|
| 6 |
multi-scene-orchestrator split: this file never loops over more than one scene on its own).
|
| 7 |
|
| 8 |
FETCHES the spatial code from:
|
| 9 |
-
/workspace/data/spatial codes/<SCENE_ID>.json
|
| 10 |
-
(the
|
| 11 |
-
see that function's "flat layout (spatial_codes_old_float32)" comment). This file does NOT
|
| 12 |
build spatial codes (that's encoder/render.py's job) and does NOT call any model -- it only
|
| 13 |
reads an already-built spatial_code.json and answers/scores against it.
|
| 14 |
|
|
@@ -55,24 +54,24 @@ sys.modules["vsi_official_eval"] = _official_vsi_eval
|
|
| 55 |
|
| 56 |
def _find_workspace_root(start):
|
| 57 |
"""Walks upward from `start` looking for a real 'data' folder containing a 'spatial
|
| 58 |
-
codes' subfolder -- the actual data root (called /workspace inside this project's
|
| 59 |
original Linux-container environment, but this walk works under ANY real folder name --
|
| 60 |
'workspace', a OneDrive-synced path, whatever the real machine actually calls it).
|
| 61 |
|
| 62 |
This is DELIBERATELY separate from _find_project_root() above: that one finds the CODE
|
| 63 |
repository root (needs harness/ + symbolic/ as siblings); this one finds the DATA root
|
| 64 |
-
(needs data/spatial codes as a descendant). On a real deployment they're often the same
|
| 65 |
directory (this file's own parent, e.g. your real C:\\...\\workspace), but they don't have
|
| 66 |
to be -- someone could keep code and data in genuinely separate trees, so this walk
|
| 67 |
doesn't assume the code repo root IS the workspace root, it looks for the real,
|
| 68 |
-
independent evidence (an actual data/spatial codes folder) instead.
|
| 69 |
|
| 70 |
Returns None (never raises) if no such folder is found within a few levels up -- callers
|
| 71 |
fall back to the hardcoded /workspace/... default in that case, so a machine that
|
| 72 |
genuinely does have /workspace (the original Linux-container case) is unaffected."""
|
| 73 |
d = os.path.abspath(start)
|
| 74 |
for _ in range(6):
|
| 75 |
-
candidate = os.path.join(d, "data", "spatial codes")
|
| 76 |
if os.path.isdir(candidate):
|
| 77 |
return d
|
| 78 |
parent = os.path.dirname(d)
|
|
@@ -86,7 +85,7 @@ _AUTO_WORKSPACE = _find_workspace_root(_HERE)
|
|
| 86 |
|
| 87 |
|
| 88 |
def _default_spatial_codes_dir():
|
| 89 |
-
return "/workspace/data/spatial codes"
|
| 90 |
|
| 91 |
|
| 92 |
def _default_test_jsonl():
|
|
@@ -102,12 +101,12 @@ def _default_results_dir():
|
|
| 102 |
# ==========================================================================================
|
| 103 |
# FETCH -- where a scene's spatial code lives on disk, and how to load+render it.
|
| 104 |
#
|
| 105 |
-
# Auto-detected from a real 'data/spatial codes' folder found by walking upward from this
|
| 106 |
# file (see _find_workspace_root() above) -- works out of the box on any machine/OS, no setup
|
| 107 |
-
# needed, as long as the real folder structure matches (data/spatial codes/, data/VSI-Bench/
|
| 108 |
# or data/vsi benchmark/). Override via environment variables if your layout genuinely
|
| 109 |
# differs (PowerShell example):
|
| 110 |
-
# $env:SYMBOLIC_SPATIAL_CODES_DIR = "D:\some\other\place\spatial codes"
|
| 111 |
# $env:SYMBOLIC_TEST_JSONL = "D:\some\other\place\test.jsonl"
|
| 112 |
# $env:SYMBOLIC_RESULTS_DIR = "D:\some\other\place\results"
|
| 113 |
# ==========================================================================================
|
|
@@ -120,7 +119,7 @@ DEFAULT_TEST_JSONL = os.environ.get("SYMBOLIC_TEST_JSONL", _default_test_jsonl()
|
|
| 120 |
|
| 121 |
def spatial_code_path(scene_id):
|
| 122 |
"""The one place this file looks for a scene's spatial code:
|
| 123 |
-
/workspace/data/spatial codes/<SCENE_ID>.json
|
| 124 |
return os.path.join(SPATIAL_CODES_DIR, f"{scene_id}.json")
|
| 125 |
|
| 126 |
|
|
|
|
| 6 |
multi-scene-orchestrator split: this file never loops over more than one scene on its own).
|
| 7 |
|
| 8 |
FETCHES the spatial code from:
|
| 9 |
+
/workspace/data/spatial codes/segvggt/<SCENE_ID>.json
|
| 10 |
+
(the model-specific on-disk layout). This file does NOT
|
|
|
|
| 11 |
build spatial codes (that's encoder/render.py's job) and does NOT call any model -- it only
|
| 12 |
reads an already-built spatial_code.json and answers/scores against it.
|
| 13 |
|
|
|
|
| 54 |
|
| 55 |
def _find_workspace_root(start):
|
| 56 |
"""Walks upward from `start` looking for a real 'data' folder containing a 'spatial
|
| 57 |
+
codes/segvggt' subfolder -- the actual data root (called /workspace inside this project's
|
| 58 |
original Linux-container environment, but this walk works under ANY real folder name --
|
| 59 |
'workspace', a OneDrive-synced path, whatever the real machine actually calls it).
|
| 60 |
|
| 61 |
This is DELIBERATELY separate from _find_project_root() above: that one finds the CODE
|
| 62 |
repository root (needs harness/ + symbolic/ as siblings); this one finds the DATA root
|
| 63 |
+
(needs data/spatial codes/segvggt as a descendant). On a real deployment they're often the same
|
| 64 |
directory (this file's own parent, e.g. your real C:\\...\\workspace), but they don't have
|
| 65 |
to be -- someone could keep code and data in genuinely separate trees, so this walk
|
| 66 |
doesn't assume the code repo root IS the workspace root, it looks for the real,
|
| 67 |
+
independent evidence (an actual data/spatial codes/segvggt folder) instead.
|
| 68 |
|
| 69 |
Returns None (never raises) if no such folder is found within a few levels up -- callers
|
| 70 |
fall back to the hardcoded /workspace/... default in that case, so a machine that
|
| 71 |
genuinely does have /workspace (the original Linux-container case) is unaffected."""
|
| 72 |
d = os.path.abspath(start)
|
| 73 |
for _ in range(6):
|
| 74 |
+
candidate = os.path.join(d, "data", "spatial codes", "segvggt")
|
| 75 |
if os.path.isdir(candidate):
|
| 76 |
return d
|
| 77 |
parent = os.path.dirname(d)
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
def _default_spatial_codes_dir():
|
| 88 |
+
return "/workspace/data/spatial codes/segvggt"
|
| 89 |
|
| 90 |
|
| 91 |
def _default_test_jsonl():
|
|
|
|
| 101 |
# ==========================================================================================
|
| 102 |
# FETCH -- where a scene's spatial code lives on disk, and how to load+render it.
|
| 103 |
#
|
| 104 |
+
# Auto-detected from a real 'data/spatial codes/segvggt' folder found by walking upward from this
|
| 105 |
# file (see _find_workspace_root() above) -- works out of the box on any machine/OS, no setup
|
| 106 |
+
# needed, as long as the real folder structure matches (data/spatial codes/segvggt/, data/VSI-Bench/
|
| 107 |
# or data/vsi benchmark/). Override via environment variables if your layout genuinely
|
| 108 |
# differs (PowerShell example):
|
| 109 |
+
# $env:SYMBOLIC_SPATIAL_CODES_DIR = "D:\some\other\place\spatial codes\segvggt"
|
| 110 |
# $env:SYMBOLIC_TEST_JSONL = "D:\some\other\place\test.jsonl"
|
| 111 |
# $env:SYMBOLIC_RESULTS_DIR = "D:\some\other\place\results"
|
| 112 |
# ==========================================================================================
|
|
|
|
| 119 |
|
| 120 |
def spatial_code_path(scene_id):
|
| 121 |
"""The one place this file looks for a scene's spatial code:
|
| 122 |
+
/workspace/data/spatial codes/segvggt/<SCENE_ID>.json."""
|
| 123 |
return os.path.join(SPATIAL_CODES_DIR, f"{scene_id}.json")
|
| 124 |
|
| 125 |
|
tests/encoder_tests/conftest.py
CHANGED
|
@@ -4,6 +4,5 @@ from pathlib import Path
|
|
| 4 |
import sys
|
| 5 |
|
| 6 |
ROOT = Path(__file__).resolve().parents[2]
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
sys.path.insert(0, str(ENCODER_ROOT))
|
|
|
|
| 4 |
import sys
|
| 5 |
|
| 6 |
ROOT = Path(__file__).resolve().parents[2]
|
| 7 |
+
if str(ROOT) not in sys.path:
|
| 8 |
+
sys.path.insert(0, str(ROOT))
|
|
|
tests/encoder_tests/test_adapters.py
CHANGED
|
@@ -1,10 +1,49 @@
|
|
| 1 |
import gzip
|
| 2 |
import pickle
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import numpy as np
|
| 5 |
import pytest
|
| 6 |
|
| 7 |
-
import adapters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def _scene():
|
|
@@ -65,6 +104,49 @@ def test_adapt_segvggt_requires_existing_cache(tmp_path):
|
|
| 65 |
adapters.adapt_segvggt(path=str(tmp_path / "missing.npz"))
|
| 66 |
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
def test_adapt_segvggt_rejects_missing_npz_fields(tmp_path):
|
| 69 |
path = tmp_path / "broken.npz"
|
| 70 |
np.savez(path, labels=np.array(["chair"], dtype=object))
|
|
|
|
| 1 |
import gzip
|
| 2 |
import pickle
|
| 3 |
+
import sys
|
| 4 |
+
import types
|
| 5 |
|
| 6 |
import numpy as np
|
| 7 |
import pytest
|
| 8 |
|
| 9 |
+
from encoder import adapters
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_registry_decodes_native_segvggt_dictionary(tmp_path, monkeypatch):
|
| 13 |
+
torch = pytest.importorskip("torch")
|
| 14 |
+
evaluation = types.ModuleType("eval.instance_eval_common")
|
| 15 |
+
evaluation.predict_by_feat_instance = lambda *args, **kwargs: (
|
| 16 |
+
torch.tensor([[1, 0, 0, 0], [0, 1, 0, 0]], dtype=torch.bool),
|
| 17 |
+
torch.tensor([0, 2]),
|
| 18 |
+
torch.ones(2),
|
| 19 |
+
)
|
| 20 |
+
pose = types.ModuleType("segvggt.utils.pose_enc")
|
| 21 |
+
pose.pose_encoding_to_extri_intri = lambda value, size: (
|
| 22 |
+
torch.cat(
|
| 23 |
+
[
|
| 24 |
+
torch.eye(3).reshape(1, 1, 3, 3),
|
| 25 |
+
torch.zeros(1, 1, 3, 1),
|
| 26 |
+
],
|
| 27 |
+
dim=-1,
|
| 28 |
+
),
|
| 29 |
+
torch.eye(3).reshape(1, 1, 3, 3),
|
| 30 |
+
)
|
| 31 |
+
monkeypatch.setitem(sys.modules, "eval.instance_eval_common", evaluation)
|
| 32 |
+
monkeypatch.setitem(sys.modules, "segvggt.utils.pose_enc", pose)
|
| 33 |
+
|
| 34 |
+
path = tmp_path / "scene.pt"
|
| 35 |
+
torch.save(
|
| 36 |
+
{
|
| 37 |
+
"world_points": torch.zeros(1, 1, 2, 2, 3),
|
| 38 |
+
"instance_maps": torch.zeros(1, 2, 1, 2, 2),
|
| 39 |
+
"instance_labels": torch.zeros(1, 2, 4),
|
| 40 |
+
"pose_enc": torch.zeros(1, 1, 9),
|
| 41 |
+
},
|
| 42 |
+
path,
|
| 43 |
+
)
|
| 44 |
+
result = adapters.adapt("segvggt", path=path)
|
| 45 |
+
assert list(result["instances"]) == ["chair"]
|
| 46 |
+
assert result["instances"]["chair"][0]["n"] == 1
|
| 47 |
|
| 48 |
|
| 49 |
def _scene():
|
|
|
|
| 104 |
adapters.adapt_segvggt(path=str(tmp_path / "missing.npz"))
|
| 105 |
|
| 106 |
|
| 107 |
+
def test_adapter_owned_raw_cache_locations(tmp_path, monkeypatch):
|
| 108 |
+
seen = {}
|
| 109 |
+
raw_path = tmp_path / "segvggt" / "scene1.pt"
|
| 110 |
+
raw_path.parent.mkdir()
|
| 111 |
+
raw_path.touch()
|
| 112 |
+
|
| 113 |
+
def fake_segvggt(path):
|
| 114 |
+
seen["segvggt"] = str(path)
|
| 115 |
+
return {
|
| 116 |
+
"world_points": np.zeros((1, 1, 1, 3), np.float32),
|
| 117 |
+
"instance_masks": np.ones((1, 1, 1, 1), bool),
|
| 118 |
+
"labels": np.array(["chair"], dtype=object),
|
| 119 |
+
"camera_positions": np.zeros((1, 3), np.float32),
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
monkeypatch.setattr(adapters, "_decode_segvggt_raw", fake_segvggt)
|
| 123 |
+
adapters.adapt_segvggt(root=str(tmp_path), scene="scene1")
|
| 124 |
+
assert seen["segvggt"] == str(raw_path)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def test_fusion_adapter_resolves_two_native_model_directories(tmp_path, monkeypatch):
|
| 128 |
+
seen = {}
|
| 129 |
+
depth = np.ones((1, 1, 1), np.float32)
|
| 130 |
+
intr = np.eye(3, dtype=np.float32)[None]
|
| 131 |
+
c2w = np.eye(4, dtype=np.float32)[None]
|
| 132 |
+
|
| 133 |
+
def fake_da3(path):
|
| 134 |
+
seen["da3"] = str(path)
|
| 135 |
+
return depth, intr, c2w, None
|
| 136 |
+
|
| 137 |
+
def fake_sam3(path):
|
| 138 |
+
seen["sam3"] = str(path)
|
| 139 |
+
return {"object": {0: {0: np.ones((1, 1), bool)}}}
|
| 140 |
+
|
| 141 |
+
monkeypatch.setattr(adapters, "_load_native_da3", fake_da3)
|
| 142 |
+
monkeypatch.setattr(adapters, "_load_native_sam3", fake_sam3)
|
| 143 |
+
adapters.adapt_da3_sam3(root=str(tmp_path), scene="scene1")
|
| 144 |
+
assert seen == {
|
| 145 |
+
"da3": str(tmp_path / "depth-anything-3" / "scene1.pkl"),
|
| 146 |
+
"sam3": str(tmp_path / "sam3" / "scene1.pt"),
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
|
| 150 |
def test_adapt_segvggt_rejects_missing_npz_fields(tmp_path):
|
| 151 |
path = tmp_path / "broken.npz"
|
| 152 |
np.savez(path, labels=np.array(["chair"], dtype=object))
|
tests/encoder_tests/test_config.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import pytest
|
| 2 |
|
| 3 |
-
import config as C
|
| 4 |
|
| 5 |
|
| 6 |
def test_cache_and_code_paths_are_flat(tmp_path, monkeypatch):
|
|
@@ -10,12 +10,12 @@ def test_cache_and_code_paths_are_flat(tmp_path, monkeypatch):
|
|
| 10 |
assert C.cache_file("scene1", "segvggt") == str(
|
| 11 |
tmp_path / "caches/segvggt/scene1.pkl.gz"
|
| 12 |
)
|
| 13 |
-
assert C.segvggt_cache_file("scene1") == str(tmp_path / "caches/segvggt/scene1.
|
| 14 |
assert C.da3_cache_file("scene1") == str(
|
| 15 |
-
tmp_path / "caches/
|
| 16 |
)
|
| 17 |
assert C.sam3_cache_file("scene1") == str(
|
| 18 |
-
tmp_path / "caches/
|
| 19 |
)
|
| 20 |
assert C.spatial_code_path("scene1") == str(tmp_path / "spatial codes/scene1.json")
|
| 21 |
|
|
|
|
| 1 |
import pytest
|
| 2 |
|
| 3 |
+
from encoder import config as C
|
| 4 |
|
| 5 |
|
| 6 |
def test_cache_and_code_paths_are_flat(tmp_path, monkeypatch):
|
|
|
|
| 10 |
assert C.cache_file("scene1", "segvggt") == str(
|
| 11 |
tmp_path / "caches/segvggt/scene1.pkl.gz"
|
| 12 |
)
|
| 13 |
+
assert C.segvggt_cache_file("scene1") == str(tmp_path / "caches/segvggt/scene1.pt")
|
| 14 |
assert C.da3_cache_file("scene1") == str(
|
| 15 |
+
tmp_path / "caches/depth-anything-3/scene1.pkl"
|
| 16 |
)
|
| 17 |
assert C.sam3_cache_file("scene1") == str(
|
| 18 |
+
tmp_path / "caches/sam3/scene1.pt"
|
| 19 |
)
|
| 20 |
assert C.spatial_code_path("scene1") == str(tmp_path / "spatial codes/scene1.json")
|
| 21 |
|
tests/encoder_tests/test_geometric.py
CHANGED
|
@@ -48,3 +48,35 @@ def test_exact_math_is_integrated_into_geometric_module():
|
|
| 48 |
assert callable(geometric.build_spatial_code_raw)
|
| 49 |
assert callable(geometric.dump_spatial_code)
|
| 50 |
assert not hasattr(geometric, "_reference")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
assert callable(geometric.build_spatial_code_raw)
|
| 49 |
assert callable(geometric.dump_spatial_code)
|
| 50 |
assert not hasattr(geometric, "_reference")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_position_reader_accepts_current_and_legacy_formatting():
|
| 54 |
+
assert geometric.pos3(
|
| 55 |
+
{
|
| 56 |
+
"position": {
|
| 57 |
+
"x coordinate": "1.25 meters",
|
| 58 |
+
"y coordinate": "-2.0 meters",
|
| 59 |
+
"height above floor": "0.5 meters",
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
) == [1.25, -2.0, 0.5]
|
| 63 |
+
assert geometric.pos3(
|
| 64 |
+
{
|
| 65 |
+
"position": {
|
| 66 |
+
"floor_x_meters": 1.25,
|
| 67 |
+
"floor_y_meters": -2.0,
|
| 68 |
+
"height_above_floor_meters": 0.5,
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
) == [1.25, -2.0, 0.5]
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def test_floor_level_v1_v2_math_is_shared(monkeypatch):
|
| 75 |
+
points = np.array([[0, 0, z] for z in [0, 0, 0, 1, 10]], np.float32)
|
| 76 |
+
gravity = np.array([0, 0, 1], np.float32)
|
| 77 |
+
monkeypatch.delenv("VSI_CODE_V2", raising=False)
|
| 78 |
+
v1 = geometric._floor_level(points, gravity)
|
| 79 |
+
monkeypatch.setenv("VSI_CODE_V2", "1")
|
| 80 |
+
v2 = geometric._floor_level(points, gravity)
|
| 81 |
+
assert 0 <= v1 < 0.2
|
| 82 |
+
assert v2 == 0.0
|
tests/encoder_tests/test_launch.py
CHANGED
|
@@ -3,8 +3,8 @@ import sys
|
|
| 3 |
|
| 4 |
import pytest
|
| 5 |
|
| 6 |
-
import config as C
|
| 7 |
-
import launch
|
| 8 |
|
| 9 |
|
| 10 |
def test_scenes_deduplicates_manifest_in_order(tmp_path, monkeypatch):
|
|
|
|
| 3 |
|
| 4 |
import pytest
|
| 5 |
|
| 6 |
+
from encoder import config as C
|
| 7 |
+
from encoder import launch
|
| 8 |
|
| 9 |
|
| 10 |
def test_scenes_deduplicates_manifest_in_order(tmp_path, monkeypatch):
|
tests/encoder_tests/test_render.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import json
|
| 2 |
|
| 3 |
-
import config as C
|
| 4 |
-
import render
|
| 5 |
|
| 6 |
|
| 7 |
def test_build_spatial_code_uses_cached_geometry(monkeypatch):
|
|
|
|
| 1 |
import json
|
| 2 |
|
| 3 |
+
from encoder import config as C
|
| 4 |
+
from encoder import render
|
| 5 |
|
| 6 |
|
| 7 |
def test_build_spatial_code_uses_cached_geometry(monkeypatch):
|
tests/encoder_tests/test_run.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import gzip
|
| 2 |
import pickle
|
| 3 |
|
| 4 |
-
import adapters
|
| 5 |
-
import config as C
|
| 6 |
-
import run
|
| 7 |
|
| 8 |
|
| 9 |
def _geometry():
|
|
@@ -30,11 +30,7 @@ def test_cache_or_load_reads_flat_cache(tmp_path, monkeypatch):
|
|
| 30 |
|
| 31 |
def test_cache_or_load_builds_and_writes_cache(tmp_path, monkeypatch):
|
| 32 |
monkeypatch.setattr(C, "CACHE_ROOT", tmp_path / "caches")
|
| 33 |
-
monkeypatch.
|
| 34 |
-
monkeypatch.setattr(run, "_adapter_kwargs", lambda scene, model: {"scene": scene})
|
| 35 |
-
monkeypatch.setattr(
|
| 36 |
-
adapters, "adapt_fake", lambda **kwargs: _geometry(), raising=False
|
| 37 |
-
)
|
| 38 |
|
| 39 |
result, how = run.cache_or_load("s1", "fake")
|
| 40 |
|
|
|
|
| 1 |
import gzip
|
| 2 |
import pickle
|
| 3 |
|
| 4 |
+
from encoder import adapters
|
| 5 |
+
from encoder import config as C
|
| 6 |
+
from encoder import run
|
| 7 |
|
| 8 |
|
| 9 |
def _geometry():
|
|
|
|
| 30 |
|
| 31 |
def test_cache_or_load_builds_and_writes_cache(tmp_path, monkeypatch):
|
| 32 |
monkeypatch.setattr(C, "CACHE_ROOT", tmp_path / "caches")
|
| 33 |
+
monkeypatch.setitem(adapters.RAW_ADAPTERS, "fake", lambda **kwargs: _geometry())
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
result, how = run.cache_or_load("s1", "fake")
|
| 36 |
|
tests/inference_tests/test_adapter_runtime.py
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import pytest
|
| 3 |
|
|
@@ -20,7 +24,7 @@ def test_load_model_validates_repository_and_checkpoint(tmp_path):
|
|
| 20 |
def test_run_scene_requires_loaded_model(tmp_path):
|
| 21 |
adapter = adapters.SegVGGTAdapter()
|
| 22 |
with pytest.raises(RuntimeError, match=r"load_model\(\)"):
|
| 23 |
-
adapter.run_scene("video.mp4", tmp_path / "scene.
|
| 24 |
|
| 25 |
|
| 26 |
def test_read_video_rejects_unopenable_file():
|
|
@@ -28,7 +32,7 @@ def test_read_video_rejects_unopenable_file():
|
|
| 28 |
adapters.SegVGGTAdapter._read_video("/missing/video.mp4", 1)
|
| 29 |
|
| 30 |
|
| 31 |
-
def
|
| 32 |
torch = pytest.importorskip("torch")
|
| 33 |
adapter = adapters.SegVGGTAdapter()
|
| 34 |
adapter.device = torch.device("cpu")
|
|
@@ -43,42 +47,116 @@ def test_run_scene_writes_expected_npz_atomically(tmp_path, monkeypatch):
|
|
| 43 |
class Model:
|
| 44 |
def __call__(self, images):
|
| 45 |
return {
|
| 46 |
-
"instance_maps": torch.zeros(
|
|
|
|
|
|
|
| 47 |
"instance_labels": torch.zeros((1, 2, 3)),
|
| 48 |
"depth": torch.ones((1, 1, 2, 2)),
|
| 49 |
"pose_enc": torch.zeros((1, 1, 4)),
|
| 50 |
}
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
def decode_pose(pose, shape):
|
| 57 |
-
return torch.eye(4).reshape(1, 1, 4, 4), torch.eye(3).reshape(1, 1, 3, 3)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
adapter.model = Model()
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
torch.nn.functional,
|
| 69 |
-
predict,
|
| 70 |
-
unproject,
|
| 71 |
-
inverse,
|
| 72 |
-
decode_pose,
|
| 73 |
-
)
|
| 74 |
-
output = tmp_path / "nested" / "scene.npz"
|
| 75 |
adapter.run_scene("video.mp4", output, 1)
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
import sys
|
| 3 |
+
from types import SimpleNamespace
|
| 4 |
+
|
| 5 |
import numpy as np
|
| 6 |
import pytest
|
| 7 |
|
|
|
|
| 24 |
def test_run_scene_requires_loaded_model(tmp_path):
|
| 25 |
adapter = adapters.SegVGGTAdapter()
|
| 26 |
with pytest.raises(RuntimeError, match=r"load_model\(\)"):
|
| 27 |
+
adapter.run_scene("video.mp4", tmp_path / "scene.pt", 1)
|
| 28 |
|
| 29 |
|
| 30 |
def test_read_video_rejects_unopenable_file():
|
|
|
|
| 32 |
adapters.SegVGGTAdapter._read_video("/missing/video.mp4", 1)
|
| 33 |
|
| 34 |
|
| 35 |
+
def test_run_scene_preserves_raw_dtypes_and_encoder_geometry(tmp_path, monkeypatch):
|
| 36 |
torch = pytest.importorskip("torch")
|
| 37 |
adapter = adapters.SegVGGTAdapter()
|
| 38 |
adapter.device = torch.device("cpu")
|
|
|
|
| 47 |
class Model:
|
| 48 |
def __call__(self, images):
|
| 49 |
return {
|
| 50 |
+
"instance_maps": torch.zeros(
|
| 51 |
+
(1, 2, 1, 2, 2), dtype=torch.bfloat16
|
| 52 |
+
),
|
| 53 |
"instance_labels": torch.zeros((1, 2, 3)),
|
| 54 |
"depth": torch.ones((1, 1, 2, 2)),
|
| 55 |
"pose_enc": torch.zeros((1, 1, 4)),
|
| 56 |
}
|
| 57 |
|
| 58 |
+
adapter.model = Model()
|
| 59 |
+
adapter.runtime = torch
|
| 60 |
+
output = tmp_path / "nested" / "scene.pt"
|
| 61 |
+
adapter.run_scene("video.mp4", output, 1)
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
assert output.is_file()
|
| 64 |
+
assert not output.with_suffix(".pt.tmp").exists()
|
| 65 |
+
cache = torch.load(output, map_location="cpu", weights_only=False)
|
| 66 |
+
assert set(cache) == {
|
| 67 |
+
"instance_maps",
|
| 68 |
+
"instance_labels",
|
| 69 |
+
"depth",
|
| 70 |
+
"pose_enc",
|
| 71 |
+
}
|
| 72 |
+
assert cache["instance_maps"].dtype == torch.bfloat16
|
| 73 |
+
assert cache["depth"].dtype == torch.float32
|
| 74 |
+
assert all(value.device.type == "cpu" for value in cache.values())
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def test_da3_preserves_native_prediction_object(tmp_path, monkeypatch):
|
| 78 |
+
adapter = adapters.DepthAnything3Adapter()
|
| 79 |
+
prediction = SimpleNamespace(
|
| 80 |
+
depth=np.ones((2, 3, 4), dtype=np.float32),
|
| 81 |
+
conf=np.ones((2, 3, 4), dtype=np.float16),
|
| 82 |
+
is_metric=True,
|
| 83 |
+
)
|
| 84 |
|
| 85 |
+
class Model:
|
| 86 |
+
def inference(self, images, export_dir):
|
| 87 |
+
assert images == ["frame"]
|
| 88 |
+
assert export_dir is None
|
| 89 |
+
return prediction
|
| 90 |
|
| 91 |
adapter.model = Model()
|
| 92 |
+
monkeypatch.setattr(adapter, "_read_video", lambda path, count: ["frame"])
|
| 93 |
+
output = tmp_path / "depth-anything-3" / "scene.pkl"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
adapter.run_scene("video.mp4", output, 1)
|
| 95 |
|
| 96 |
+
with output.open("rb") as stream:
|
| 97 |
+
restored = pickle.load(stream)
|
| 98 |
+
assert vars(restored).keys() == vars(prediction).keys()
|
| 99 |
+
assert restored.depth.dtype == np.float32
|
| 100 |
+
assert restored.conf.dtype == np.float16
|
| 101 |
+
assert restored.is_metric is True
|
| 102 |
+
assert not output.with_suffix(".pkl.tmp").exists()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def test_sam3_preserves_independent_image_responses_without_tracking(
|
| 106 |
+
tmp_path, monkeypatch
|
| 107 |
+
):
|
| 108 |
+
states = []
|
| 109 |
+
monkeypatch.setitem(
|
| 110 |
+
sys.modules,
|
| 111 |
+
"PIL",
|
| 112 |
+
SimpleNamespace(Image=SimpleNamespace(fromarray=lambda frame: frame)),
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
class Processor:
|
| 116 |
+
def set_image(self, image):
|
| 117 |
+
state = {"frame": len(states), "shape": image.shape}
|
| 118 |
+
states.append(state)
|
| 119 |
+
return state
|
| 120 |
+
|
| 121 |
+
def set_text_prompt(self, state, prompt):
|
| 122 |
+
assert prompt == "chair"
|
| 123 |
+
return {"state": state, "masks": np.ones((1, 2, 2), np.float32)}
|
| 124 |
+
|
| 125 |
+
class InferenceMode:
|
| 126 |
+
def __enter__(self):
|
| 127 |
+
return self
|
| 128 |
+
|
| 129 |
+
def __exit__(self, *args):
|
| 130 |
+
return False
|
| 131 |
+
|
| 132 |
+
class Runtime:
|
| 133 |
+
@staticmethod
|
| 134 |
+
def inference_mode():
|
| 135 |
+
return InferenceMode()
|
| 136 |
+
|
| 137 |
+
@staticmethod
|
| 138 |
+
def save(value, path):
|
| 139 |
+
with open(path, "wb") as stream:
|
| 140 |
+
pickle.dump(value, stream)
|
| 141 |
+
|
| 142 |
+
adapter = adapters.SAM3Adapter(prompt="chair")
|
| 143 |
+
adapter.model = object()
|
| 144 |
+
adapter.processor = Processor()
|
| 145 |
+
adapter.runtime = Runtime()
|
| 146 |
+
monkeypatch.setattr(
|
| 147 |
+
adapters.DepthAnything3Adapter,
|
| 148 |
+
"_read_video",
|
| 149 |
+
lambda path, count: [
|
| 150 |
+
np.zeros((2, 3, 3), np.uint8),
|
| 151 |
+
np.ones((2, 3, 3), np.uint8),
|
| 152 |
+
],
|
| 153 |
+
)
|
| 154 |
+
output = tmp_path / "sam3" / "scene.pt"
|
| 155 |
+
adapter.run_scene("video.mp4", output, 2)
|
| 156 |
+
|
| 157 |
+
with output.open("rb") as stream:
|
| 158 |
+
restored = pickle.load(stream)
|
| 159 |
+
assert [response["state"]["frame"] for response in restored] == [0, 1]
|
| 160 |
+
assert all(response["masks"].dtype == np.float32 for response in restored)
|
| 161 |
+
assert len(states) == 2
|
| 162 |
+
assert not output.with_suffix(".pt.tmp").exists()
|
tests/inference_tests/test_gpu_integration.py
CHANGED
|
@@ -3,7 +3,6 @@
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
import numpy as np
|
| 7 |
import pytest
|
| 8 |
|
| 9 |
from inference import adapters
|
|
@@ -14,24 +13,29 @@ from inference import run
|
|
| 14 |
os.environ.get("VSI_RUN_GPU_TESTS") != "1",
|
| 15 |
reason="set VSI_RUN_GPU_TESTS=1 to run real SegVGGT inference",
|
| 16 |
)
|
| 17 |
-
def
|
| 18 |
-
|
|
|
|
| 19 |
scene = str(json.loads(next(manifest))["scene_name"])
|
| 20 |
adapter = adapters.get_adapter("segvggt")
|
| 21 |
adapter.load_model("cuda:0")
|
| 22 |
-
output = tmp_path / f"{scene}.
|
| 23 |
adapter.run_scene(
|
| 24 |
-
run.
|
| 25 |
str(output),
|
| 26 |
-
run.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
)
|
| 28 |
-
with np.load(output, allow_pickle=True) as cache:
|
| 29 |
-
assert set(cache.files) == {
|
| 30 |
-
"world_points",
|
| 31 |
-
"instance_masks",
|
| 32 |
-
"labels",
|
| 33 |
-
"frame_times",
|
| 34 |
-
"camera_positions",
|
| 35 |
-
}
|
| 36 |
-
assert cache["world_points"].shape[-1] == 3
|
| 37 |
-
assert cache["instance_masks"].dtype == bool
|
|
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
|
|
|
|
| 6 |
import pytest
|
| 7 |
|
| 8 |
from inference import adapters
|
|
|
|
| 13 |
os.environ.get("VSI_RUN_GPU_TESTS") != "1",
|
| 14 |
reason="set VSI_RUN_GPU_TESTS=1 to run real SegVGGT inference",
|
| 15 |
)
|
| 16 |
+
def test_real_segvggt_scene_preserves_native_prediction_dictionary(tmp_path):
|
| 17 |
+
torch = pytest.importorskip("torch")
|
| 18 |
+
with open(run.inference_config.JSONL) as manifest:
|
| 19 |
scene = str(json.loads(next(manifest))["scene_name"])
|
| 20 |
adapter = adapters.get_adapter("segvggt")
|
| 21 |
adapter.load_model("cuda:0")
|
| 22 |
+
output = tmp_path / f"{scene}.pt"
|
| 23 |
adapter.run_scene(
|
| 24 |
+
run.inference_config.video_path(scene),
|
| 25 |
str(output),
|
| 26 |
+
run.inference_config.FRAMES_PER_VIDEO,
|
| 27 |
+
)
|
| 28 |
+
cache = torch.load(output, map_location="cpu", weights_only=False)
|
| 29 |
+
assert isinstance(cache, dict)
|
| 30 |
+
assert {
|
| 31 |
+
"pose_enc",
|
| 32 |
+
"depth",
|
| 33 |
+
"world_points",
|
| 34 |
+
"instance_maps",
|
| 35 |
+
"instance_labels",
|
| 36 |
+
}.issubset(cache)
|
| 37 |
+
assert all(
|
| 38 |
+
value.device.type == "cpu"
|
| 39 |
+
for value in cache.values()
|
| 40 |
+
if isinstance(value, torch.Tensor)
|
| 41 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/inference_tests/test_inference.py
CHANGED
|
@@ -8,6 +8,8 @@ from inference import run
|
|
| 8 |
|
| 9 |
|
| 10 |
class FakeAdapter:
|
|
|
|
|
|
|
| 11 |
def __init__(self):
|
| 12 |
self.calls = []
|
| 13 |
|
|
@@ -19,21 +21,40 @@ class FakeAdapter:
|
|
| 19 |
|
| 20 |
|
| 21 |
def test_adapter_registry():
|
| 22 |
-
assert adapters.available_models() == (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
assert isinstance(adapters.get_adapter("segvggt"), adapters.SegVGGTAdapter)
|
| 24 |
with pytest.raises(KeyError, match="unknown inference model"):
|
| 25 |
adapters.get_adapter("unknown")
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
def test_run_scene_builds_then_skips(tmp_path, monkeypatch):
|
| 29 |
-
monkeypatch.setattr(run.
|
| 30 |
monkeypatch.setattr(
|
| 31 |
-
run.
|
| 32 |
)
|
| 33 |
adapter = FakeAdapter()
|
| 34 |
assert run.run_scene("scene1", adapter=adapter) == (
|
| 35 |
"built",
|
| 36 |
-
str(tmp_path / "segvggt" / "scene1.
|
| 37 |
)
|
| 38 |
assert run.run_scene("scene1", adapter=adapter)[0] == "skipped"
|
| 39 |
assert len(adapter.calls) == 1
|
|
@@ -44,7 +65,7 @@ def test_scenes_deduplicates_manifest(tmp_path, monkeypatch):
|
|
| 44 |
manifest.write_text(
|
| 45 |
'{"scene_name": "s1"}\n{"scene_name": "s2"}\n{"scene_name": "s1"}\n'
|
| 46 |
)
|
| 47 |
-
monkeypatch.setattr(launch.
|
| 48 |
assert launch.scenes() == ["s1", "s2"]
|
| 49 |
|
| 50 |
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
class FakeAdapter:
|
| 11 |
+
model = object()
|
| 12 |
+
|
| 13 |
def __init__(self):
|
| 14 |
self.calls = []
|
| 15 |
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
def test_adapter_registry():
|
| 24 |
+
assert adapters.available_models() == (
|
| 25 |
+
"depth-anything-3",
|
| 26 |
+
"sam3",
|
| 27 |
+
"segvggt",
|
| 28 |
+
)
|
| 29 |
+
assert isinstance(
|
| 30 |
+
adapters.get_adapter("depth-anything-3"),
|
| 31 |
+
adapters.DepthAnything3Adapter,
|
| 32 |
+
)
|
| 33 |
+
assert isinstance(adapters.get_adapter("sam3"), adapters.SAM3Adapter)
|
| 34 |
assert isinstance(adapters.get_adapter("segvggt"), adapters.SegVGGTAdapter)
|
| 35 |
with pytest.raises(KeyError, match="unknown inference model"):
|
| 36 |
adapters.get_adapter("unknown")
|
| 37 |
|
| 38 |
|
| 39 |
+
def test_native_output_paths(tmp_path, monkeypatch):
|
| 40 |
+
monkeypatch.setattr(run.inference_config, "CACHE_ROOT", tmp_path)
|
| 41 |
+
assert run.output_path("scene1", "depth-anything-3") == str(
|
| 42 |
+
tmp_path / "depth-anything-3" / "scene1.pkl"
|
| 43 |
+
)
|
| 44 |
+
assert run.output_path("scene1", "sam3") == str(
|
| 45 |
+
tmp_path / "sam3" / "scene1.pt"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
def test_run_scene_builds_then_skips(tmp_path, monkeypatch):
|
| 50 |
+
monkeypatch.setattr(run.inference_config, "CACHE_ROOT", tmp_path)
|
| 51 |
monkeypatch.setattr(
|
| 52 |
+
run.inference_config, "video_path", lambda scene: f"/videos/{scene}.mp4"
|
| 53 |
)
|
| 54 |
adapter = FakeAdapter()
|
| 55 |
assert run.run_scene("scene1", adapter=adapter) == (
|
| 56 |
"built",
|
| 57 |
+
str(tmp_path / "segvggt" / "scene1.pt"),
|
| 58 |
)
|
| 59 |
assert run.run_scene("scene1", adapter=adapter)[0] == "skipped"
|
| 60 |
assert len(adapter.calls) == 1
|
|
|
|
| 65 |
manifest.write_text(
|
| 66 |
'{"scene_name": "s1"}\n{"scene_name": "s2"}\n{"scene_name": "s1"}\n'
|
| 67 |
)
|
| 68 |
+
monkeypatch.setattr(launch.inference_config, "JSONL", manifest)
|
| 69 |
assert launch.scenes() == ["s1", "s2"]
|
| 70 |
|
| 71 |
|
tests/inference_tests/test_launch_runtime.py
CHANGED
|
@@ -84,9 +84,9 @@ def test_worker_reports_scene_failure_and_continues(monkeypatch):
|
|
| 84 |
|
| 85 |
|
| 86 |
def test_run_scene_rebuild_overwrites_existing_cache(tmp_path, monkeypatch):
|
| 87 |
-
monkeypatch.setattr(run.
|
| 88 |
-
monkeypatch.setattr(run.
|
| 89 |
-
destination = tmp_path / "segvggt" / "s1.
|
| 90 |
destination.parent.mkdir()
|
| 91 |
destination.write_bytes(b"old")
|
| 92 |
calls = []
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
def test_run_scene_rebuild_overwrites_existing_cache(tmp_path, monkeypatch):
|
| 87 |
+
monkeypatch.setattr(run.inference_config, "CACHE_ROOT", tmp_path)
|
| 88 |
+
monkeypatch.setattr(run.inference_config, "video_path", lambda scene: f"/{scene}.mp4")
|
| 89 |
+
destination = tmp_path / "segvggt" / "s1.pt"
|
| 90 |
destination.parent.mkdir()
|
| 91 |
destination.write_bytes(b"old")
|
| 92 |
calls = []
|
tests/symbolic_tests/test_run.py
CHANGED
|
@@ -7,7 +7,9 @@ import symbolic_run_tests as symbolic_run
|
|
| 7 |
|
| 8 |
def test_find_workspace_root_uses_spatial_codes_folder(tmp_path):
|
| 9 |
start = tmp_path / "project" / "symbolic"
|
| 10 |
-
(tmp_path / "project" / "data" / "spatial codes").mkdir(
|
|
|
|
|
|
|
| 11 |
start.mkdir()
|
| 12 |
assert symbolic_run._find_workspace_root(start) == str(tmp_path / "project")
|
| 13 |
|
|
|
|
| 7 |
|
| 8 |
def test_find_workspace_root_uses_spatial_codes_folder(tmp_path):
|
| 9 |
start = tmp_path / "project" / "symbolic"
|
| 10 |
+
(tmp_path / "project" / "data" / "spatial codes" / "segvggt").mkdir(
|
| 11 |
+
parents=True
|
| 12 |
+
)
|
| 13 |
start.mkdir()
|
| 14 |
assert symbolic_run._find_workspace_root(start) == str(tmp_path / "project")
|
| 15 |
|