Add files using upload-large-folder tool
Browse files- encoder/__pycache__/geometric.cpython-311.pyc +2 -2
- encoder/config.py +4 -5
- encoder/geometric.py +71 -38
- encoder/ground_truth.py +12 -7
- encoder/launch.py +5 -14
- harness/A/__init__.py +1 -3
- harness/A/__pycache__/models.cpython-311.pyc +0 -0
- harness/A/__pycache__/sweep.cpython-311.pyc +0 -0
- harness/A/run.py +61 -19
- harness/B/__pycache__/prompts.cpython-311.pyc +0 -0
- harness/B/__pycache__/spatial_codes.cpython-311.pyc +0 -0
- harness/B/__pycache__/sweep.cpython-311.pyc +0 -0
- harness/B/launch.py +132 -41
- harness/B/spatial_codes.py +3 -1
- harness/B/sweep.py +84 -31
encoder/__pycache__/geometric.cpython-311.pyc
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3ac64db9babd5e880fa52f32cd0d05bb460afaef9f1568463f9cee478650ec66
|
| 3 |
+
size 134984
|
encoder/config.py
CHANGED
|
@@ -5,7 +5,6 @@ from __future__ import annotations
|
|
| 5 |
import os
|
| 6 |
from pathlib import Path
|
| 7 |
|
| 8 |
-
|
| 9 |
MODEL = "sam3+depth-anything-3"
|
| 10 |
FRAMES_PER_VIDEO = int(os.environ.get("VSI_FRAMES_PER_VIDEO", "32"))
|
| 11 |
FPS = float(os.environ.get("VSI_FPS", "6"))
|
|
@@ -36,7 +35,9 @@ def _validate_dimensions(depth, input_selection, tracking, frame_count):
|
|
| 36 |
f"unknown input selection {input_selection!r}; expected {INPUT_SELECTIONS}"
|
| 37 |
)
|
| 38 |
if tracking not in TRACKING_MODES:
|
| 39 |
-
raise ValueError(
|
|
|
|
|
|
|
| 40 |
if frame_count < 1:
|
| 41 |
raise ValueError("frame count must be positive")
|
| 42 |
|
|
@@ -85,9 +86,7 @@ def da3_cache_file(scene, depth, input_selection, frame_count=FRAMES_PER_VIDEO):
|
|
| 85 |
return str(directory / str(frame_count) / f"{scene}.pkl")
|
| 86 |
|
| 87 |
|
| 88 |
-
def sam3_cache_file(
|
| 89 |
-
scene, input_selection, tracking, frame_count=FRAMES_PER_VIDEO
|
| 90 |
-
):
|
| 91 |
"""Return one native SAM3 cache path for a specific set of input dimensions."""
|
| 92 |
_validate_dimensions("relative", input_selection, tracking, frame_count)
|
| 93 |
directory = CACHE_ROOT / "sam3" / tracking / input_selection
|
|
|
|
| 5 |
import os
|
| 6 |
from pathlib import Path
|
| 7 |
|
|
|
|
| 8 |
MODEL = "sam3+depth-anything-3"
|
| 9 |
FRAMES_PER_VIDEO = int(os.environ.get("VSI_FRAMES_PER_VIDEO", "32"))
|
| 10 |
FPS = float(os.environ.get("VSI_FPS", "6"))
|
|
|
|
| 35 |
f"unknown input selection {input_selection!r}; expected {INPUT_SELECTIONS}"
|
| 36 |
)
|
| 37 |
if tracking not in TRACKING_MODES:
|
| 38 |
+
raise ValueError(
|
| 39 |
+
f"unknown tracking mode {tracking!r}; expected {TRACKING_MODES}"
|
| 40 |
+
)
|
| 41 |
if frame_count < 1:
|
| 42 |
raise ValueError("frame count must be positive")
|
| 43 |
|
|
|
|
| 86 |
return str(directory / str(frame_count) / f"{scene}.pkl")
|
| 87 |
|
| 88 |
|
| 89 |
+
def sam3_cache_file(scene, input_selection, tracking, frame_count=FRAMES_PER_VIDEO):
|
|
|
|
|
|
|
| 90 |
"""Return one native SAM3 cache path for a specific set of input dimensions."""
|
| 91 |
_validate_dimensions("relative", input_selection, tracking, frame_count)
|
| 92 |
directory = CACHE_ROOT / "sam3" / tracking / input_selection
|
encoder/geometric.py
CHANGED
|
@@ -31,7 +31,6 @@ import json
|
|
| 31 |
import numpy as np
|
| 32 |
import cv2
|
| 33 |
|
| 34 |
-
|
| 35 |
# ==========================================================================================
|
| 36 |
# CONSTANTS -- geometry-cleanup knobs, merged in from perceptual.py. Env-tunable levers that
|
| 37 |
# affect only the math below (build_instances/backproject_frame/etc.), never model inference.
|
|
@@ -125,7 +124,8 @@ def room_gravity(
|
|
| 125 |
):
|
| 126 |
"""Robust UP vector = normal of the RANSAC floor plane (a real physical plane), oriented toward
|
| 127 |
the cameras. Works when the reconstruction is tilted/drifted (ScanNet++) where argmin-extent fails.
|
| 128 |
-
Floor = large planar support with most non-inlier mass on ONE side. Returns (gravity_unit_vec, axis).
|
|
|
|
| 129 |
points = []
|
| 130 |
for f in range(0, len(depth), fstride):
|
| 131 |
height, width = depth[f].shape
|
|
@@ -218,7 +218,8 @@ def _floor_basis(up_vec):
|
|
| 218 |
floor_x world axis projected onto the gravity plane (v the old floor_y axis), so this frame
|
| 219 |
differs from the old axis-drop frame ONLY by the tilt correction -- NO arbitrary in-plane
|
| 220 |
rotation (aligned scenes stay put; only tilt gets corrected). Objects / camera / room_outline
|
| 221 |
-
all share this one gravity-plane frame; floor_area is rotation-invariant so it matches too.
|
|
|
|
| 222 |
g = np.asarray(up_vec, np.float64)
|
| 223 |
g = g / (np.linalg.norm(g) + 1e-12)
|
| 224 |
up_ax = int(np.argmax(np.abs(g)))
|
|
@@ -274,8 +275,10 @@ def _find_cls(name, classes):
|
|
| 274 |
name_tokens = set(name.split())
|
| 275 |
for c in classes:
|
| 276 |
class_tokens = set(c.split())
|
| 277 |
-
if
|
| 278 |
-
name_tokens
|
|
|
|
|
|
|
| 279 |
):
|
| 280 |
return c
|
| 281 |
return None
|
|
@@ -397,7 +400,8 @@ def answer_route(ql, cents, up_vec, up_ax):
|
|
| 397 |
def _sor(pts, k=16, std=2.0, cap=4000):
|
| 398 |
"""Statistical outlier removal: drop points whose mean distance to their k nearest neighbors exceeds
|
| 399 |
mean + std*sigma. Removes mask-bleed / depth-speckle points that corrupt a literal closest-point min.
|
| 400 |
-
k=16 and std=2 are universal robust-statistics defaults -- NOT tuned to VSI (no benchmark-fit knob).
|
|
|
|
| 401 |
from scipy.spatial import cKDTree
|
| 402 |
|
| 403 |
if len(pts) < k + 2:
|
|
@@ -412,7 +416,8 @@ def _sor(pts, k=16, std=2.0, cap=4000):
|
|
| 412 |
def _main_cluster(pts):
|
| 413 |
"""Keep the object's dominant spatial cluster. Coherent mask-bleed onto a SPATIALLY-SEPARATED adjacent
|
| 414 |
object forms a disconnected component (a gap separates two objects); the true object is the largest one.
|
| 415 |
-
Linkage scale self-calibrates from the cloud's own nearest-neighbor spacing -- no fixed distance.
|
|
|
|
| 416 |
from scipy.spatial import cKDTree
|
| 417 |
|
| 418 |
if len(pts) < 30:
|
|
@@ -448,7 +453,8 @@ def _clean(inst, cap=4000):
|
|
| 448 |
(1) per-point DA3 confidence: boundary mask-bleed = depth discontinuity = LOW conf -> drop below the
|
| 449 |
object's OWN median confidence (data-derived cut);
|
| 450 |
(2) statistical density outlier removal on the survivors;
|
| 451 |
-
(3) dominant spatial cluster: coherent bleed onto a separated adjacent object is a disconnected cluster.
|
|
|
|
| 452 |
if inst.get("_cleanpts") is not None:
|
| 453 |
return inst["_cleanpts"]
|
| 454 |
pts = inst["pts"]
|
|
@@ -474,7 +480,8 @@ def answer_closest_distance(instances_a, instances_b, k=4000):
|
|
| 474 |
"""Closest distance between the two objects' point clouds ('closest point of each object'). Points are
|
| 475 |
cleaned by _clean (self-calibrated per-object confidence + density) then exact nearest-neighbor min via
|
| 476 |
KD-tree, so mask-bleed/speckle can't collapse the answer. NOTE: VSI's GT is box-to-box on CLEAN annotation
|
| 477 |
-
boxes; the residual gap is object-segmentation quality (bleed), not this formula -- see _clean docstring.
|
|
|
|
| 478 |
points_a = _clean(_rep(instances_a), cap=k)
|
| 479 |
points_b = _clean(_rep(instances_b), cap=k)
|
| 480 |
if len(points_a) == 0 or len(points_b) == 0:
|
|
@@ -521,7 +528,8 @@ def refine_mask(mask, rgb):
|
|
| 521 |
"""Snap a coarse SAM3 mask boundary to the RGB color edge (appearance-guided). This clips the same-depth
|
| 522 |
bleed that depth CANNOT see: where the halo crosses onto a differently-colored neighbor, the color edge
|
| 523 |
cuts it. Params are DERIVED, not tuned -- radius from frame scale, smoothness from the image's own color
|
| 524 |
-
variance (same MAD-style principle as depth_edges). No model, no GPU. Falls back to grabCut, then erode.
|
|
|
|
| 525 |
if mask.shape[:2] != rgb.shape[:2]:
|
| 526 |
mask = cv2.resize(
|
| 527 |
mask.astype(np.uint8),
|
|
@@ -576,7 +584,8 @@ def backproject_frame(
|
|
| 576 |
valid_f: optional precomputed (isfinite & >0) depth mask, reused across all masks of a frame.
|
| 577 |
return_conf: also return the (M,) DA3 confidence of each kept point (for per-point noise-aware cleaning).
|
| 578 |
edges_f: optional per-frame depth-edge map; if given, keep the mask's largest depth-coherent component
|
| 579 |
-
(cuts mask-bleed onto adjacent objects at the depth boundary, per frame, before back-projection).
|
|
|
|
| 580 |
height, width = depth_f.shape
|
| 581 |
empty = (
|
| 582 |
(np.empty((0, 3), np.float32), np.empty((0,), np.float32))
|
|
@@ -1043,7 +1052,8 @@ def dump_spatial_code(code, path):
|
|
| 1043 |
"appearance order" is written as one compact line instead of one line per entry -- it's a
|
| 1044 |
single ordered sequence meant to be scanned, not structured data meant to be read field by
|
| 1045 |
field like the rest of the code. Every writer of spatial_code.json should go through this
|
| 1046 |
-
(not a bare json.dump) so the on-disk format and the prompt-time format never drift apart.
|
|
|
|
| 1047 |
body = dict(code)
|
| 1048 |
ao = body.pop("appearance order", None)
|
| 1049 |
text = json.dumps(body, indent=1).rstrip()
|
|
@@ -1344,15 +1354,11 @@ def _compact_oriented_box(instance, u, v, g, floor_level):
|
|
| 1344 |
points = _canonical_clean(instance)
|
| 1345 |
if not len(points):
|
| 1346 |
points = instance["pts"]
|
| 1347 |
-
room_points = np.stack(
|
| 1348 |
-
[points @ u, points @ v, points @ g - floor_level], axis=1
|
| 1349 |
-
)
|
| 1350 |
horizontal = room_points[:, :2]
|
| 1351 |
centered = horizontal - np.median(horizontal, axis=0)
|
| 1352 |
if len(centered) > 5000:
|
| 1353 |
-
centered = centered[
|
| 1354 |
-
np.random.RandomState(0).choice(len(centered), 5000, False)
|
| 1355 |
-
]
|
| 1356 |
try:
|
| 1357 |
_, _, rotation = np.linalg.svd(
|
| 1358 |
centered - centered.mean(axis=0), full_matrices=False
|
|
@@ -1387,7 +1393,9 @@ def _compact_oriented_box(instance, u, v, g, floor_level):
|
|
| 1387 |
upper = np.percentile(projected, 98, axis=0)
|
| 1388 |
centers.append((lower + upper) / 2)
|
| 1389 |
dimensions.append(np.maximum(upper - lower, 0.0))
|
| 1390 |
-
full_dimensions.append(
|
|
|
|
|
|
|
| 1391 |
weights.append(len(observation))
|
| 1392 |
if not centers:
|
| 1393 |
projected = room_points @ orientation.T
|
|
@@ -1417,7 +1425,9 @@ def _compact_oriented_box(instance, u, v, g, floor_level):
|
|
| 1417 |
# the short-axis ship's one 32f caveat).
|
| 1418 |
core_centers, core_weights = centers, weights
|
| 1419 |
if len(centers) >= 4:
|
| 1420 |
-
features = np.concatenate(
|
|
|
|
|
|
|
| 1421 |
median = np.median(features, axis=0)
|
| 1422 |
deviation = np.abs(features - median)
|
| 1423 |
scale = 1.4826 * np.median(deviation, axis=0)
|
|
@@ -1443,7 +1453,10 @@ def _compact_oriented_box(instance, u, v, g, floor_level):
|
|
| 1443 |
full_dimensions = full_dimensions[consistent]
|
| 1444 |
weights = weights[consistent]
|
| 1445 |
box_center_local = np.array(
|
| 1446 |
-
[
|
|
|
|
|
|
|
|
|
|
| 1447 |
)
|
| 1448 |
# Size each axis by a HIGH percentile (0.90) of the mutually-consistent observed extents,
|
| 1449 |
# not the 75th. A partial/occluded/foreshortened view of an object can only measure a
|
|
@@ -1488,7 +1501,10 @@ def _compact_oriented_box(instance, u, v, g, floor_level):
|
|
| 1488 |
[_weighted_quantile(dimensions[:, axis], weights, 0.5) for axis in range(3)]
|
| 1489 |
)
|
| 1490 |
full_axis_dimensions = np.array(
|
| 1491 |
-
[
|
|
|
|
|
|
|
|
|
|
| 1492 |
)
|
| 1493 |
box_dimensions = tight_dimensions.copy()
|
| 1494 |
longest_axis = int(np.argmax(robust_dimensions))
|
|
@@ -1587,13 +1603,17 @@ def _compact_floor_boundary_polygons(points, u, v, object_points=None):
|
|
| 1587 |
footprint_points = np.zeros((0, 2), np.float64)
|
| 1588 |
if object_points:
|
| 1589 |
stacked = [
|
| 1590 |
-
np.stack(
|
|
|
|
|
|
|
| 1591 |
for p in object_points
|
| 1592 |
if len(p)
|
| 1593 |
]
|
| 1594 |
if stacked:
|
| 1595 |
footprint_points = np.concatenate(stacked, axis=0)
|
| 1596 |
-
footprint_points = footprint_points[
|
|
|
|
|
|
|
| 1597 |
|
| 1598 |
resolution = 0.1
|
| 1599 |
combined_for_bounds = np.concatenate([floor_points, footprint_points], axis=0)
|
|
@@ -1757,9 +1777,7 @@ def _consolidate_compact_instances(instances, stats, up_axis):
|
|
| 1757 |
instance["centroid"] - fragment["centroid"]
|
| 1758 |
),
|
| 1759 |
)
|
| 1760 |
-
nearest["first_time"] = min(
|
| 1761 |
-
nearest["first_time"], fragment["first_time"]
|
| 1762 |
-
)
|
| 1763 |
consolidated[class_name] = retained
|
| 1764 |
return consolidated
|
| 1765 |
|
|
@@ -1792,9 +1810,7 @@ def _compact_instances(scene, up_axis):
|
|
| 1792 |
points, up_axis
|
| 1793 |
)
|
| 1794 |
record = dict(item)
|
| 1795 |
-
record.update(
|
| 1796 |
-
{"centroid": centroid, "size": size, "dims": dimensions}
|
| 1797 |
-
)
|
| 1798 |
measured.append(record)
|
| 1799 |
instances[class_name] = _canonical_merge_by_box_overlap(measured, up_axis)
|
| 1800 |
instances = _consolidate_compact_instances(instances, stats, up_axis)
|
|
@@ -1822,7 +1838,10 @@ def instance_source_track_ids(scene):
|
|
| 1822 |
"cache carries only canonical points (no SAM3 track ids to recover)"
|
| 1823 |
)
|
| 1824 |
up_vec, up_ax = room_gravity(
|
| 1825 |
-
raw_inputs["depth"],
|
|
|
|
|
|
|
|
|
|
| 1826 |
)
|
| 1827 |
instances, _stats = _compact_instances(scene, up_ax)
|
| 1828 |
out = {}
|
|
@@ -2005,13 +2024,17 @@ def _compact_box_distance(box_a, box_b):
|
|
| 2005 |
"""
|
| 2006 |
from scipy.optimize import lsq_linear
|
| 2007 |
|
| 2008 |
-
center_a = np.asarray(
|
|
|
|
|
|
|
| 2009 |
dimensions_a = np.asarray(box_a["3D oriented bounding box dimensions"], np.float64)
|
| 2010 |
orientation_a = np.asarray(
|
| 2011 |
box_a["3D oriented bounding box orientation unit vectors"], np.float64
|
| 2012 |
)
|
| 2013 |
orientation_a = orientation_a / np.linalg.norm(orientation_a, axis=1, keepdims=True)
|
| 2014 |
-
center_b = np.asarray(
|
|
|
|
|
|
|
| 2015 |
dimensions_b = np.asarray(box_b["3D oriented bounding box dimensions"], np.float64)
|
| 2016 |
orientation_b = np.asarray(
|
| 2017 |
box_b["3D oriented bounding box orientation unit vectors"], np.float64
|
|
@@ -2033,7 +2056,9 @@ def _compact_box_distance(box_a, box_b):
|
|
| 2033 |
max_iter=200,
|
| 2034 |
)
|
| 2035 |
if not result.success:
|
| 2036 |
-
raise RuntimeError(
|
|
|
|
|
|
|
| 2037 |
distance = float(np.linalg.norm(matrix @ result.x + center_a - center_b))
|
| 2038 |
return 0.0 if distance < 1e-10 else distance
|
| 2039 |
|
|
@@ -2041,7 +2066,9 @@ def _compact_box_distance(box_a, box_b):
|
|
| 2041 |
def _compact_class_distance(instances_a, instances_b):
|
| 2042 |
"""Return the minimum compact oriented-box distance across every cross-class instance pair."""
|
| 2043 |
return min(
|
| 2044 |
-
_compact_box_distance(
|
|
|
|
|
|
|
| 2045 |
for a in instances_a
|
| 2046 |
for b in instances_b
|
| 2047 |
)
|
|
@@ -2167,7 +2194,9 @@ def _explicit_from_compact(compact_code):
|
|
| 2167 |
printed_distances = {class_name: {} for class_name in classes}
|
| 2168 |
for index, class_name in enumerate(classes):
|
| 2169 |
for other in classes[index + 1 :]:
|
| 2170 |
-
raw = _compact_class_distance(
|
|
|
|
|
|
|
| 2171 |
printed = _corrected_class_distance(
|
| 2172 |
compact_objects[class_name], compact_objects[other]
|
| 2173 |
)
|
|
@@ -2187,7 +2216,10 @@ def _explicit_from_compact(compact_code):
|
|
| 2187 |
}
|
| 2188 |
|
| 2189 |
floor_area = round(
|
| 2190 |
-
_compact_room_floor_area(
|
|
|
|
|
|
|
|
|
|
| 2191 |
)
|
| 2192 |
|
| 2193 |
return {
|
|
@@ -2206,7 +2238,8 @@ def build_explicit_spatial_code(scene):
|
|
| 2206 |
compact schema (see the section header above): every object position/dimension/count and
|
| 2207 |
the appearance order are direct subsets of the compact spatial code's own values; the
|
| 2208 |
distance table is computed purely from compact's 3D oriented boxes. Nothing here
|
| 2209 |
-
independently re-measures geometry -- build_compact_spatial_code() already did that once.
|
|
|
|
| 2210 |
compact_code, instances, stats, up_ax, up_vec, _ = build_compact_spatial_code(scene)
|
| 2211 |
code, floor_area = _explicit_from_compact(compact_code)
|
| 2212 |
return code, instances, stats, up_ax, up_vec, floor_area
|
|
|
|
| 31 |
import numpy as np
|
| 32 |
import cv2
|
| 33 |
|
|
|
|
| 34 |
# ==========================================================================================
|
| 35 |
# CONSTANTS -- geometry-cleanup knobs, merged in from perceptual.py. Env-tunable levers that
|
| 36 |
# affect only the math below (build_instances/backproject_frame/etc.), never model inference.
|
|
|
|
| 124 |
):
|
| 125 |
"""Robust UP vector = normal of the RANSAC floor plane (a real physical plane), oriented toward
|
| 126 |
the cameras. Works when the reconstruction is tilted/drifted (ScanNet++) where argmin-extent fails.
|
| 127 |
+
Floor = large planar support with most non-inlier mass on ONE side. Returns (gravity_unit_vec, axis).
|
| 128 |
+
"""
|
| 129 |
points = []
|
| 130 |
for f in range(0, len(depth), fstride):
|
| 131 |
height, width = depth[f].shape
|
|
|
|
| 218 |
floor_x world axis projected onto the gravity plane (v the old floor_y axis), so this frame
|
| 219 |
differs from the old axis-drop frame ONLY by the tilt correction -- NO arbitrary in-plane
|
| 220 |
rotation (aligned scenes stay put; only tilt gets corrected). Objects / camera / room_outline
|
| 221 |
+
all share this one gravity-plane frame; floor_area is rotation-invariant so it matches too.
|
| 222 |
+
"""
|
| 223 |
g = np.asarray(up_vec, np.float64)
|
| 224 |
g = g / (np.linalg.norm(g) + 1e-12)
|
| 225 |
up_ax = int(np.argmax(np.abs(g)))
|
|
|
|
| 275 |
name_tokens = set(name.split())
|
| 276 |
for c in classes:
|
| 277 |
class_tokens = set(c.split())
|
| 278 |
+
if (
|
| 279 |
+
name_tokens
|
| 280 |
+
and class_tokens
|
| 281 |
+
and (name_tokens <= class_tokens or class_tokens <= name_tokens)
|
| 282 |
):
|
| 283 |
return c
|
| 284 |
return None
|
|
|
|
| 400 |
def _sor(pts, k=16, std=2.0, cap=4000):
|
| 401 |
"""Statistical outlier removal: drop points whose mean distance to their k nearest neighbors exceeds
|
| 402 |
mean + std*sigma. Removes mask-bleed / depth-speckle points that corrupt a literal closest-point min.
|
| 403 |
+
k=16 and std=2 are universal robust-statistics defaults -- NOT tuned to VSI (no benchmark-fit knob).
|
| 404 |
+
"""
|
| 405 |
from scipy.spatial import cKDTree
|
| 406 |
|
| 407 |
if len(pts) < k + 2:
|
|
|
|
| 416 |
def _main_cluster(pts):
|
| 417 |
"""Keep the object's dominant spatial cluster. Coherent mask-bleed onto a SPATIALLY-SEPARATED adjacent
|
| 418 |
object forms a disconnected component (a gap separates two objects); the true object is the largest one.
|
| 419 |
+
Linkage scale self-calibrates from the cloud's own nearest-neighbor spacing -- no fixed distance.
|
| 420 |
+
"""
|
| 421 |
from scipy.spatial import cKDTree
|
| 422 |
|
| 423 |
if len(pts) < 30:
|
|
|
|
| 453 |
(1) per-point DA3 confidence: boundary mask-bleed = depth discontinuity = LOW conf -> drop below the
|
| 454 |
object's OWN median confidence (data-derived cut);
|
| 455 |
(2) statistical density outlier removal on the survivors;
|
| 456 |
+
(3) dominant spatial cluster: coherent bleed onto a separated adjacent object is a disconnected cluster.
|
| 457 |
+
"""
|
| 458 |
if inst.get("_cleanpts") is not None:
|
| 459 |
return inst["_cleanpts"]
|
| 460 |
pts = inst["pts"]
|
|
|
|
| 480 |
"""Closest distance between the two objects' point clouds ('closest point of each object'). Points are
|
| 481 |
cleaned by _clean (self-calibrated per-object confidence + density) then exact nearest-neighbor min via
|
| 482 |
KD-tree, so mask-bleed/speckle can't collapse the answer. NOTE: VSI's GT is box-to-box on CLEAN annotation
|
| 483 |
+
boxes; the residual gap is object-segmentation quality (bleed), not this formula -- see _clean docstring.
|
| 484 |
+
"""
|
| 485 |
points_a = _clean(_rep(instances_a), cap=k)
|
| 486 |
points_b = _clean(_rep(instances_b), cap=k)
|
| 487 |
if len(points_a) == 0 or len(points_b) == 0:
|
|
|
|
| 528 |
"""Snap a coarse SAM3 mask boundary to the RGB color edge (appearance-guided). This clips the same-depth
|
| 529 |
bleed that depth CANNOT see: where the halo crosses onto a differently-colored neighbor, the color edge
|
| 530 |
cuts it. Params are DERIVED, not tuned -- radius from frame scale, smoothness from the image's own color
|
| 531 |
+
variance (same MAD-style principle as depth_edges). No model, no GPU. Falls back to grabCut, then erode.
|
| 532 |
+
"""
|
| 533 |
if mask.shape[:2] != rgb.shape[:2]:
|
| 534 |
mask = cv2.resize(
|
| 535 |
mask.astype(np.uint8),
|
|
|
|
| 584 |
valid_f: optional precomputed (isfinite & >0) depth mask, reused across all masks of a frame.
|
| 585 |
return_conf: also return the (M,) DA3 confidence of each kept point (for per-point noise-aware cleaning).
|
| 586 |
edges_f: optional per-frame depth-edge map; if given, keep the mask's largest depth-coherent component
|
| 587 |
+
(cuts mask-bleed onto adjacent objects at the depth boundary, per frame, before back-projection).
|
| 588 |
+
"""
|
| 589 |
height, width = depth_f.shape
|
| 590 |
empty = (
|
| 591 |
(np.empty((0, 3), np.float32), np.empty((0,), np.float32))
|
|
|
|
| 1052 |
"appearance order" is written as one compact line instead of one line per entry -- it's a
|
| 1053 |
single ordered sequence meant to be scanned, not structured data meant to be read field by
|
| 1054 |
field like the rest of the code. Every writer of spatial_code.json should go through this
|
| 1055 |
+
(not a bare json.dump) so the on-disk format and the prompt-time format never drift apart.
|
| 1056 |
+
"""
|
| 1057 |
body = dict(code)
|
| 1058 |
ao = body.pop("appearance order", None)
|
| 1059 |
text = json.dumps(body, indent=1).rstrip()
|
|
|
|
| 1354 |
points = _canonical_clean(instance)
|
| 1355 |
if not len(points):
|
| 1356 |
points = instance["pts"]
|
| 1357 |
+
room_points = np.stack([points @ u, points @ v, points @ g - floor_level], axis=1)
|
|
|
|
|
|
|
| 1358 |
horizontal = room_points[:, :2]
|
| 1359 |
centered = horizontal - np.median(horizontal, axis=0)
|
| 1360 |
if len(centered) > 5000:
|
| 1361 |
+
centered = centered[np.random.RandomState(0).choice(len(centered), 5000, False)]
|
|
|
|
|
|
|
| 1362 |
try:
|
| 1363 |
_, _, rotation = np.linalg.svd(
|
| 1364 |
centered - centered.mean(axis=0), full_matrices=False
|
|
|
|
| 1393 |
upper = np.percentile(projected, 98, axis=0)
|
| 1394 |
centers.append((lower + upper) / 2)
|
| 1395 |
dimensions.append(np.maximum(upper - lower, 0.0))
|
| 1396 |
+
full_dimensions.append(
|
| 1397 |
+
np.maximum(projected.max(axis=0) - projected.min(axis=0), 0.0)
|
| 1398 |
+
)
|
| 1399 |
weights.append(len(observation))
|
| 1400 |
if not centers:
|
| 1401 |
projected = room_points @ orientation.T
|
|
|
|
| 1425 |
# the short-axis ship's one 32f caveat).
|
| 1426 |
core_centers, core_weights = centers, weights
|
| 1427 |
if len(centers) >= 4:
|
| 1428 |
+
features = np.concatenate(
|
| 1429 |
+
[centers, np.log(np.maximum(dimensions, 1e-4))], axis=1
|
| 1430 |
+
)
|
| 1431 |
median = np.median(features, axis=0)
|
| 1432 |
deviation = np.abs(features - median)
|
| 1433 |
scale = 1.4826 * np.median(deviation, axis=0)
|
|
|
|
| 1453 |
full_dimensions = full_dimensions[consistent]
|
| 1454 |
weights = weights[consistent]
|
| 1455 |
box_center_local = np.array(
|
| 1456 |
+
[
|
| 1457 |
+
_weighted_quantile(core_centers[:, axis], core_weights, 0.5)
|
| 1458 |
+
for axis in range(3)
|
| 1459 |
+
]
|
| 1460 |
)
|
| 1461 |
# Size each axis by a HIGH percentile (0.90) of the mutually-consistent observed extents,
|
| 1462 |
# not the 75th. A partial/occluded/foreshortened view of an object can only measure a
|
|
|
|
| 1501 |
[_weighted_quantile(dimensions[:, axis], weights, 0.5) for axis in range(3)]
|
| 1502 |
)
|
| 1503 |
full_axis_dimensions = np.array(
|
| 1504 |
+
[
|
| 1505 |
+
_weighted_quantile(full_dimensions[:, axis], weights, 0.9)
|
| 1506 |
+
for axis in range(3)
|
| 1507 |
+
]
|
| 1508 |
)
|
| 1509 |
box_dimensions = tight_dimensions.copy()
|
| 1510 |
longest_axis = int(np.argmax(robust_dimensions))
|
|
|
|
| 1603 |
footprint_points = np.zeros((0, 2), np.float64)
|
| 1604 |
if object_points:
|
| 1605 |
stacked = [
|
| 1606 |
+
np.stack(
|
| 1607 |
+
[np.asarray(p, np.float64) @ u, np.asarray(p, np.float64) @ v], axis=1
|
| 1608 |
+
)
|
| 1609 |
for p in object_points
|
| 1610 |
if len(p)
|
| 1611 |
]
|
| 1612 |
if stacked:
|
| 1613 |
footprint_points = np.concatenate(stacked, axis=0)
|
| 1614 |
+
footprint_points = footprint_points[
|
| 1615 |
+
np.isfinite(footprint_points).all(axis=1)
|
| 1616 |
+
]
|
| 1617 |
|
| 1618 |
resolution = 0.1
|
| 1619 |
combined_for_bounds = np.concatenate([floor_points, footprint_points], axis=0)
|
|
|
|
| 1777 |
instance["centroid"] - fragment["centroid"]
|
| 1778 |
),
|
| 1779 |
)
|
| 1780 |
+
nearest["first_time"] = min(nearest["first_time"], fragment["first_time"])
|
|
|
|
|
|
|
| 1781 |
consolidated[class_name] = retained
|
| 1782 |
return consolidated
|
| 1783 |
|
|
|
|
| 1810 |
points, up_axis
|
| 1811 |
)
|
| 1812 |
record = dict(item)
|
| 1813 |
+
record.update({"centroid": centroid, "size": size, "dims": dimensions})
|
|
|
|
|
|
|
| 1814 |
measured.append(record)
|
| 1815 |
instances[class_name] = _canonical_merge_by_box_overlap(measured, up_axis)
|
| 1816 |
instances = _consolidate_compact_instances(instances, stats, up_axis)
|
|
|
|
| 1838 |
"cache carries only canonical points (no SAM3 track ids to recover)"
|
| 1839 |
)
|
| 1840 |
up_vec, up_ax = room_gravity(
|
| 1841 |
+
raw_inputs["depth"],
|
| 1842 |
+
raw_inputs["intr"],
|
| 1843 |
+
raw_inputs["c2w"],
|
| 1844 |
+
raw_inputs.get("conf"),
|
| 1845 |
)
|
| 1846 |
instances, _stats = _compact_instances(scene, up_ax)
|
| 1847 |
out = {}
|
|
|
|
| 2024 |
"""
|
| 2025 |
from scipy.optimize import lsq_linear
|
| 2026 |
|
| 2027 |
+
center_a = np.asarray(
|
| 2028 |
+
box_a["3D oriented bounding box center coordinates"], np.float64
|
| 2029 |
+
)
|
| 2030 |
dimensions_a = np.asarray(box_a["3D oriented bounding box dimensions"], np.float64)
|
| 2031 |
orientation_a = np.asarray(
|
| 2032 |
box_a["3D oriented bounding box orientation unit vectors"], np.float64
|
| 2033 |
)
|
| 2034 |
orientation_a = orientation_a / np.linalg.norm(orientation_a, axis=1, keepdims=True)
|
| 2035 |
+
center_b = np.asarray(
|
| 2036 |
+
box_b["3D oriented bounding box center coordinates"], np.float64
|
| 2037 |
+
)
|
| 2038 |
dimensions_b = np.asarray(box_b["3D oriented bounding box dimensions"], np.float64)
|
| 2039 |
orientation_b = np.asarray(
|
| 2040 |
box_b["3D oriented bounding box orientation unit vectors"], np.float64
|
|
|
|
| 2056 |
max_iter=200,
|
| 2057 |
)
|
| 2058 |
if not result.success:
|
| 2059 |
+
raise RuntimeError(
|
| 2060 |
+
f"oriented-box distance optimization failed: {result.message}"
|
| 2061 |
+
)
|
| 2062 |
distance = float(np.linalg.norm(matrix @ result.x + center_a - center_b))
|
| 2063 |
return 0.0 if distance < 1e-10 else distance
|
| 2064 |
|
|
|
|
| 2066 |
def _compact_class_distance(instances_a, instances_b):
|
| 2067 |
"""Return the minimum compact oriented-box distance across every cross-class instance pair."""
|
| 2068 |
return min(
|
| 2069 |
+
_compact_box_distance(
|
| 2070 |
+
a["3D oriented bounding box"], b["3D oriented bounding box"]
|
| 2071 |
+
)
|
| 2072 |
for a in instances_a
|
| 2073 |
for b in instances_b
|
| 2074 |
)
|
|
|
|
| 2194 |
printed_distances = {class_name: {} for class_name in classes}
|
| 2195 |
for index, class_name in enumerate(classes):
|
| 2196 |
for other in classes[index + 1 :]:
|
| 2197 |
+
raw = _compact_class_distance(
|
| 2198 |
+
compact_objects[class_name], compact_objects[other]
|
| 2199 |
+
)
|
| 2200 |
printed = _corrected_class_distance(
|
| 2201 |
compact_objects[class_name], compact_objects[other]
|
| 2202 |
)
|
|
|
|
| 2216 |
}
|
| 2217 |
|
| 2218 |
floor_area = round(
|
| 2219 |
+
_compact_room_floor_area(
|
| 2220 |
+
compact_code["room"].get("floor boundary polygons", [])
|
| 2221 |
+
),
|
| 2222 |
+
1,
|
| 2223 |
)
|
| 2224 |
|
| 2225 |
return {
|
|
|
|
| 2238 |
compact schema (see the section header above): every object position/dimension/count and
|
| 2239 |
the appearance order are direct subsets of the compact spatial code's own values; the
|
| 2240 |
distance table is computed purely from compact's 3D oriented boxes. Nothing here
|
| 2241 |
+
independently re-measures geometry -- build_compact_spatial_code() already did that once.
|
| 2242 |
+
"""
|
| 2243 |
compact_code, instances, stats, up_ax, up_vec, _ = build_compact_spatial_code(scene)
|
| 2244 |
code, floor_area = _explicit_from_compact(compact_code)
|
| 2245 |
return code, instances, stats, up_ax, up_vec, floor_area
|
encoder/ground_truth.py
CHANGED
|
@@ -51,9 +51,7 @@ from encoder.geometric import (
|
|
| 51 |
dump_spatial_code,
|
| 52 |
)
|
| 53 |
|
| 54 |
-
META_INFO_DIR = Path(
|
| 55 |
-
config.DATA_ROOT
|
| 56 |
-
) / "thinking-in-space" / "data" / "meta_info"
|
| 57 |
META_INFO_DATASETS = ("scannet", "arkitscenes", "scannetpp")
|
| 58 |
|
| 59 |
|
|
@@ -97,7 +95,9 @@ def _appearance_order_ranks_by_scene():
|
|
| 97 |
|
| 98 |
ranks_by_scene = {}
|
| 99 |
for scene, edges in edges_by_scene.items():
|
| 100 |
-
nodes = set(edges) | {
|
|
|
|
|
|
|
| 101 |
order = []
|
| 102 |
visited, in_progress = set(), set()
|
| 103 |
|
|
@@ -243,7 +243,8 @@ def build_and_write(scene, spatial_code_format="explicit"):
|
|
| 243 |
|
| 244 |
def scenes():
|
| 245 |
"""Every scene meta_info has ground truth for (a superset of every scene any
|
| 246 |
-
perception-built spatial code could ever cover, since this needs no SAM3/DA3 cache).
|
|
|
|
| 247 |
return sorted(load_meta_info())
|
| 248 |
|
| 249 |
|
|
@@ -261,9 +262,13 @@ if __name__ == "__main__":
|
|
| 261 |
import argparse
|
| 262 |
|
| 263 |
parser = argparse.ArgumentParser()
|
| 264 |
-
parser.add_argument("--scenes", help="comma-separated scenes (default: every scene)")
|
| 265 |
parser.add_argument(
|
| 266 |
-
"--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
)
|
| 268 |
args = parser.parse_args()
|
| 269 |
scene_list = (
|
|
|
|
| 51 |
dump_spatial_code,
|
| 52 |
)
|
| 53 |
|
| 54 |
+
META_INFO_DIR = Path(config.DATA_ROOT) / "thinking-in-space" / "data" / "meta_info"
|
|
|
|
|
|
|
| 55 |
META_INFO_DATASETS = ("scannet", "arkitscenes", "scannetpp")
|
| 56 |
|
| 57 |
|
|
|
|
| 95 |
|
| 96 |
ranks_by_scene = {}
|
| 97 |
for scene, edges in edges_by_scene.items():
|
| 98 |
+
nodes = set(edges) | {
|
| 99 |
+
node for successors in edges.values() for node in successors
|
| 100 |
+
}
|
| 101 |
order = []
|
| 102 |
visited, in_progress = set(), set()
|
| 103 |
|
|
|
|
| 243 |
|
| 244 |
def scenes():
|
| 245 |
"""Every scene meta_info has ground truth for (a superset of every scene any
|
| 246 |
+
perception-built spatial code could ever cover, since this needs no SAM3/DA3 cache).
|
| 247 |
+
"""
|
| 248 |
return sorted(load_meta_info())
|
| 249 |
|
| 250 |
|
|
|
|
| 262 |
import argparse
|
| 263 |
|
| 264 |
parser = argparse.ArgumentParser()
|
|
|
|
| 265 |
parser.add_argument(
|
| 266 |
+
"--scenes", help="comma-separated scenes (default: every scene)"
|
| 267 |
+
)
|
| 268 |
+
parser.add_argument(
|
| 269 |
+
"--formats",
|
| 270 |
+
default="explicit,compact",
|
| 271 |
+
help="comma-separated spatial-code formats",
|
| 272 |
)
|
| 273 |
args = parser.parse_args()
|
| 274 |
scene_list = (
|
encoder/launch.py
CHANGED
|
@@ -33,26 +33,18 @@ def _has_required_caches(scene, depth, input_selection, tracking, frame_count):
|
|
| 33 |
return all(
|
| 34 |
os.path.isfile(path)
|
| 35 |
for path in (
|
| 36 |
-
config.sam3_cache_file(
|
| 37 |
-
|
| 38 |
-
),
|
| 39 |
-
config.da3_cache_file(
|
| 40 |
-
scene, depth, input_selection, frame_count
|
| 41 |
-
),
|
| 42 |
)
|
| 43 |
)
|
| 44 |
|
| 45 |
|
| 46 |
-
def _scenes_with_required_caches(
|
| 47 |
-
depth, input_selection, tracking, frame_count
|
| 48 |
-
):
|
| 49 |
"""Return manifest scenes having every cache required by this encoder run."""
|
| 50 |
return [
|
| 51 |
scene
|
| 52 |
for scene in _scenes()
|
| 53 |
-
if _has_required_caches(
|
| 54 |
-
scene, depth, input_selection, tracking, frame_count
|
| 55 |
-
)
|
| 56 |
]
|
| 57 |
|
| 58 |
|
|
@@ -226,8 +218,7 @@ def _launch(args, selected):
|
|
| 226 |
process.join()
|
| 227 |
succeeded = len(selected) - len(failed) - skipped
|
| 228 |
print(
|
| 229 |
-
f"[{label}] DONE: {succeeded} ok, {skipped} skipped, "
|
| 230 |
-
f"{len(failed)} failed"
|
| 231 |
)
|
| 232 |
if failed:
|
| 233 |
raise SystemExit(1)
|
|
|
|
| 33 |
return all(
|
| 34 |
os.path.isfile(path)
|
| 35 |
for path in (
|
| 36 |
+
config.sam3_cache_file(scene, input_selection, tracking, frame_count),
|
| 37 |
+
config.da3_cache_file(scene, depth, input_selection, frame_count),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
)
|
| 40 |
|
| 41 |
|
| 42 |
+
def _scenes_with_required_caches(depth, input_selection, tracking, frame_count):
|
|
|
|
|
|
|
| 43 |
"""Return manifest scenes having every cache required by this encoder run."""
|
| 44 |
return [
|
| 45 |
scene
|
| 46 |
for scene in _scenes()
|
| 47 |
+
if _has_required_caches(scene, depth, input_selection, tracking, frame_count)
|
|
|
|
|
|
|
| 48 |
]
|
| 49 |
|
| 50 |
|
|
|
|
| 218 |
process.join()
|
| 219 |
succeeded = len(selected) - len(failed) - skipped
|
| 220 |
print(
|
| 221 |
+
f"[{label}] DONE: {succeeded} ok, {skipped} skipped, " f"{len(failed)} failed"
|
|
|
|
| 222 |
)
|
| 223 |
if failed:
|
| 224 |
raise SystemExit(1)
|
harness/A/__init__.py
CHANGED
|
@@ -20,9 +20,7 @@ JSONL = Path(os.environ.get("VSI_JSONL", VSI_ROOT / "test.jsonl"))
|
|
| 20 |
WORKSPACE_ROOT = Path(__file__).resolve().parent.parent.parent
|
| 21 |
# One JSON per question, matching the layout results/symbolic/... already uses:
|
| 22 |
# results/A/<model>/<frame_selection>/<frame_count>/<scene>/<question_id>.json
|
| 23 |
-
RESULTS_DIR = Path(
|
| 24 |
-
os.environ.get("VSI_HARNESS_RESULTS_DIR", "/root/results/A")
|
| 25 |
-
)
|
| 26 |
|
| 27 |
# Same two selection strategies and vocabulary as inference.SAM3_FRAME_SELECTIONS:
|
| 28 |
# "uniform" (evenly spaced indices) or "selective" (the quality/redundancy/motion-
|
|
|
|
| 20 |
WORKSPACE_ROOT = Path(__file__).resolve().parent.parent.parent
|
| 21 |
# One JSON per question, matching the layout results/symbolic/... already uses:
|
| 22 |
# results/A/<model>/<frame_selection>/<frame_count>/<scene>/<question_id>.json
|
| 23 |
+
RESULTS_DIR = Path(os.environ.get("VSI_HARNESS_RESULTS_DIR", "/root/results/A"))
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Same two selection strategies and vocabulary as inference.SAM3_FRAME_SELECTIONS:
|
| 26 |
# "uniform" (evenly spaced indices) or "selective" (the quality/redundancy/motion-
|
harness/A/__pycache__/models.cpython-311.pyc
CHANGED
|
Binary files a/harness/A/__pycache__/models.cpython-311.pyc and b/harness/A/__pycache__/models.cpython-311.pyc differ
|
|
|
harness/A/__pycache__/sweep.cpython-311.pyc
CHANGED
|
Binary files a/harness/A/__pycache__/sweep.cpython-311.pyc and b/harness/A/__pycache__/sweep.cpython-311.pyc differ
|
|
|
harness/A/run.py
CHANGED
|
@@ -79,7 +79,9 @@ def load_questions(jsonl_path=None, scene=None, scenes=None, limit=None):
|
|
| 79 |
"""Return VSI-Bench question rows, optionally filtered to one/many scenes / capped."""
|
| 80 |
if scene is not None and scenes is not None:
|
| 81 |
raise ValueError("scene and scenes cannot both be given")
|
| 82 |
-
allowed =
|
|
|
|
|
|
|
| 83 |
jsonl_path = jsonl_path or JSONL
|
| 84 |
rows = []
|
| 85 |
with open(jsonl_path) as stream:
|
|
@@ -103,7 +105,9 @@ def results_dir_for(model, protocol, frame_selection, frame_count, results_dir=N
|
|
| 103 |
return RESULTS_DIR / model / protocol / frame_selection / str(frame_count)
|
| 104 |
|
| 105 |
|
| 106 |
-
def _build_record(
|
|
|
|
|
|
|
| 107 |
"""Assemble one question's full, untruncated result record (nothing summarized)."""
|
| 108 |
return {
|
| 109 |
"model": model,
|
|
@@ -153,15 +157,26 @@ def _build_record(row, prompt, answer, metric_name, score, model, model_path, fr
|
|
| 153 |
|
| 154 |
|
| 155 |
def write_question_result(
|
| 156 |
-
row,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
):
|
| 158 |
"""Write one question's full, untruncated result record. Return (path, record)."""
|
| 159 |
record = _build_record(
|
| 160 |
row, prompt, answer, metric_name, score, model, model_path, frame_info
|
| 161 |
)
|
| 162 |
root = results_dir_for(
|
| 163 |
-
model,
|
| 164 |
-
frame_info["
|
|
|
|
|
|
|
|
|
|
| 165 |
)
|
| 166 |
scene_dir = root / record["scene"]
|
| 167 |
scene_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -227,8 +242,10 @@ def run(
|
|
| 227 |
scene_id = row["scene_name"]
|
| 228 |
if scene_id not in frame_cache:
|
| 229 |
video_path = inference_config.video_path(scene_id, row.get("dataset"))
|
| 230 |
-
frame_images, frame_timestamps, frame_indices =
|
| 231 |
-
|
|
|
|
|
|
|
| 232 |
)
|
| 233 |
frame_cache[scene_id] = {
|
| 234 |
"video_path": video_path,
|
|
@@ -244,22 +261,29 @@ def run(
|
|
| 244 |
)
|
| 245 |
answer = (
|
| 246 |
adapter.answer_extended(
|
| 247 |
-
cached["frame_images"],
|
| 248 |
-
|
|
|
|
|
|
|
| 249 |
)
|
| 250 |
if extended
|
| 251 |
-
else adapter.answer(
|
|
|
|
|
|
|
| 252 |
)
|
| 253 |
-
doc = {
|
|
|
|
|
|
|
|
|
|
| 254 |
score_doc = vsi_official_eval.vsibench_process_results(
|
| 255 |
doc, [answer["answer_text"]]
|
| 256 |
)["vsibench_score"]
|
| 257 |
metric_name, score = _scalar_score(row["question_type"], score_doc)
|
| 258 |
frame_info = {
|
| 259 |
"protocol": (
|
| 260 |
-
f"{reasoning_budget}"
|
| 261 |
-
|
| 262 |
-
else "base"
|
| 263 |
),
|
| 264 |
"video_path": cached["video_path"],
|
| 265 |
"frame_timestamps": cached["frame_timestamps"],
|
|
@@ -269,13 +293,27 @@ def run(
|
|
| 269 |
}
|
| 270 |
if write_results:
|
| 271 |
path, record = write_question_result(
|
| 272 |
-
row,
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
)
|
| 275 |
else:
|
| 276 |
path = None
|
| 277 |
record = _build_record(
|
| 278 |
-
row,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
)
|
| 280 |
record["result_path"] = str(path) if path else None
|
| 281 |
results.append(record)
|
|
@@ -296,7 +334,9 @@ def main():
|
|
| 296 |
dest="frame_selection",
|
| 297 |
)
|
| 298 |
parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
|
| 299 |
-
parser.add_argument(
|
|
|
|
|
|
|
| 300 |
parser.add_argument("--device", default="cuda")
|
| 301 |
parser.add_argument(
|
| 302 |
"--results-dir",
|
|
@@ -320,7 +360,9 @@ def main():
|
|
| 320 |
parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
|
| 321 |
parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
|
| 322 |
parser.add_argument(
|
| 323 |
-
"--raw-budget",
|
|
|
|
|
|
|
| 324 |
help="raw-budget arm: run the base protocol's exact single-generation, "
|
| 325 |
"no-rescue mechanism at this token cap instead of the hardcoded 16 "
|
| 326 |
"(mutually exclusive with --extended)",
|
|
|
|
| 79 |
"""Return VSI-Bench question rows, optionally filtered to one/many scenes / capped."""
|
| 80 |
if scene is not None and scenes is not None:
|
| 81 |
raise ValueError("scene and scenes cannot both be given")
|
| 82 |
+
allowed = (
|
| 83 |
+
{scene} if scene is not None else (set(scenes) if scenes is not None else None)
|
| 84 |
+
)
|
| 85 |
jsonl_path = jsonl_path or JSONL
|
| 86 |
rows = []
|
| 87 |
with open(jsonl_path) as stream:
|
|
|
|
| 105 |
return RESULTS_DIR / model / protocol / frame_selection / str(frame_count)
|
| 106 |
|
| 107 |
|
| 108 |
+
def _build_record(
|
| 109 |
+
row, prompt, answer, metric_name, score, model, model_path, frame_info
|
| 110 |
+
):
|
| 111 |
"""Assemble one question's full, untruncated result record (nothing summarized)."""
|
| 112 |
return {
|
| 113 |
"model": model,
|
|
|
|
| 157 |
|
| 158 |
|
| 159 |
def write_question_result(
|
| 160 |
+
row,
|
| 161 |
+
prompt,
|
| 162 |
+
answer,
|
| 163 |
+
metric_name,
|
| 164 |
+
score,
|
| 165 |
+
model,
|
| 166 |
+
model_path,
|
| 167 |
+
frame_info,
|
| 168 |
+
results_dir=None,
|
| 169 |
):
|
| 170 |
"""Write one question's full, untruncated result record. Return (path, record)."""
|
| 171 |
record = _build_record(
|
| 172 |
row, prompt, answer, metric_name, score, model, model_path, frame_info
|
| 173 |
)
|
| 174 |
root = results_dir_for(
|
| 175 |
+
model,
|
| 176 |
+
frame_info["protocol"],
|
| 177 |
+
frame_info["frame_selection"],
|
| 178 |
+
frame_info["frame_count"],
|
| 179 |
+
results_dir,
|
| 180 |
)
|
| 181 |
scene_dir = root / record["scene"]
|
| 182 |
scene_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 242 |
scene_id = row["scene_name"]
|
| 243 |
if scene_id not in frame_cache:
|
| 244 |
video_path = inference_config.video_path(scene_id, row.get("dataset"))
|
| 245 |
+
frame_images, frame_timestamps, frame_indices = (
|
| 246 |
+
frame_sampling.sample_frames(
|
| 247 |
+
video_path, frame_count, frame_selection
|
| 248 |
+
)
|
| 249 |
)
|
| 250 |
frame_cache[scene_id] = {
|
| 251 |
"video_path": video_path,
|
|
|
|
| 261 |
)
|
| 262 |
answer = (
|
| 263 |
adapter.answer_extended(
|
| 264 |
+
cached["frame_images"],
|
| 265 |
+
prompt,
|
| 266 |
+
reasoning_budget=reasoning_budget,
|
| 267 |
+
force_budget=force_budget,
|
| 268 |
)
|
| 269 |
if extended
|
| 270 |
+
else adapter.answer(
|
| 271 |
+
cached["frame_images"], prompt, max_new_tokens=raw_budget
|
| 272 |
+
)
|
| 273 |
)
|
| 274 |
+
doc = {
|
| 275 |
+
"question_type": row["question_type"],
|
| 276 |
+
"ground_truth": row["ground_truth"],
|
| 277 |
+
}
|
| 278 |
score_doc = vsi_official_eval.vsibench_process_results(
|
| 279 |
doc, [answer["answer_text"]]
|
| 280 |
)["vsibench_score"]
|
| 281 |
metric_name, score = _scalar_score(row["question_type"], score_doc)
|
| 282 |
frame_info = {
|
| 283 |
"protocol": (
|
| 284 |
+
f"{reasoning_budget}"
|
| 285 |
+
if extended
|
| 286 |
+
else f"truncated/{raw_budget}" if raw_budget is not None else "base"
|
| 287 |
),
|
| 288 |
"video_path": cached["video_path"],
|
| 289 |
"frame_timestamps": cached["frame_timestamps"],
|
|
|
|
| 293 |
}
|
| 294 |
if write_results:
|
| 295 |
path, record = write_question_result(
|
| 296 |
+
row,
|
| 297 |
+
prompt,
|
| 298 |
+
answer,
|
| 299 |
+
metric_name,
|
| 300 |
+
score,
|
| 301 |
+
model,
|
| 302 |
+
adapter.model_path,
|
| 303 |
+
frame_info,
|
| 304 |
+
results_dir,
|
| 305 |
)
|
| 306 |
else:
|
| 307 |
path = None
|
| 308 |
record = _build_record(
|
| 309 |
+
row,
|
| 310 |
+
prompt,
|
| 311 |
+
answer,
|
| 312 |
+
metric_name,
|
| 313 |
+
score,
|
| 314 |
+
model,
|
| 315 |
+
adapter.model_path,
|
| 316 |
+
frame_info,
|
| 317 |
)
|
| 318 |
record["result_path"] = str(path) if path else None
|
| 319 |
results.append(record)
|
|
|
|
| 334 |
dest="frame_selection",
|
| 335 |
)
|
| 336 |
parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
|
| 337 |
+
parser.add_argument(
|
| 338 |
+
"--limit", type=int, default=None, help="cap the number of questions"
|
| 339 |
+
)
|
| 340 |
parser.add_argument("--device", default="cuda")
|
| 341 |
parser.add_argument(
|
| 342 |
"--results-dir",
|
|
|
|
| 360 |
parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
|
| 361 |
parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
|
| 362 |
parser.add_argument(
|
| 363 |
+
"--raw-budget",
|
| 364 |
+
type=int,
|
| 365 |
+
default=None,
|
| 366 |
help="raw-budget arm: run the base protocol's exact single-generation, "
|
| 367 |
"no-rescue mechanism at this token cap instead of the hardcoded 16 "
|
| 368 |
"(mutually exclusive with --extended)",
|
harness/B/__pycache__/prompts.cpython-311.pyc
CHANGED
|
Binary files a/harness/B/__pycache__/prompts.cpython-311.pyc and b/harness/B/__pycache__/prompts.cpython-311.pyc differ
|
|
|
harness/B/__pycache__/spatial_codes.cpython-311.pyc
CHANGED
|
Binary files a/harness/B/__pycache__/spatial_codes.cpython-311.pyc and b/harness/B/__pycache__/spatial_codes.cpython-311.pyc differ
|
|
|
harness/B/__pycache__/sweep.cpython-311.pyc
CHANGED
|
Binary files a/harness/B/__pycache__/sweep.cpython-311.pyc and b/harness/B/__pycache__/sweep.cpython-311.pyc differ
|
|
|
harness/B/launch.py
CHANGED
|
@@ -54,10 +54,28 @@ def _load_run_module():
|
|
| 54 |
|
| 55 |
|
| 56 |
def _worker(
|
| 57 |
-
tasks,
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
):
|
| 62 |
if gpu is not None:
|
| 63 |
os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
|
|
@@ -115,11 +133,25 @@ def _worker(
|
|
| 115 |
|
| 116 |
|
| 117 |
def launch(
|
| 118 |
-
model,
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
flat_distance_table=False,
|
| 124 |
):
|
| 125 |
"""Answer every question for ``selected`` scenes, sharded across every visible GPU.
|
|
@@ -132,9 +164,9 @@ def launch(
|
|
| 132 |
if extended and raw_budget is not None:
|
| 133 |
raise ValueError("extended and raw_budget are mutually exclusive")
|
| 134 |
protocol = (
|
| 135 |
-
f"{reasoning_budget}"
|
| 136 |
-
|
| 137 |
-
else "base"
|
| 138 |
)
|
| 139 |
condition = (
|
| 140 |
f"{model}/{protocol}/{spatial_code_format}/{depth}/{tracking}"
|
|
@@ -142,7 +174,13 @@ def launch(
|
|
| 142 |
)
|
| 143 |
run = _load_run_module()
|
| 144 |
root = run.results_dir_for(
|
| 145 |
-
model,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
results_dir,
|
| 147 |
)
|
| 148 |
pending = []
|
|
@@ -152,12 +190,16 @@ def launch(
|
|
| 152 |
if question_ids is not None:
|
| 153 |
rows = [row for row in rows if row["id"] in question_ids]
|
| 154 |
if not rows:
|
| 155 |
-
|
| 156 |
-
|
|
|
|
| 157 |
answered = all((root / scene / f"{row['id']}.json").is_file() for row in rows)
|
| 158 |
if answered and not rebuild:
|
| 159 |
completed += 1
|
| 160 |
-
print(
|
|
|
|
|
|
|
|
|
|
| 161 |
else:
|
| 162 |
pending.append(scene)
|
| 163 |
if not pending:
|
|
@@ -185,10 +227,28 @@ def launch(
|
|
| 185 |
context.Process(
|
| 186 |
target=_worker,
|
| 187 |
args=(
|
| 188 |
-
tasks,
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
),
|
| 193 |
)
|
| 194 |
for gpu in assignments
|
|
@@ -219,16 +279,21 @@ def main():
|
|
| 219 |
parser = argparse.ArgumentParser()
|
| 220 |
parser.add_argument("scene", nargs="?")
|
| 221 |
parser.add_argument(
|
| 222 |
-
"--scenes",
|
|
|
|
| 223 |
)
|
| 224 |
parser.add_argument("--model", required=True, choices=vlm_models.available_models())
|
| 225 |
parser.add_argument(
|
| 226 |
-
"--spatial-code-format",
|
| 227 |
-
|
|
|
|
|
|
|
| 228 |
)
|
| 229 |
parser.add_argument(
|
| 230 |
-
"--input-selection",
|
| 231 |
-
|
|
|
|
|
|
|
| 232 |
)
|
| 233 |
parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
|
| 234 |
parser.add_argument("--depth", default=DEFAULT_DEPTH, choices=DEPTH_VARIANTS)
|
|
@@ -236,49 +301,64 @@ def main():
|
|
| 236 |
parser.add_argument("--results-dir", default=None)
|
| 237 |
parser.add_argument("--rebuild", action="store_true")
|
| 238 |
parser.add_argument(
|
| 239 |
-
"--base-protocol",
|
|
|
|
| 240 |
help="run harness.A's exact fixed 16-token protocol instead of the extended default",
|
| 241 |
)
|
| 242 |
parser.add_argument(
|
| 243 |
-
"--serialization",
|
|
|
|
| 244 |
help="robustness arm only: 'yaml' renders the identical code dict as YAML "
|
| 245 |
"(pair with an explicit --results-dir)",
|
| 246 |
)
|
| 247 |
parser.add_argument(
|
| 248 |
-
"--paraphrase-context",
|
|
|
|
|
|
|
| 249 |
help="robustness arm only: the pre-registered paraphrased context line "
|
| 250 |
"(pair with an explicit --results-dir)",
|
| 251 |
)
|
| 252 |
parser.add_argument(
|
| 253 |
-
"--no-schema-legend",
|
|
|
|
|
|
|
| 254 |
help="legend-ablation arm: drop the embedded schema legend before prompting "
|
| 255 |
"(pair with an explicit --results-dir)",
|
| 256 |
)
|
| 257 |
parser.add_argument(
|
| 258 |
-
"--prose-legend",
|
|
|
|
|
|
|
| 259 |
help="legacy-legend arm: drop the embedded schema block AND use the legacy "
|
| 260 |
"prose legend as the context block (pair with an explicit --results-dir)",
|
| 261 |
)
|
| 262 |
parser.add_argument(
|
| 263 |
-
"--reasoning-note",
|
|
|
|
|
|
|
| 264 |
help="prefix the Thinking-with-Spatial-Code step-by-step note to the "
|
| 265 |
"post-prompt (pair with an explicit --results-dir)",
|
| 266 |
)
|
| 267 |
parser.add_argument(
|
| 268 |
-
"--thinking",
|
|
|
|
| 269 |
help="enable native thinking mode (Qwen only; pair with an explicit "
|
| 270 |
"--results-dir)",
|
| 271 |
)
|
| 272 |
parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
|
| 273 |
parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
|
| 274 |
parser.add_argument(
|
| 275 |
-
"--truncated-budget",
|
|
|
|
|
|
|
| 276 |
help="raw-budget arm: base-protocol mechanics (single generation, no forced "
|
| 277 |
"rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
|
| 278 |
"with --base-protocol)",
|
| 279 |
)
|
| 280 |
parser.add_argument(
|
| 281 |
-
"--flat-distance-table",
|
|
|
|
|
|
|
| 282 |
help="flat-table arm: flatten the distance table's two-level nesting into "
|
| 283 |
"single-level '<class> to <other>' keys, identical information (pair with "
|
| 284 |
"an explicit --results-dir)",
|
|
@@ -304,17 +384,28 @@ def main():
|
|
| 304 |
if args.base_protocol and args.truncated_budget is not None:
|
| 305 |
parser.error("--base-protocol and --truncated-budget are mutually exclusive")
|
| 306 |
launch(
|
| 307 |
-
args.model,
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
extended=not args.base_protocol and args.truncated_budget is None,
|
| 310 |
raw_budget=args.truncated_budget,
|
| 311 |
-
reasoning_budget=args.reasoning_budget,
|
|
|
|
| 312 |
serialization=args.serialization,
|
| 313 |
context_line=(
|
| 314 |
-
PROSE_LEGEND
|
| 315 |
-
|
| 316 |
-
else
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
| 318 |
),
|
| 319 |
strip_schema_legend=args.strip_schema_legend or args.prose_legend,
|
| 320 |
reasoning_note=args.reasoning_note,
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
def _worker(
|
| 57 |
+
tasks,
|
| 58 |
+
results,
|
| 59 |
+
model,
|
| 60 |
+
spatial_code_format,
|
| 61 |
+
input_selection,
|
| 62 |
+
frame_count,
|
| 63 |
+
depth,
|
| 64 |
+
tracking,
|
| 65 |
+
results_dir,
|
| 66 |
+
gpu,
|
| 67 |
+
cpu_threads,
|
| 68 |
+
extended,
|
| 69 |
+
reasoning_budget,
|
| 70 |
+
force_budget,
|
| 71 |
+
serialization,
|
| 72 |
+
context_line,
|
| 73 |
+
question_ids,
|
| 74 |
+
strip_schema_legend,
|
| 75 |
+
reasoning_note,
|
| 76 |
+
thinking,
|
| 77 |
+
raw_budget,
|
| 78 |
+
flat_distance_table,
|
| 79 |
):
|
| 80 |
if gpu is not None:
|
| 81 |
os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
|
|
|
|
| 133 |
|
| 134 |
|
| 135 |
def launch(
|
| 136 |
+
model,
|
| 137 |
+
spatial_code_format,
|
| 138 |
+
input_selection,
|
| 139 |
+
frame_count,
|
| 140 |
+
selected,
|
| 141 |
+
depth=DEFAULT_DEPTH,
|
| 142 |
+
tracking=DEFAULT_TRACKING,
|
| 143 |
+
results_dir=None,
|
| 144 |
+
rebuild=False,
|
| 145 |
+
extended=True,
|
| 146 |
+
reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
|
| 147 |
+
force_budget=MAX_NEW_TOKENS,
|
| 148 |
+
serialization="json",
|
| 149 |
+
context_line=None,
|
| 150 |
+
question_ids=None,
|
| 151 |
+
strip_schema_legend=False,
|
| 152 |
+
reasoning_note=False,
|
| 153 |
+
thinking=False,
|
| 154 |
+
raw_budget=None,
|
| 155 |
flat_distance_table=False,
|
| 156 |
):
|
| 157 |
"""Answer every question for ``selected`` scenes, sharded across every visible GPU.
|
|
|
|
| 164 |
if extended and raw_budget is not None:
|
| 165 |
raise ValueError("extended and raw_budget are mutually exclusive")
|
| 166 |
protocol = (
|
| 167 |
+
f"{reasoning_budget}"
|
| 168 |
+
if extended
|
| 169 |
+
else f"truncated/{raw_budget}" if raw_budget is not None else "base"
|
| 170 |
)
|
| 171 |
condition = (
|
| 172 |
f"{model}/{protocol}/{spatial_code_format}/{depth}/{tracking}"
|
|
|
|
| 174 |
)
|
| 175 |
run = _load_run_module()
|
| 176 |
root = run.results_dir_for(
|
| 177 |
+
model,
|
| 178 |
+
protocol,
|
| 179 |
+
spatial_code_format,
|
| 180 |
+
depth,
|
| 181 |
+
tracking,
|
| 182 |
+
input_selection,
|
| 183 |
+
frame_count,
|
| 184 |
results_dir,
|
| 185 |
)
|
| 186 |
pending = []
|
|
|
|
| 190 |
if question_ids is not None:
|
| 191 |
rows = [row for row in rows if row["id"] in question_ids]
|
| 192 |
if not rows:
|
| 193 |
+
raise ValueError(
|
| 194 |
+
f"no questions found for scene {scene!r}; check the manifest, scene selection, or question_ids"
|
| 195 |
+
)
|
| 196 |
answered = all((root / scene / f"{row['id']}.json").is_file() for row in rows)
|
| 197 |
if answered and not rebuild:
|
| 198 |
completed += 1
|
| 199 |
+
print(
|
| 200 |
+
f"[{condition} {completed}/{len(selected)}] {scene}: skipped",
|
| 201 |
+
flush=True,
|
| 202 |
+
)
|
| 203 |
else:
|
| 204 |
pending.append(scene)
|
| 205 |
if not pending:
|
|
|
|
| 227 |
context.Process(
|
| 228 |
target=_worker,
|
| 229 |
args=(
|
| 230 |
+
tasks,
|
| 231 |
+
results,
|
| 232 |
+
model,
|
| 233 |
+
spatial_code_format,
|
| 234 |
+
input_selection,
|
| 235 |
+
frame_count,
|
| 236 |
+
depth,
|
| 237 |
+
tracking,
|
| 238 |
+
results_dir,
|
| 239 |
+
gpu,
|
| 240 |
+
cpu_threads,
|
| 241 |
+
extended,
|
| 242 |
+
reasoning_budget,
|
| 243 |
+
force_budget,
|
| 244 |
+
serialization,
|
| 245 |
+
context_line,
|
| 246 |
+
question_ids,
|
| 247 |
+
strip_schema_legend,
|
| 248 |
+
reasoning_note,
|
| 249 |
+
thinking,
|
| 250 |
+
raw_budget,
|
| 251 |
+
flat_distance_table,
|
| 252 |
),
|
| 253 |
)
|
| 254 |
for gpu in assignments
|
|
|
|
| 279 |
parser = argparse.ArgumentParser()
|
| 280 |
parser.add_argument("scene", nargs="?")
|
| 281 |
parser.add_argument(
|
| 282 |
+
"--scenes",
|
| 283 |
+
help="comma-separated scenes (cannot be combined with positional scene)",
|
| 284 |
)
|
| 285 |
parser.add_argument("--model", required=True, choices=vlm_models.available_models())
|
| 286 |
parser.add_argument(
|
| 287 |
+
"--spatial-code-format",
|
| 288 |
+
default=DEFAULT_SPATIAL_CODE_FORMAT,
|
| 289 |
+
choices=SPATIAL_CODE_FORMATS,
|
| 290 |
+
dest="spatial_code_format",
|
| 291 |
)
|
| 292 |
parser.add_argument(
|
| 293 |
+
"--input-selection",
|
| 294 |
+
default=DEFAULT_INPUT_SELECTION,
|
| 295 |
+
choices=INPUT_SELECTIONS,
|
| 296 |
+
dest="input_selection",
|
| 297 |
)
|
| 298 |
parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
|
| 299 |
parser.add_argument("--depth", default=DEFAULT_DEPTH, choices=DEPTH_VARIANTS)
|
|
|
|
| 301 |
parser.add_argument("--results-dir", default=None)
|
| 302 |
parser.add_argument("--rebuild", action="store_true")
|
| 303 |
parser.add_argument(
|
| 304 |
+
"--base-protocol",
|
| 305 |
+
action="store_true",
|
| 306 |
help="run harness.A's exact fixed 16-token protocol instead of the extended default",
|
| 307 |
)
|
| 308 |
parser.add_argument(
|
| 309 |
+
"--serialization",
|
| 310 |
+
default="json",
|
| 311 |
help="robustness arm only: 'yaml' renders the identical code dict as YAML "
|
| 312 |
"(pair with an explicit --results-dir)",
|
| 313 |
)
|
| 314 |
parser.add_argument(
|
| 315 |
+
"--paraphrase-context",
|
| 316 |
+
action="store_true",
|
| 317 |
+
dest="paraphrase_context",
|
| 318 |
help="robustness arm only: the pre-registered paraphrased context line "
|
| 319 |
"(pair with an explicit --results-dir)",
|
| 320 |
)
|
| 321 |
parser.add_argument(
|
| 322 |
+
"--no-schema-legend",
|
| 323 |
+
action="store_true",
|
| 324 |
+
dest="strip_schema_legend",
|
| 325 |
help="legend-ablation arm: drop the embedded schema legend before prompting "
|
| 326 |
"(pair with an explicit --results-dir)",
|
| 327 |
)
|
| 328 |
parser.add_argument(
|
| 329 |
+
"--prose-legend",
|
| 330 |
+
action="store_true",
|
| 331 |
+
dest="prose_legend",
|
| 332 |
help="legacy-legend arm: drop the embedded schema block AND use the legacy "
|
| 333 |
"prose legend as the context block (pair with an explicit --results-dir)",
|
| 334 |
)
|
| 335 |
parser.add_argument(
|
| 336 |
+
"--reasoning-note",
|
| 337 |
+
action="store_true",
|
| 338 |
+
dest="reasoning_note",
|
| 339 |
help="prefix the Thinking-with-Spatial-Code step-by-step note to the "
|
| 340 |
"post-prompt (pair with an explicit --results-dir)",
|
| 341 |
)
|
| 342 |
parser.add_argument(
|
| 343 |
+
"--thinking",
|
| 344 |
+
action="store_true",
|
| 345 |
help="enable native thinking mode (Qwen only; pair with an explicit "
|
| 346 |
"--results-dir)",
|
| 347 |
)
|
| 348 |
parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
|
| 349 |
parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
|
| 350 |
parser.add_argument(
|
| 351 |
+
"--truncated-budget",
|
| 352 |
+
type=int,
|
| 353 |
+
default=None,
|
| 354 |
help="raw-budget arm: base-protocol mechanics (single generation, no forced "
|
| 355 |
"rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
|
| 356 |
"with --base-protocol)",
|
| 357 |
)
|
| 358 |
parser.add_argument(
|
| 359 |
+
"--flat-distance-table",
|
| 360 |
+
action="store_true",
|
| 361 |
+
dest="flat_distance_table",
|
| 362 |
help="flat-table arm: flatten the distance table's two-level nesting into "
|
| 363 |
"single-level '<class> to <other>' keys, identical information (pair with "
|
| 364 |
"an explicit --results-dir)",
|
|
|
|
| 384 |
if args.base_protocol and args.truncated_budget is not None:
|
| 385 |
parser.error("--base-protocol and --truncated-budget are mutually exclusive")
|
| 386 |
launch(
|
| 387 |
+
args.model,
|
| 388 |
+
args.spatial_code_format,
|
| 389 |
+
args.input_selection,
|
| 390 |
+
args.frames,
|
| 391 |
+
selected,
|
| 392 |
+
depth=args.depth,
|
| 393 |
+
tracking=args.tracking,
|
| 394 |
+
results_dir=args.results_dir,
|
| 395 |
+
rebuild=args.rebuild,
|
| 396 |
extended=not args.base_protocol and args.truncated_budget is None,
|
| 397 |
raw_budget=args.truncated_budget,
|
| 398 |
+
reasoning_budget=args.reasoning_budget,
|
| 399 |
+
force_budget=args.force_budget,
|
| 400 |
serialization=args.serialization,
|
| 401 |
context_line=(
|
| 402 |
+
PROSE_LEGEND
|
| 403 |
+
if args.prose_legend
|
| 404 |
+
else (
|
| 405 |
+
PARAPHRASE_PRE_PROMPT
|
| 406 |
+
if args.paraphrase_context
|
| 407 |
+
else NO_LEGEND_PRE_PROMPT if args.strip_schema_legend else None
|
| 408 |
+
)
|
| 409 |
),
|
| 410 |
strip_schema_legend=args.strip_schema_legend or args.prose_legend,
|
| 411 |
reasoning_note=args.reasoning_note,
|
harness/B/spatial_codes.py
CHANGED
|
@@ -15,7 +15,9 @@ from encoder.config import spatial_code_path
|
|
| 15 |
from harness.B import SPATIAL_CODE_FORMATS
|
| 16 |
|
| 17 |
|
| 18 |
-
def load_spatial_code(
|
|
|
|
|
|
|
| 19 |
"""Return (spatial code dict, path it was loaded from)."""
|
| 20 |
if spatial_code_format not in SPATIAL_CODE_FORMATS:
|
| 21 |
raise ValueError(
|
|
|
|
| 15 |
from harness.B import SPATIAL_CODE_FORMATS
|
| 16 |
|
| 17 |
|
| 18 |
+
def load_spatial_code(
|
| 19 |
+
scene, depth, input_selection, tracking, frame_count, spatial_code_format
|
| 20 |
+
):
|
| 21 |
"""Return (spatial code dict, path it was loaded from)."""
|
| 22 |
if spatial_code_format not in SPATIAL_CODE_FORMATS:
|
| 23 |
raise ValueError(
|
harness/B/sweep.py
CHANGED
|
@@ -35,7 +35,9 @@ from harness.B import ( # noqa: E402
|
|
| 35 |
from harness.B import launch as harness_launch # noqa: E402
|
| 36 |
|
| 37 |
|
| 38 |
-
def build_plan(
|
|
|
|
|
|
|
| 39 |
"""Return every (model, spatial_code_format, depth, tracking, input_selection,
|
| 40 |
frame_count) 6-tuple in the sweep, in a stable, cheapest-first-ish order (frame
|
| 41 |
count sorted first)."""
|
|
@@ -51,31 +53,57 @@ def build_plan(models, spatial_code_formats, input_selections, frame_counts, dep
|
|
| 51 |
|
| 52 |
|
| 53 |
def sweep(
|
| 54 |
-
models,
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
):
|
| 59 |
"""Run every sweep combination across all visible GPUs."""
|
| 60 |
-
plan = build_plan(
|
|
|
|
|
|
|
| 61 |
protocol = (
|
| 62 |
-
f"{reasoning_budget}"
|
| 63 |
-
|
| 64 |
-
else "base"
|
| 65 |
)
|
| 66 |
-
for index, (
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
print(
|
| 70 |
f"=== sweep {index}/{len(plan)}: {model}/{protocol}/"
|
| 71 |
f"{spatial_code_format}/{depth}/{tracking}/{input_selection}/{frame_count} ===",
|
| 72 |
flush=True,
|
| 73 |
)
|
| 74 |
harness_launch.launch(
|
| 75 |
-
model,
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
flat_distance_table=flat_distance_table,
|
| 80 |
)
|
| 81 |
|
|
@@ -84,56 +112,73 @@ def main():
|
|
| 84 |
parser = argparse.ArgumentParser()
|
| 85 |
parser.add_argument("scene", nargs="?")
|
| 86 |
parser.add_argument(
|
| 87 |
-
"--scenes",
|
|
|
|
| 88 |
)
|
| 89 |
parser.add_argument(
|
| 90 |
-
"--models",
|
|
|
|
| 91 |
help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
|
| 92 |
)
|
| 93 |
parser.add_argument(
|
| 94 |
-
"--spatial-code-formats",
|
|
|
|
|
|
|
| 95 |
help=f"comma-separated formats (or 'all'); one of {SPATIAL_CODE_FORMATS}",
|
| 96 |
)
|
| 97 |
parser.add_argument(
|
| 98 |
-
"--input-selections",
|
|
|
|
|
|
|
| 99 |
help=f"comma-separated selections (or 'all'); one of {INPUT_SELECTIONS}",
|
| 100 |
)
|
| 101 |
parser.add_argument(
|
| 102 |
"--frames", required=True, help="comma-separated frame counts, e.g. 16,32,64"
|
| 103 |
)
|
| 104 |
parser.add_argument(
|
| 105 |
-
"--depths",
|
|
|
|
| 106 |
help=f"comma-separated depths (or 'all'); one of {DEPTH_VARIANTS}",
|
| 107 |
)
|
| 108 |
parser.add_argument(
|
| 109 |
-
"--trackings",
|
|
|
|
| 110 |
help=f"comma-separated tracking modes (or 'all'); one of {TRACKING_MODES}",
|
| 111 |
)
|
| 112 |
parser.add_argument("--results-dir", default=None)
|
| 113 |
parser.add_argument("--rebuild", action="store_true")
|
| 114 |
parser.add_argument(
|
| 115 |
-
"--base-protocol",
|
|
|
|
| 116 |
help="run the whole sweep under harness.A's exact fixed 16-token protocol "
|
| 117 |
"instead of the extended default",
|
| 118 |
)
|
| 119 |
parser.add_argument(
|
| 120 |
-
"--reasoning-budget",
|
|
|
|
|
|
|
| 121 |
dest="reasoning_budget",
|
| 122 |
help="extended-protocol first-pass budget (the calibrated value from "
|
| 123 |
"analysis/preregistration.md, e.g. 512)",
|
| 124 |
)
|
| 125 |
parser.add_argument(
|
| 126 |
-
"--no-schema-legend",
|
|
|
|
|
|
|
| 127 |
help="drop the embedded schema legend from every prompt (the amended main-run "
|
| 128 |
"design; see analysis/preregistration.md)",
|
| 129 |
)
|
| 130 |
parser.add_argument(
|
| 131 |
-
"--truncated-budget",
|
|
|
|
|
|
|
| 132 |
help="raw-budget arm: base-protocol mechanics (single generation, no forced "
|
| 133 |
"rescue) at this token cap (mutually exclusive with --base-protocol)",
|
| 134 |
)
|
| 135 |
parser.add_argument(
|
| 136 |
-
"--flat-distance-table",
|
|
|
|
|
|
|
| 137 |
help="flat-table arm: flatten the distance table's two-level nesting into "
|
| 138 |
"single-level '<class> to <other>' keys, identical information",
|
| 139 |
)
|
|
@@ -144,7 +189,9 @@ def main():
|
|
| 144 |
parser.error("--base-protocol and --truncated-budget are mutually exclusive")
|
| 145 |
|
| 146 |
try:
|
| 147 |
-
models = _parse_csv_choice(
|
|
|
|
|
|
|
| 148 |
spatial_code_formats = _parse_csv_choice(
|
| 149 |
args.spatial_code_formats, SPATIAL_CODE_FORMATS, "--spatial-code-formats"
|
| 150 |
)
|
|
@@ -168,9 +215,15 @@ def main():
|
|
| 168 |
selected = [args.scene] if args.scene else scenes()
|
| 169 |
|
| 170 |
sweep(
|
| 171 |
-
models,
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
extended=not args.base_protocol and args.truncated_budget is None,
|
| 175 |
reasoning_budget=args.reasoning_budget,
|
| 176 |
strip_schema_legend=args.strip_schema_legend,
|
|
|
|
| 35 |
from harness.B import launch as harness_launch # noqa: E402
|
| 36 |
|
| 37 |
|
| 38 |
+
def build_plan(
|
| 39 |
+
models, spatial_code_formats, input_selections, frame_counts, depths, trackings
|
| 40 |
+
):
|
| 41 |
"""Return every (model, spatial_code_format, depth, tracking, input_selection,
|
| 42 |
frame_count) 6-tuple in the sweep, in a stable, cheapest-first-ish order (frame
|
| 43 |
count sorted first)."""
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
def sweep(
|
| 56 |
+
models,
|
| 57 |
+
spatial_code_formats,
|
| 58 |
+
input_selections,
|
| 59 |
+
frame_counts,
|
| 60 |
+
selected_scenes,
|
| 61 |
+
depths=(DEFAULT_DEPTH,),
|
| 62 |
+
trackings=(DEFAULT_TRACKING,),
|
| 63 |
+
results_dir=None,
|
| 64 |
+
rebuild=False,
|
| 65 |
+
extended=True,
|
| 66 |
+
reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
|
| 67 |
+
strip_schema_legend=False,
|
| 68 |
+
raw_budget=None,
|
| 69 |
+
flat_distance_table=False,
|
| 70 |
):
|
| 71 |
"""Run every sweep combination across all visible GPUs."""
|
| 72 |
+
plan = build_plan(
|
| 73 |
+
models, spatial_code_formats, input_selections, frame_counts, depths, trackings
|
| 74 |
+
)
|
| 75 |
protocol = (
|
| 76 |
+
f"{reasoning_budget}"
|
| 77 |
+
if extended
|
| 78 |
+
else f"truncated/{raw_budget}" if raw_budget is not None else "base"
|
| 79 |
)
|
| 80 |
+
for index, (
|
| 81 |
+
model,
|
| 82 |
+
spatial_code_format,
|
| 83 |
+
depth,
|
| 84 |
+
tracking,
|
| 85 |
+
input_selection,
|
| 86 |
+
frame_count,
|
| 87 |
+
) in enumerate(plan, start=1):
|
| 88 |
print(
|
| 89 |
f"=== sweep {index}/{len(plan)}: {model}/{protocol}/"
|
| 90 |
f"{spatial_code_format}/{depth}/{tracking}/{input_selection}/{frame_count} ===",
|
| 91 |
flush=True,
|
| 92 |
)
|
| 93 |
harness_launch.launch(
|
| 94 |
+
model,
|
| 95 |
+
spatial_code_format,
|
| 96 |
+
input_selection,
|
| 97 |
+
frame_count,
|
| 98 |
+
selected_scenes,
|
| 99 |
+
depth=depth,
|
| 100 |
+
tracking=tracking,
|
| 101 |
+
results_dir=results_dir,
|
| 102 |
+
rebuild=rebuild,
|
| 103 |
+
extended=extended,
|
| 104 |
+
reasoning_budget=reasoning_budget,
|
| 105 |
+
strip_schema_legend=strip_schema_legend,
|
| 106 |
+
raw_budget=raw_budget,
|
| 107 |
flat_distance_table=flat_distance_table,
|
| 108 |
)
|
| 109 |
|
|
|
|
| 112 |
parser = argparse.ArgumentParser()
|
| 113 |
parser.add_argument("scene", nargs="?")
|
| 114 |
parser.add_argument(
|
| 115 |
+
"--scenes",
|
| 116 |
+
help="comma-separated scenes (cannot be combined with positional scene)",
|
| 117 |
)
|
| 118 |
parser.add_argument(
|
| 119 |
+
"--models",
|
| 120 |
+
required=True,
|
| 121 |
help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
|
| 122 |
)
|
| 123 |
parser.add_argument(
|
| 124 |
+
"--spatial-code-formats",
|
| 125 |
+
required=True,
|
| 126 |
+
dest="spatial_code_formats",
|
| 127 |
help=f"comma-separated formats (or 'all'); one of {SPATIAL_CODE_FORMATS}",
|
| 128 |
)
|
| 129 |
parser.add_argument(
|
| 130 |
+
"--input-selections",
|
| 131 |
+
required=True,
|
| 132 |
+
dest="input_selections",
|
| 133 |
help=f"comma-separated selections (or 'all'); one of {INPUT_SELECTIONS}",
|
| 134 |
)
|
| 135 |
parser.add_argument(
|
| 136 |
"--frames", required=True, help="comma-separated frame counts, e.g. 16,32,64"
|
| 137 |
)
|
| 138 |
parser.add_argument(
|
| 139 |
+
"--depths",
|
| 140 |
+
default=DEFAULT_DEPTH,
|
| 141 |
help=f"comma-separated depths (or 'all'); one of {DEPTH_VARIANTS}",
|
| 142 |
)
|
| 143 |
parser.add_argument(
|
| 144 |
+
"--trackings",
|
| 145 |
+
default=DEFAULT_TRACKING,
|
| 146 |
help=f"comma-separated tracking modes (or 'all'); one of {TRACKING_MODES}",
|
| 147 |
)
|
| 148 |
parser.add_argument("--results-dir", default=None)
|
| 149 |
parser.add_argument("--rebuild", action="store_true")
|
| 150 |
parser.add_argument(
|
| 151 |
+
"--base-protocol",
|
| 152 |
+
action="store_true",
|
| 153 |
help="run the whole sweep under harness.A's exact fixed 16-token protocol "
|
| 154 |
"instead of the extended default",
|
| 155 |
)
|
| 156 |
parser.add_argument(
|
| 157 |
+
"--reasoning-budget",
|
| 158 |
+
type=int,
|
| 159 |
+
default=EXTENDED_MAX_NEW_TOKENS,
|
| 160 |
dest="reasoning_budget",
|
| 161 |
help="extended-protocol first-pass budget (the calibrated value from "
|
| 162 |
"analysis/preregistration.md, e.g. 512)",
|
| 163 |
)
|
| 164 |
parser.add_argument(
|
| 165 |
+
"--no-schema-legend",
|
| 166 |
+
action="store_true",
|
| 167 |
+
dest="strip_schema_legend",
|
| 168 |
help="drop the embedded schema legend from every prompt (the amended main-run "
|
| 169 |
"design; see analysis/preregistration.md)",
|
| 170 |
)
|
| 171 |
parser.add_argument(
|
| 172 |
+
"--truncated-budget",
|
| 173 |
+
type=int,
|
| 174 |
+
default=None,
|
| 175 |
help="raw-budget arm: base-protocol mechanics (single generation, no forced "
|
| 176 |
"rescue) at this token cap (mutually exclusive with --base-protocol)",
|
| 177 |
)
|
| 178 |
parser.add_argument(
|
| 179 |
+
"--flat-distance-table",
|
| 180 |
+
action="store_true",
|
| 181 |
+
dest="flat_distance_table",
|
| 182 |
help="flat-table arm: flatten the distance table's two-level nesting into "
|
| 183 |
"single-level '<class> to <other>' keys, identical information",
|
| 184 |
)
|
|
|
|
| 189 |
parser.error("--base-protocol and --truncated-budget are mutually exclusive")
|
| 190 |
|
| 191 |
try:
|
| 192 |
+
models = _parse_csv_choice(
|
| 193 |
+
args.models, vlm_models.available_models(), "--models"
|
| 194 |
+
)
|
| 195 |
spatial_code_formats = _parse_csv_choice(
|
| 196 |
args.spatial_code_formats, SPATIAL_CODE_FORMATS, "--spatial-code-formats"
|
| 197 |
)
|
|
|
|
| 215 |
selected = [args.scene] if args.scene else scenes()
|
| 216 |
|
| 217 |
sweep(
|
| 218 |
+
models,
|
| 219 |
+
spatial_code_formats,
|
| 220 |
+
input_selections,
|
| 221 |
+
frame_counts,
|
| 222 |
+
selected,
|
| 223 |
+
depths=depths,
|
| 224 |
+
trackings=trackings,
|
| 225 |
+
results_dir=args.results_dir,
|
| 226 |
+
rebuild=args.rebuild,
|
| 227 |
extended=not args.base_protocol and args.truncated_budget is None,
|
| 228 |
reasoning_budget=args.reasoning_budget,
|
| 229 |
strip_schema_legend=args.strip_schema_legend,
|