Spaces:
Paused
Paused
github-actions[bot] commited on
Commit ·
2ada41e
1
Parent(s): 94b277a
Automated Deploy: 494b38d4389f07608143d8f5f6850e5abc24d1fd
Browse files- services/geometry/multi_plane.py +20 -0
- services/pipeline/packaging.py +6 -10
- test_geometry_optimization.py +19 -1
- visualizer.gpu.toml +1 -1
- visualizer.hf.toml +2 -1
services/geometry/multi_plane.py
CHANGED
|
@@ -22,6 +22,24 @@ from services.geometry.plane_fitting import plane_basis, surface_distance_thresh
|
|
| 22 |
from services.geometry.ransac import ransac_surface_plane, ransac_surface_plane_by_distance
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def geometry_point_maps(mask: np.ndarray, geometry: dict | None):
|
| 26 |
if not ENABLE_MULTI_PLANE_SURFACES or geometry is None:
|
| 27 |
return None
|
|
@@ -130,6 +148,8 @@ def fit_multi_surface_planes(points: np.ndarray, normals: np.ndarray, normals_re
|
|
| 130 |
if not planes:
|
| 131 |
return []
|
| 132 |
|
|
|
|
|
|
|
| 133 |
floor_id = int(np.argmax([
|
| 134 |
plane["inlierCount"] * max(0.1, abs(float(plane["normal"][1])))
|
| 135 |
for plane in planes
|
|
|
|
| 22 |
from services.geometry.ransac import ransac_surface_plane, ransac_surface_plane_by_distance
|
| 23 |
|
| 24 |
|
| 25 |
+
MIN_SECONDARY_PLANE_RATIO = 0.05
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _prune_weak_secondary_planes(planes: list[dict]) -> list[dict]:
|
| 29 |
+
if not planes:
|
| 30 |
+
return []
|
| 31 |
+
|
| 32 |
+
primary_inliers = max(plane["inlierCount"] for plane in planes)
|
| 33 |
+
retained_planes = [
|
| 34 |
+
plane
|
| 35 |
+
for plane in planes
|
| 36 |
+
if plane["inlierCount"] >= primary_inliers * MIN_SECONDARY_PLANE_RATIO
|
| 37 |
+
]
|
| 38 |
+
for plane_id, plane in enumerate(retained_planes):
|
| 39 |
+
plane["id"] = plane_id
|
| 40 |
+
return retained_planes
|
| 41 |
+
|
| 42 |
+
|
| 43 |
def geometry_point_maps(mask: np.ndarray, geometry: dict | None):
|
| 44 |
if not ENABLE_MULTI_PLANE_SURFACES or geometry is None:
|
| 45 |
return None
|
|
|
|
| 148 |
if not planes:
|
| 149 |
return []
|
| 150 |
|
| 151 |
+
planes = _prune_weak_secondary_planes(planes)
|
| 152 |
+
|
| 153 |
floor_id = int(np.argmax([
|
| 154 |
plane["inlierCount"] * max(0.1, abs(float(plane["normal"][1])))
|
| 155 |
for plane in planes
|
services/pipeline/packaging.py
CHANGED
|
@@ -219,13 +219,11 @@ def build_manifest_segmentation_bundle(
|
|
| 219 |
if surface_uv is not None:
|
| 220 |
data, encoding_metadata = encode_surface_uv_asset(surface_uv)
|
| 221 |
extension = "u16" if encoding_metadata["dtype"] == "uint16" else "f32"
|
| 222 |
-
|
| 223 |
-
|
| 224 |
segment_metadata["surfaceUv"] = {
|
| 225 |
-
**make_binary_ref(
|
| 226 |
**encoding_metadata,
|
| 227 |
-
"url": f"/viz2d/jobs/{job_id}/assets/{asset_name}",
|
| 228 |
-
"lazy": True,
|
| 229 |
}
|
| 230 |
for field, (filename, dtype) in lazy_asset_fields.items():
|
| 231 |
value = segment.get(field)
|
|
@@ -238,12 +236,10 @@ def build_manifest_segmentation_bundle(
|
|
| 238 |
data = base64.b64decode(value)
|
| 239 |
else:
|
| 240 |
data = bytes(value)
|
| 241 |
-
|
| 242 |
-
|
| 243 |
segment_metadata[field] = {
|
| 244 |
-
**make_binary_ref(
|
| 245 |
-
"url": f"/viz2d/jobs/{job_id}/assets/{asset_name}",
|
| 246 |
-
"lazy": True,
|
| 247 |
}
|
| 248 |
metadata["segments"].append(segment_metadata)
|
| 249 |
|
|
|
|
| 219 |
if surface_uv is not None:
|
| 220 |
data, encoding_metadata = encode_surface_uv_asset(surface_uv)
|
| 221 |
extension = "u16" if encoding_metadata["dtype"] == "uint16" else "f32"
|
| 222 |
+
asset_path = f"segments/{segment_index}/surface-uv.{extension}"
|
| 223 |
+
archive.writestr(asset_path, data)
|
| 224 |
segment_metadata["surfaceUv"] = {
|
| 225 |
+
**make_binary_ref(asset_path, data, encoding_metadata["dtype"]),
|
| 226 |
**encoding_metadata,
|
|
|
|
|
|
|
| 227 |
}
|
| 228 |
for field, (filename, dtype) in lazy_asset_fields.items():
|
| 229 |
value = segment.get(field)
|
|
|
|
| 236 |
data = base64.b64decode(value)
|
| 237 |
else:
|
| 238 |
data = bytes(value)
|
| 239 |
+
asset_path = f"segments/{segment_index}/{filename}"
|
| 240 |
+
archive.writestr(asset_path, data)
|
| 241 |
segment_metadata[field] = {
|
| 242 |
+
**make_binary_ref(asset_path, data, dtype),
|
|
|
|
|
|
|
| 243 |
}
|
| 244 |
metadata["segments"].append(segment_metadata)
|
| 245 |
|
test_geometry_optimization.py
CHANGED
|
@@ -3,7 +3,10 @@ import unittest
|
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
from services.floor.geometry_filter import filter_surface_by_floor_geometry
|
| 6 |
-
from services.geometry.multi_plane import
|
|
|
|
|
|
|
|
|
|
| 7 |
from services.geometry.ransac import (
|
| 8 |
_best_surface_hypothesis,
|
| 9 |
_candidate_hypotheses,
|
|
@@ -11,6 +14,21 @@ from services.geometry.ransac import (
|
|
| 11 |
|
| 12 |
|
| 13 |
class GeometryOptimizationTests(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def test_batched_ransac_scoring_matches_sequential_scoring(self):
|
| 15 |
rng = np.random.default_rng(7)
|
| 16 |
xz = rng.uniform(-2, 2, size=(4_000, 2)).astype(np.float32)
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
from services.floor.geometry_filter import filter_surface_by_floor_geometry
|
| 6 |
+
from services.geometry.multi_plane import (
|
| 7 |
+
_prune_weak_secondary_planes,
|
| 8 |
+
geometry_point_maps,
|
| 9 |
+
)
|
| 10 |
from services.geometry.ransac import (
|
| 11 |
_best_surface_hypothesis,
|
| 12 |
_candidate_hypotheses,
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
class GeometryOptimizationTests(unittest.TestCase):
|
| 17 |
+
def test_weak_secondary_planes_are_removed_and_ids_are_reindexed(self):
|
| 18 |
+
planes = [
|
| 19 |
+
{"id": 0, "inlierCount": 325_002},
|
| 20 |
+
{"id": 1, "inlierCount": 5_302},
|
| 21 |
+
{"id": 2, "inlierCount": 26_000},
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
retained = _prune_weak_secondary_planes(planes)
|
| 25 |
+
|
| 26 |
+
self.assertEqual(
|
| 27 |
+
[plane["inlierCount"] for plane in retained],
|
| 28 |
+
[325_002, 26_000],
|
| 29 |
+
)
|
| 30 |
+
self.assertEqual([plane["id"] for plane in retained], [0, 1])
|
| 31 |
+
|
| 32 |
def test_batched_ransac_scoring_matches_sequential_scoring(self):
|
| 33 |
rng = np.random.default_rng(7)
|
| 34 |
xz = rng.uniform(-2, 2, size=(4_000, 2)).astype(np.float32)
|
visualizer.gpu.toml
CHANGED
|
@@ -32,7 +32,7 @@ data_dir = "data"
|
|
| 32 |
|
| 33 |
[surface_mapping]
|
| 34 |
ransac_distance_threshold = 0.04
|
| 35 |
-
max_planes =
|
| 36 |
normal_angle_threshold_degrees = 35
|
| 37 |
normal_smoothing_kernel = 5
|
| 38 |
min_plane_pixels = 1500
|
|
|
|
| 32 |
|
| 33 |
[surface_mapping]
|
| 34 |
ransac_distance_threshold = 0.04
|
| 35 |
+
max_planes = 1
|
| 36 |
normal_angle_threshold_degrees = 35
|
| 37 |
normal_smoothing_kernel = 5
|
| 38 |
min_plane_pixels = 1500
|
visualizer.hf.toml
CHANGED
|
@@ -21,6 +21,7 @@ enable_wall_segments = false
|
|
| 21 |
enable_intrinsic_shading = false
|
| 22 |
enable_shading_transfer = false
|
| 23 |
enable_sam_refinement = false
|
|
|
|
| 24 |
debug_artifacts_enabled = false
|
| 25 |
inference_max_dimension = 1024
|
| 26 |
conversion_target_ms = 30000
|
|
@@ -28,7 +29,7 @@ data_dir = "data"
|
|
| 28 |
|
| 29 |
[surface_mapping]
|
| 30 |
ransac_distance_threshold = 0.04
|
| 31 |
-
max_planes =
|
| 32 |
normal_angle_threshold_degrees = 35
|
| 33 |
normal_smoothing_kernel = 5
|
| 34 |
min_plane_pixels = 1500
|
|
|
|
| 21 |
enable_intrinsic_shading = false
|
| 22 |
enable_shading_transfer = false
|
| 23 |
enable_sam_refinement = false
|
| 24 |
+
enable_floor_mask_cleanup = true
|
| 25 |
debug_artifacts_enabled = false
|
| 26 |
inference_max_dimension = 1024
|
| 27 |
conversion_target_ms = 30000
|
|
|
|
| 29 |
|
| 30 |
[surface_mapping]
|
| 31 |
ransac_distance_threshold = 0.04
|
| 32 |
+
max_planes = 1
|
| 33 |
normal_angle_threshold_degrees = 35
|
| 34 |
normal_smoothing_kernel = 5
|
| 35 |
min_plane_pixels = 1500
|