Spaces:
Paused
Paused
GitHub Actions commited on
Commit ·
190bd61
1
Parent(s): c4458f9
Deploy from GitHub commit fb9441ea5262c5a5845759c792252bc7e4cae62e
Browse files- app.py +76 -3
- verify_r1_moge_sim.py +54 -0
- visualizer.gpu.toml +2 -0
app.py
CHANGED
|
@@ -177,6 +177,19 @@ ENABLE_MOGE_GEOMETRY = str(config_value(
|
|
| 177 |
"enable_moge_geometry",
|
| 178 |
"0",
|
| 179 |
)).lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 182 |
seg_processor = None
|
|
@@ -607,6 +620,28 @@ def plane_homography_from_moge(geometry, mask: np.ndarray, w: int, h: int):
|
|
| 607 |
return H.flatten().tolist(), plane
|
| 608 |
|
| 609 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 610 |
# ---------------------------------------------------------------------------
|
| 611 |
# B4 — Shade Range Expansion
|
| 612 |
# Encode the shade multiplier using the actual brightness spread of the floor
|
|
@@ -2322,12 +2357,12 @@ def build_segmentation_bundle(contents: bytes):
|
|
| 2322 |
# floor), walls remain the fallback for lineless floors (carpet),
|
| 2323 |
# and the silhouette v1 estimate is the final fallback.
|
| 2324 |
H_plane = np.asarray(homography, np.float64).reshape(3, 3)
|
|
|
|
| 2325 |
lattice_rot = estimate_floor_lattice_rotation(img_np, floor_mask, H_plane)
|
| 2326 |
if lattice_rot is not None:
|
| 2327 |
plane["defaultRotation"] = lattice_rot
|
| 2328 |
plane["rotationSource"] = "floor-lattice"
|
| 2329 |
else:
|
| 2330 |
-
wall_mask = np.isin(seg_map, class_ids(WALL_CONTACT_CLASSES)).astype(np.uint8)
|
| 2331 |
wall_rot = estimate_wall_rotation(wall_mask, floor_mask, H_plane)
|
| 2332 |
if wall_rot is not None:
|
| 2333 |
plane["defaultRotation"] = wall_rot
|
|
@@ -2389,6 +2424,42 @@ def build_segmentation_bundle(contents: bytes):
|
|
| 2389 |
if len(region_indices) < min_floor_area:
|
| 2390 |
continue
|
| 2391 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2392 |
# Per-region confidence sub-map
|
| 2393 |
region_conf = build_confidence_map(region_mask, occluder_zone)
|
| 2394 |
|
|
@@ -2404,8 +2475,10 @@ def build_segmentation_bundle(contents: bytes):
|
|
| 2404 |
"id": region_idx,
|
| 2405 |
"className": "floor",
|
| 2406 |
"mask": base64.b64encode(region_indices.tobytes()).decode(),
|
| 2407 |
-
|
| 2408 |
-
|
|
|
|
|
|
|
| 2409 |
"shadeMap": base64.b64encode(shade_map.tobytes()).decode() if shade_map is not None else None,
|
| 2410 |
"shadeRange": list(shade_range), # B4 — frontend decodes with this
|
| 2411 |
"colorTemperature": color_temperature, # B2
|
|
|
|
| 177 |
"enable_moge_geometry",
|
| 178 |
"0",
|
| 179 |
)).lower() in {"1", "true", "yes", "on"}
|
| 180 |
+
# R1-6 (Pull 2) — per-region plane charts: disjoint floor regions (hallway
|
| 181 |
+
# through a doorway, around a partition) each get their OWN fitted plane
|
| 182 |
+
# chart instead of inheriting the main room's. Ported from main's
|
| 183 |
+
# multi-plane surface decomposition (c15e49a) and reduced to dev's
|
| 184 |
+
# contracts: segmentation already separates regions spatially, so each
|
| 185 |
+
# region runs the certified single-plane fitters; a region that fails the
|
| 186 |
+
# gates keeps the shared global chart (exactly today's behaviour).
|
| 187 |
+
ENABLE_MULTI_PLANE_SURFACES = str(config_value(
|
| 188 |
+
"ENABLE_MULTI_PLANE_SURFACES",
|
| 189 |
+
"runtime",
|
| 190 |
+
"enable_multi_plane_surfaces",
|
| 191 |
+
"1",
|
| 192 |
+
)).lower() in {"1", "true", "yes", "on"}
|
| 193 |
|
| 194 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 195 |
seg_processor = None
|
|
|
|
| 620 |
return H.flatten().tolist(), plane
|
| 621 |
|
| 622 |
|
| 623 |
+
def region_plane_chart(
|
| 624 |
+
region_mask: np.ndarray,
|
| 625 |
+
geometry: dict | None,
|
| 626 |
+
depth: np.ndarray | None,
|
| 627 |
+
w: int,
|
| 628 |
+
h: int,
|
| 629 |
+
):
|
| 630 |
+
"""R1-6 (Pull 2) — fit ONE disjoint floor region its own metre-unit plane
|
| 631 |
+
chart, reusing the certified single-plane fitters (MoGe point map first,
|
| 632 |
+
pinhole metric depth second). Returns (homography_list, plane_dict) or
|
| 633 |
+
None — the caller keeps the shared global chart on abstention, so this
|
| 634 |
+
can only improve a region, never regress it.
|
| 635 |
+
"""
|
| 636 |
+
if geometry is not None:
|
| 637 |
+
fitted = plane_homography_from_moge(geometry, region_mask, w, h)
|
| 638 |
+
if fitted is not None:
|
| 639 |
+
return fitted
|
| 640 |
+
if depth is not None:
|
| 641 |
+
return plane_homography_from_depth(depth, region_mask, w, h)
|
| 642 |
+
return None
|
| 643 |
+
|
| 644 |
+
|
| 645 |
# ---------------------------------------------------------------------------
|
| 646 |
# B4 — Shade Range Expansion
|
| 647 |
# Encode the shade multiplier using the actual brightness spread of the floor
|
|
|
|
| 2357 |
# floor), walls remain the fallback for lineless floors (carpet),
|
| 2358 |
# and the silhouette v1 estimate is the final fallback.
|
| 2359 |
H_plane = np.asarray(homography, np.float64).reshape(3, 3)
|
| 2360 |
+
wall_mask = np.isin(seg_map, class_ids(WALL_CONTACT_CLASSES)).astype(np.uint8)
|
| 2361 |
lattice_rot = estimate_floor_lattice_rotation(img_np, floor_mask, H_plane)
|
| 2362 |
if lattice_rot is not None:
|
| 2363 |
plane["defaultRotation"] = lattice_rot
|
| 2364 |
plane["rotationSource"] = "floor-lattice"
|
| 2365 |
else:
|
|
|
|
| 2366 |
wall_rot = estimate_wall_rotation(wall_mask, floor_mask, H_plane)
|
| 2367 |
if wall_rot is not None:
|
| 2368 |
plane["defaultRotation"] = wall_rot
|
|
|
|
| 2424 |
if len(region_indices) < min_floor_area:
|
| 2425 |
continue
|
| 2426 |
|
| 2427 |
+
# R1-6 (Pull 2) — per-region plane chart: secondary regions (the
|
| 2428 |
+
# hallway through the doorway) inherit the main room's chart only
|
| 2429 |
+
# when their own fit abstains. The largest region keeps the
|
| 2430 |
+
# global chart — it dominated the global fit by construction.
|
| 2431 |
+
region_h, region_plane = homography, plane
|
| 2432 |
+
if (
|
| 2433 |
+
ENABLE_MULTI_PLANE_SURFACES
|
| 2434 |
+
and multi_room
|
| 2435 |
+
and region_idx > 0
|
| 2436 |
+
and plane is not None
|
| 2437 |
+
):
|
| 2438 |
+
fitted = region_plane_chart(region_mask, geometry, depth, w, h)
|
| 2439 |
+
if fitted is not None:
|
| 2440 |
+
region_h, region_plane = fitted
|
| 2441 |
+
region_plane["metersPerUnit"] = 1.0 # metre charts by construction
|
| 2442 |
+
H_r = np.asarray(region_h, np.float64).reshape(3, 3)
|
| 2443 |
+
r_rot = estimate_floor_lattice_rotation(img_np, region_mask, H_r)
|
| 2444 |
+
if r_rot is not None:
|
| 2445 |
+
region_plane["defaultRotation"] = r_rot
|
| 2446 |
+
region_plane["rotationSource"] = "floor-lattice"
|
| 2447 |
+
else:
|
| 2448 |
+
r_rot = estimate_wall_rotation(wall_mask, region_mask, H_r)
|
| 2449 |
+
if r_rot is not None:
|
| 2450 |
+
region_plane["defaultRotation"] = r_rot
|
| 2451 |
+
region_plane["rotationSource"] = "wall-contact"
|
| 2452 |
+
else:
|
| 2453 |
+
region_plane["defaultRotation"] = plane.get("defaultRotation")
|
| 2454 |
+
region_plane["rotationSource"] = plane.get("rotationSource")
|
| 2455 |
+
print(
|
| 2456 |
+
f"[REGION] region {region_idx}: own chart "
|
| 2457 |
+
f"({region_plane.get('geometrySource')}, rot "
|
| 2458 |
+
f"{region_plane.get('defaultRotation')}, "
|
| 2459 |
+
f"{region_plane.get('rotationSource')})",
|
| 2460 |
+
flush=True,
|
| 2461 |
+
)
|
| 2462 |
+
|
| 2463 |
# Per-region confidence sub-map
|
| 2464 |
region_conf = build_confidence_map(region_mask, occluder_zone)
|
| 2465 |
|
|
|
|
| 2475 |
"id": region_idx,
|
| 2476 |
"className": "floor",
|
| 2477 |
"mask": base64.b64encode(region_indices.tobytes()).decode(),
|
| 2478 |
+
# B7 shared chart; R1-6 — secondary regions carry their own
|
| 2479 |
+
# fitted chart when the per-region fit passed its gates.
|
| 2480 |
+
"homography": region_h,
|
| 2481 |
+
"plane": region_plane,
|
| 2482 |
"shadeMap": base64.b64encode(shade_map.tobytes()).decode() if shade_map is not None else None,
|
| 2483 |
"shadeRange": list(shade_range), # B4 — frontend decodes with this
|
| 2484 |
"colorTemperature": color_temperature, # B2
|
verify_r1_moge_sim.py
CHANGED
|
@@ -132,6 +132,60 @@ def main():
|
|
| 132 |
print(f" [{'PASS' if none_ok else 'FAIL'}] no geometry -> None")
|
| 133 |
ok_all &= none_ok
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
print("\n" + ("ALL R1-5 SIM CHECKS PASSED" if ok_all else "R1-5 SIM CHECKS FAILED"))
|
| 136 |
return 0 if ok_all else 1
|
| 137 |
|
|
|
|
| 132 |
print(f" [{'PASS' if none_ok else 'FAIL'}] no geometry -> None")
|
| 133 |
ok_all &= none_ok
|
| 134 |
|
| 135 |
+
# --- R1-6 (Pull 2) — per-region plane charts -----------------------------
|
| 136 |
+
start = src.index("def region_plane_chart")
|
| 137 |
+
end = src.index("\n# ---", start)
|
| 138 |
+
ns["plane_homography_from_depth"] = lambda *a, **k: None
|
| 139 |
+
exec(compile(src[start:end], "app.py", "exec"), ns)
|
| 140 |
+
region_plane_chart = ns["region_plane_chart"]
|
| 141 |
+
|
| 142 |
+
# Two-level floor: left half is the main floor (1.5 m below the camera),
|
| 143 |
+
# right half a raised platform (1.0 m). One point map, two region masks.
|
| 144 |
+
geom_a, mask_a, points_a, ok_a = synthetic_geometry(cam_h=1.5)
|
| 145 |
+
geom_b, mask_b, points_b, ok_b = synthetic_geometry(cam_h=1.0)
|
| 146 |
+
half = IMG_W // 2
|
| 147 |
+
points = points_a.copy()
|
| 148 |
+
points[:, half:] = points_b[:, half:]
|
| 149 |
+
okm = ok_a.copy()
|
| 150 |
+
okm[:, half:] = ok_b[:, half:]
|
| 151 |
+
geometry2 = dict(geom_a)
|
| 152 |
+
geometry2["points"] = points.astype(np.float32)
|
| 153 |
+
geometry2["validMask"] = okm
|
| 154 |
+
region_a = (mask_a > 0) & (np.indices((IMG_H, IMG_W))[1] < half)
|
| 155 |
+
region_b = (mask_b > 0) & (np.indices((IMG_H, IMG_W))[1] >= half)
|
| 156 |
+
|
| 157 |
+
# 6 — each region gets its OWN metre chart for its OWN plane
|
| 158 |
+
fit_b = region_plane_chart(region_b.astype(np.uint8), geometry2, None, IMG_W, IMG_H)
|
| 159 |
+
good = fit_b is not None
|
| 160 |
+
if good:
|
| 161 |
+
Hb = np.asarray(fit_b[0], np.float64).reshape(3, 3)
|
| 162 |
+
ys, xs = np.nonzero(region_b & okm)
|
| 163 |
+
rngb = np.random.default_rng(13)
|
| 164 |
+
sel = rngb.choice(len(xs), 3000, replace=False)
|
| 165 |
+
i, j = sel[:1500], sel[1500:]
|
| 166 |
+
P = points[ys, xs]
|
| 167 |
+
d3 = np.linalg.norm(P[i] - P[j], axis=1)
|
| 168 |
+
den = Hb[2, 0] * xs + Hb[2, 1] * ys + Hb[2, 2]
|
| 169 |
+
pa = (Hb[0, 0] * xs + Hb[0, 1] * ys + Hb[0, 2]) / den
|
| 170 |
+
pb = (Hb[1, 0] * xs + Hb[1, 1] * ys + Hb[1, 2]) / den
|
| 171 |
+
dp = np.hypot(pa[i] - pa[j], pb[i] - pb[j])
|
| 172 |
+
far = dp > 0.3
|
| 173 |
+
ratio_b = float(np.median(d3[far] / dp[far]))
|
| 174 |
+
good = abs(ratio_b - 1.0) <= 0.02
|
| 175 |
+
print(f" [{'PASS' if good else 'FAIL'}] region chart: raised region gets its own "
|
| 176 |
+
f"metre chart (ratio {ratio_b:.4f})")
|
| 177 |
+
else:
|
| 178 |
+
print(" [FAIL] region chart: abstained on a clean raised region")
|
| 179 |
+
ok_all &= good
|
| 180 |
+
|
| 181 |
+
# 7 — tiny/garbage regions abstain so the caller keeps the shared chart
|
| 182 |
+
tiny = np.zeros((IMG_H, IMG_W), np.uint8)
|
| 183 |
+
tiny[200:230, 200:230] = 1
|
| 184 |
+
abstain_ok = region_plane_chart(tiny, geometry2, None, IMG_W, IMG_H) is None
|
| 185 |
+
print(f" [{'PASS' if abstain_ok else 'FAIL'}] region chart: tiny region abstains "
|
| 186 |
+
f"(shared chart kept)")
|
| 187 |
+
ok_all &= abstain_ok
|
| 188 |
+
|
| 189 |
print("\n" + ("ALL R1-5 SIM CHECKS PASSED" if ok_all else "R1-5 SIM CHECKS FAILED"))
|
| 190 |
return 0 if ok_all else 1
|
| 191 |
|
visualizer.gpu.toml
CHANGED
|
@@ -17,4 +17,6 @@ moge_model_name = "Ruicheng/moge-2-vitl-normal"
|
|
| 17 |
enable_depth_estimation = true
|
| 18 |
enable_intrinsic_shading = true
|
| 19 |
enable_moge_geometry = true
|
|
|
|
|
|
|
| 20 |
data_dir = "data"
|
|
|
|
| 17 |
enable_depth_estimation = true
|
| 18 |
enable_intrinsic_shading = true
|
| 19 |
enable_moge_geometry = true
|
| 20 |
+
# R1-6 (Pull 2) — per-region plane charts for disjoint floor regions
|
| 21 |
+
enable_multi_plane_surfaces = true
|
| 22 |
data_dir = "data"
|