modventures commited on
Commit
799b97a
·
verified ·
1 Parent(s): b396a32

Dev Deploy: dce9644

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ data/test_output.json filter=lfs diff=lfs merge=lfs -text
.gitignore CHANGED
@@ -35,9 +35,6 @@ Thumbs.db
35
  data/uploads/
36
  data/jobs/
37
 
38
- # Verification harness output — local debug artifacts, never deploy
39
- verify_out/
40
-
41
  # Logs
42
  *.log
43
  uvicorn.log
 
35
  data/uploads/
36
  data/jobs/
37
 
 
 
 
38
  # Logs
39
  *.log
40
  uvicorn.log
Dockerfile CHANGED
@@ -1,26 +1,20 @@
1
- FROM nvidia/cuda:12.6.3-runtime-ubuntu22.04
2
 
3
  # Set environment variables
4
  ENV PYTHONUNBUFFERED=1 \
5
  PYTHONDONTWRITEBYTECODE=1 \
6
  HF_HOME=/home/user/.cache/huggingface \
7
- VISUALIZER_CONFIG=visualizer.hf.toml \
8
- HOME=/home/user \
9
- DEBIAN_FRONTEND=noninteractive
10
 
11
- # Install Python and system dependencies
12
  RUN apt-get update && \
13
  apt-get install -y --no-install-recommends \
14
- python3.10 \
15
- python3.10-venv \
16
- python3-pip \
17
  git \
18
  ffmpeg \
19
  libglib2.0-0 \
20
  libgomp1 \
21
  build-essential && \
22
- ln -sf /usr/bin/python3.10 /usr/bin/python3 && \
23
- ln -sf /usr/bin/python3 /usr/bin/python && \
24
  rm -rf /var/lib/apt/lists/*
25
 
26
  # Set up a new user named "user" with UID 1000 for Hugging Face permissions
@@ -31,31 +25,10 @@ WORKDIR /app
31
  # Copy requirements files first
32
  COPY requirements-base.txt requirements-gpu-cu126.txt ./
33
 
34
- # Install CUDA PyTorch/Torchvision first, then other base requirements
35
  RUN pip install --no-cache-dir --upgrade pip && \
36
  pip install --no-cache-dir -r requirements-gpu-cu126.txt
37
 
38
- # R4-1 — bake the intrinsic-decomposition weights (~1.7 GB) into the image:
39
- # Space disk is ephemeral, so without this every wake re-downloads them
40
- # before the first conversion. We DOWNLOAD the checkpoints only — we must NOT
41
- # call load_models() here, because instantiating all five v2 stages at once
42
- # spikes CPU RAM past the build container's cap (exit 137 / OOMKilled). At
43
- # runtime load_models() finds these cached by filename in hub/checkpoints and
44
- # skips the network; only the tiny backbone source zips are fetched on first
45
- # request. The trusted_list write mirrors app._ensure_torch_hub_trust
46
- # (altered_midas prompts interactively without it and crashes headless
47
- # builds). chown in the SAME layer so the cache isn't duplicated into a
48
- # second layer.
49
- RUN python3 -c "import os, torch.hub as hub; \
50
- ckpt = os.path.join(hub.get_dir(), 'checkpoints'); \
51
- os.makedirs(ckpt, exist_ok=True); \
52
- open(os.path.join(hub.get_dir(), 'trusted_list'), 'a').write('rwightman_gen-efficientnet-pytorch\n'); \
53
- base = 'https://github.com/compphoto/Intrinsic/releases/download/v2.0'; \
54
- [hub.download_url_to_file(base + '/stage_%d.pt' % n, os.path.join(ckpt, 'stage_%d.pt' % n)) for n in range(5)]; \
55
- hub.download_url_to_file('https://download.pytorch.org/models/ig_resnext101_32x8-c38310e5.pth', os.path.join(ckpt, 'ig_resnext101_32x8-c38310e5.pth')); \
56
- print('intrinsic weights baked (download-only)')" && \
57
- chown -R user:1000 /home/user/.cache
58
-
59
  # Copy the rest of the application files
60
  COPY --chown=user:1000 . .
61
 
 
1
+ FROM python:3.12-slim
2
 
3
  # Set environment variables
4
  ENV PYTHONUNBUFFERED=1 \
5
  PYTHONDONTWRITEBYTECODE=1 \
6
  HF_HOME=/home/user/.cache/huggingface \
7
+ VISUALIZER_CONFIG=visualizer.gpu.toml \
8
+ HOME=/home/user
 
9
 
10
+ # Install system dependencies (git for compphoto/Intrinsic installation, ffmpeg, glib for OpenCV)
11
  RUN apt-get update && \
12
  apt-get install -y --no-install-recommends \
 
 
 
13
  git \
14
  ffmpeg \
15
  libglib2.0-0 \
16
  libgomp1 \
17
  build-essential && \
 
 
18
  rm -rf /var/lib/apt/lists/*
19
 
20
  # Set up a new user named "user" with UID 1000 for Hugging Face permissions
 
25
  # Copy requirements files first
26
  COPY requirements-base.txt requirements-gpu-cu126.txt ./
27
 
28
+ # Install CUDA PyTorch, MoGe, and the visualizer dependencies for GPU Spaces
29
  RUN pip install --no-cache-dir --upgrade pip && \
30
  pip install --no-cache-dir -r requirements-gpu-cu126.txt
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  # Copy the rest of the application files
33
  COPY --chown=user:1000 . .
34
 
Dockerfile.hf CHANGED
@@ -1,10 +1,10 @@
1
- FROM python:3.10-slim
2
 
3
  # Set environment variables
4
  ENV PYTHONUNBUFFERED=1 \
5
  PYTHONDONTWRITEBYTECODE=1 \
6
  HF_HOME=/home/user/.cache/huggingface \
7
- VISUALIZER_CONFIG=visualizer.hf.toml \
8
  HOME=/home/user
9
 
10
  # Install system dependencies (git for compphoto/Intrinsic installation, ffmpeg, glib for OpenCV)
@@ -23,12 +23,11 @@ RUN useradd -m -u 1000 user
23
  WORKDIR /app
24
 
25
  # Copy requirements files first
26
- COPY requirements-base.txt ./
27
 
28
- # Install CPU PyTorch/Torchvision first, then other base requirements
29
  RUN pip install --no-cache-dir --upgrade pip && \
30
- pip install --no-cache-dir torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu && \
31
- pip install --no-cache-dir -r requirements-base.txt
32
 
33
  # Copy the rest of the application files
34
  COPY --chown=user:1000 . .
 
1
+ FROM python:3.12-slim
2
 
3
  # Set environment variables
4
  ENV PYTHONUNBUFFERED=1 \
5
  PYTHONDONTWRITEBYTECODE=1 \
6
  HF_HOME=/home/user/.cache/huggingface \
7
+ VISUALIZER_CONFIG=visualizer.gpu.toml \
8
  HOME=/home/user
9
 
10
  # Install system dependencies (git for compphoto/Intrinsic installation, ffmpeg, glib for OpenCV)
 
23
  WORKDIR /app
24
 
25
  # Copy requirements files first
26
+ COPY requirements-base.txt requirements-gpu-cu126.txt ./
27
 
28
+ # Install CUDA PyTorch, MoGe, and the visualizer dependencies for GPU Spaces
29
  RUN pip install --no-cache-dir --upgrade pip && \
30
+ pip install --no-cache-dir -r requirements-gpu-cu126.txt
 
31
 
32
  # Copy the rest of the application files
33
  COPY --chown=user:1000 . .
README.md CHANGED
@@ -33,7 +33,17 @@ GPU run:
33
  python3.12 -m venv .venv
34
  source .venv/bin/activate
35
  python -m pip install --upgrade pip
36
- python -m pip install --index-url https://download.pytorch.org/whl/cu126 torch==2.7.0 torchvision==0.22.0
37
- python -m pip install -r requirements-base.txt
38
  VISUALIZER_CONFIG=visualizer.gpu.toml uvicorn app:app --host 0.0.0.0 --port 8002
39
  ```
 
 
 
 
 
 
 
 
 
 
 
 
33
  python3.12 -m venv .venv
34
  source .venv/bin/activate
35
  python -m pip install --upgrade pip
36
+ python -m pip install -r requirements-gpu-cu126.txt
 
37
  VISUALIZER_CONFIG=visualizer.gpu.toml uvicorn app:app --host 0.0.0.0 --port 8002
38
  ```
39
+
40
+ Hugging Face GPU Spaces use the Dockerfile in this directory. It installs the
41
+ CUDA 12.6 PyTorch stack and starts FastAPI on port `7860` with
42
+ `visualizer.gpu.toml`.
43
+
44
+ The GPU profile uses `shi-labs/oneformer_ade20k_swin_large` for segmentation,
45
+ `Ruicheng/moge-2-vitl-normal` for metric point maps, surface normals, and camera
46
+ intrinsics, and `depth-anything/Depth-Anything-V2-Metric-Indoor-Large-hf` for
47
+ metric depth. If MoGe cannot load or its floor-plane fit is unreliable, the
48
+ service falls back to Depth Anything V2 metric depth, then to the existing
49
+ image-space homography.
SETUP.md CHANGED
@@ -22,12 +22,12 @@ cd backend/floor-visualizer
22
  python3.12 -m venv .venv
23
  source .venv/bin/activate
24
  python -m pip install --upgrade pip
25
- python -m pip install --index-url https://download.pytorch.org/whl/cu126 torch==2.7.0 torchvision==0.22.0
26
- python -m pip install -r requirements-base.txt
27
  VISUALIZER_CONFIG=visualizer.gpu.toml uvicorn app:app --host 0.0.0.0 --port 8002
28
  ```
29
 
30
  The first GPU run downloads `shi-labs/oneformer_ade20k_swin_large` and the depth model into the Hugging Face cache.
 
31
 
32
  ## Notes
33
 
 
22
  python3.12 -m venv .venv
23
  source .venv/bin/activate
24
  python -m pip install --upgrade pip
25
+ python -m pip install -r requirements-gpu-cu126.txt
 
26
  VISUALIZER_CONFIG=visualizer.gpu.toml uvicorn app:app --host 0.0.0.0 --port 8002
27
  ```
28
 
29
  The first GPU run downloads `shi-labs/oneformer_ade20k_swin_large` and the depth model into the Hugging Face cache.
30
+ It also downloads `Ruicheng/moge-2-vitl-normal`, the primary GPU geometry model.
31
 
32
  ## Notes
33
 
app.py CHANGED
The diff for this file is too large to render. See raw diff
 
data/test_output.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:46ded1ce80506b2076b3a53da7e22891573b837e0db342b66ebf3b187a005a85
3
+ size 17921826
requirements-base.txt CHANGED
@@ -1,4 +1,3 @@
1
- tomli==2.2.1
2
  aiofiles==24.1.0
3
  fastapi==0.115.12
4
  huggingface-hub==0.32.0
@@ -8,7 +7,6 @@ pillow==11.2.1
8
  python-multipart==0.0.20
9
  safetensors==0.5.3
10
  timm==1.0.15
11
- # transformers >=4.45 required: Depth-Anything-V2 metric checkpoints (R1-1)
12
  tokenizers==0.20.3
13
  transformers==4.46.3
14
  uvicorn==0.34.2
 
 
1
  aiofiles==24.1.0
2
  fastapi==0.115.12
3
  huggingface-hub==0.32.0
 
7
  python-multipart==0.0.20
8
  safetensors==0.5.3
9
  timm==1.0.15
 
10
  tokenizers==0.20.3
11
  transformers==4.46.3
12
  uvicorn==0.34.2
requirements-gpu-cu126.txt CHANGED
@@ -3,5 +3,4 @@
3
  torch==2.7.0+cu126
4
  torchvision==0.22.0+cu126
5
  triton==3.3.0
6
- # R1-5 — MoGe-2 point-map geometry
7
  git+https://github.com/microsoft/MoGe.git
 
3
  torch==2.7.0+cu126
4
  torchvision==0.22.0+cu126
5
  triton==3.3.0
 
6
  git+https://github.com/microsoft/MoGe.git
requirements.txt CHANGED
@@ -71,12 +71,12 @@ sniffio==1.3.1
71
  starlette==0.46.2
72
  sympy==1.14.0
73
  timm==1.0.15
74
- tokenizers==0.20.3
75
  tomlkit==0.13.2
76
  torch==2.7.0
77
  torchvision==0.22.0
78
  tqdm==4.67.1
79
- transformers==4.46.3
80
  triton==3.3.0
81
  typer==0.15.4
82
  typing-inspection==0.4.1
 
71
  starlette==0.46.2
72
  sympy==1.14.0
73
  timm==1.0.15
74
+ tokenizers==0.15.2
75
  tomlkit==0.13.2
76
  torch==2.7.0
77
  torchvision==0.22.0
78
  tqdm==4.67.1
79
+ transformers==4.38.2
80
  triton==3.3.0
81
  typer==0.15.4
82
  typing-inspection==0.4.1
start.sh CHANGED
@@ -5,10 +5,10 @@
5
  set -e
6
 
7
  echo "==> Installing dependencies..."
8
- pip install --no-cache-dir -r requirements-linux-cpu.txt
9
 
10
  echo "==> Creating data directories..."
11
  mkdir -p data/uploads data/jobs
12
 
13
  echo "==> Starting server..."
14
- VISUALIZER_CONFIG=visualizer.hf.toml uvicorn app:app --host 0.0.0.0 --port 7860 --workers 1
 
5
  set -e
6
 
7
  echo "==> Installing dependencies..."
8
+ pip install --no-cache-dir -r requirements-gpu-cu126.txt
9
 
10
  echo "==> Creating data directories..."
11
  mkdir -p data/uploads data/jobs
12
 
13
  echo "==> Starting server..."
14
+ VISUALIZER_CONFIG=visualizer.gpu.toml uvicorn app:app --host 0.0.0.0 --port 8002 --workers 1
test_floor_geometry.py ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ import numpy as np
4
+
5
+ import app
6
+
7
+
8
+ class MetricFloorGeometryTests(unittest.TestCase):
9
+ def test_surface_uv_quality_keeps_smooth_complete_uvs(self):
10
+ height, width = 60, 80
11
+ yy, xx = np.mgrid[0:height, 0:width]
12
+ surface = np.ones((height, width), dtype=np.uint8)
13
+ surface_indices = np.flatnonzero(surface.ravel()).astype(np.uint32)
14
+ uv = np.column_stack((
15
+ xx.ravel()[surface_indices] * 0.02,
16
+ yy.ravel()[surface_indices] * 0.02,
17
+ )).astype(np.float32)
18
+ plane_ids = np.zeros(len(surface_indices), dtype=np.uint8)
19
+
20
+ quality = app.analyze_surface_uv_quality(surface, surface_indices, uv, plane_ids)
21
+
22
+ self.assertTrue(quality["surfaceUvEnabled"])
23
+ self.assertEqual(quality["textureMappingMode"], "surface-uv")
24
+ self.assertEqual(quality["textureMappingReason"], "surface-uv-quality-ok")
25
+
26
+ def test_surface_uv_quality_rejects_noisy_far_region_jumps(self):
27
+ height, width = 60, 80
28
+ yy, xx = np.mgrid[0:height, 0:width]
29
+ surface = np.ones((height, width), dtype=np.uint8)
30
+ surface_indices = np.flatnonzero(surface.ravel()).astype(np.uint32)
31
+ uv_grid = np.dstack((xx * 0.02, yy * 0.02)).astype(np.float32)
32
+ uv_grid[:20, 40::2, 0] += 4.0
33
+ uv = uv_grid.reshape(-1, 2)[surface_indices]
34
+ plane_ids = np.zeros(len(surface_indices), dtype=np.uint8)
35
+
36
+ quality = app.analyze_surface_uv_quality(surface, surface_indices, uv, plane_ids)
37
+
38
+ self.assertFalse(quality["surfaceUvEnabled"])
39
+ self.assertEqual(quality["textureMappingMode"], "regularized-floor-plane")
40
+ self.assertEqual(quality["textureMappingReason"], "noisy-surface-uv")
41
+
42
+ def test_surface_uv_quality_rejects_partial_invalid_uvs(self):
43
+ height, width = 60, 80
44
+ yy, xx = np.mgrid[0:height, 0:width]
45
+ surface = np.ones((height, width), dtype=np.uint8)
46
+ surface_indices = np.flatnonzero(surface.ravel()).astype(np.uint32)
47
+ uv = np.column_stack((
48
+ xx.ravel()[surface_indices] * 0.02,
49
+ yy.ravel()[surface_indices] * 0.02,
50
+ )).astype(np.float32)
51
+ uv[:80] = np.nan
52
+ plane_ids = np.zeros(len(surface_indices), dtype=np.uint8)
53
+
54
+ quality = app.analyze_surface_uv_quality(surface, surface_indices, uv, plane_ids)
55
+
56
+ self.assertFalse(quality["surfaceUvEnabled"])
57
+ self.assertEqual(quality["textureMappingReason"], "incomplete-surface-uv")
58
+
59
+ def test_surface_edge_coverage_closes_small_boundary_gaps(self):
60
+ surface = np.zeros((80, 120), dtype=np.uint8)
61
+ surface[40:75, 20:100] = 1
62
+ surface[40:48, 55:57] = 0
63
+ protected = np.zeros_like(surface, dtype=bool)
64
+
65
+ repaired, metadata = app.improve_surface_edge_coverage(surface, protected)
66
+
67
+ self.assertGreater(metadata["surfacePixelsAfterEdgeFix"], metadata["surfacePixelsBeforeEdgeFix"])
68
+ self.assertEqual(int(repaired[44, 56]), 1)
69
+
70
+ def test_surface_edge_coverage_respects_protected_pixels(self):
71
+ surface = np.zeros((80, 120), dtype=np.uint8)
72
+ surface[40:75, 20:100] = 1
73
+ protected = np.zeros_like(surface, dtype=bool)
74
+ protected[35:45, 95:110] = True
75
+
76
+ repaired, _ = app.improve_surface_edge_coverage(surface, protected)
77
+
78
+ self.assertFalse(repaired[protected].any())
79
+ self.assertEqual(int(repaired[42, 99]), 0)
80
+
81
+ def test_point_map_produces_moge_transform(self):
82
+ height, width = 360, 640
83
+ yy, xx = np.mgrid[0:height, 0:width]
84
+ mask = (yy > 220).astype(np.uint8)
85
+ focal = max(height, width) * 0.95
86
+ depth = np.full((height, width), 20.0, dtype=np.float32)
87
+ depth[mask > 0] = 1.6 * focal / (yy[mask > 0] - (height - 1) * 0.5)
88
+ points = np.dstack((
89
+ (xx - (width - 1) * 0.5) * depth / focal,
90
+ (yy - (height - 1) * 0.5) * depth / focal,
91
+ depth,
92
+ )).astype(np.float32)
93
+ normals = np.zeros_like(points)
94
+ normals[:, :, 1] = 1.0
95
+
96
+ result = app.fit_metric_floor_transform(
97
+ mask,
98
+ points,
99
+ valid_mask=mask > 0,
100
+ normals_map=normals,
101
+ intrinsics=np.array([[focal, 0, width / 2], [0, focal, height / 2], [0, 0, 1]], dtype=np.float32),
102
+ provider="moge-2",
103
+ )
104
+
105
+ self.assertIsNotNone(result)
106
+ self.assertEqual(result["geometryProvider"], "moge-2")
107
+ self.assertEqual(len(result["cameraIntrinsics"]), 9)
108
+ self.assertGreater(result["geometryConfidence"], 0.35)
109
+
110
+ def test_metric_depth_produces_meter_space_transform(self):
111
+ height, width = 360, 640
112
+ yy, xx = np.mgrid[0:height, 0:width]
113
+ mask = (yy > 220).astype(np.uint8)
114
+ focal = max(height, width) * 0.95
115
+ depth = np.full((height, width), 20.0, dtype=np.float32)
116
+ depth[mask > 0] = 1.6 * focal / (yy[mask > 0] - (height - 1) * 0.5)
117
+
118
+ original_name = app.DEPTH_MODEL_NAME
119
+ app.DEPTH_MODEL_NAME = "depth-anything/Depth-Anything-V2-Metric-Indoor-Large-hf"
120
+ try:
121
+ result = app.estimate_metric_floor_transform(mask, depth)
122
+ finally:
123
+ app.DEPTH_MODEL_NAME = original_name
124
+
125
+ self.assertIsNotNone(result)
126
+ self.assertEqual(len(result["floorTransform"]), 9)
127
+ self.assertGreater(result["geometryConfidence"], 0.35)
128
+ self.assertLess(result["fitResidualMeters"], 0.18)
129
+
130
+ def test_relative_depth_is_normalized_for_backprojection(self):
131
+ height, width = 360, 640
132
+ yy, _ = np.mgrid[0:height, 0:width]
133
+ mask = (yy > 220).astype(np.uint8)
134
+ depth = np.zeros((height, width), dtype=np.float32)
135
+ depth[mask > 0] = (yy[mask > 0] - 220) / float(height - 220)
136
+
137
+ depth_for_points, depth_scale = app.prepare_depth_for_backprojection(depth, mask, False)
138
+ intrinsics = app.default_camera_intrinsics(width, height)
139
+ points = app.backproject_depth(depth_for_points, intrinsics)
140
+
141
+ self.assertEqual(depth_scale, "relative-normalized")
142
+ self.assertEqual(points.shape, (height, width, 3))
143
+ self.assertTrue(np.isfinite(points[mask > 0]).all())
144
+
145
+ def test_plane_fit_flag_preserves_homography_fallback(self):
146
+ mask = np.ones((100, 100), dtype=np.uint8)
147
+ depth = np.ones((100, 100), dtype=np.float32)
148
+
149
+ original_flag = app.ENABLE_PLANE_FIT
150
+ app.ENABLE_PLANE_FIT = False
151
+ try:
152
+ result = app.estimate_metric_floor_transform(mask, depth)
153
+ finally:
154
+ app.ENABLE_PLANE_FIT = original_flag
155
+
156
+ self.assertIsNone(result)
157
+
158
+ def test_multi_plane_surface_mapping_assigns_floor_and_wall(self):
159
+ height, width = 120, 120
160
+ yy, xx = np.mgrid[0:height, 0:width]
161
+ mask = np.zeros((height, width), dtype=np.uint8)
162
+ mask[60:, :] = 1
163
+ mask[20:60, 30:90] = 1
164
+
165
+ points = np.zeros((height, width, 3), dtype=np.float32)
166
+ normals = np.zeros_like(points)
167
+
168
+ floor = mask.astype(bool) & (yy >= 60)
169
+ points[floor, 0] = (xx[floor] - width / 2) / 40.0
170
+ points[floor, 1] = 1.0
171
+ points[floor, 2] = (yy[floor] - 60) / 40.0 + 1.0
172
+ normals[floor] = np.array([0.0, 1.0, 0.0], dtype=np.float32)
173
+
174
+ wall = mask.astype(bool) & (yy < 60)
175
+ points[wall, 0] = (xx[wall] - width / 2) / 40.0
176
+ points[wall, 1] = (60 - yy[wall]) / 40.0
177
+ points[wall, 2] = 1.0
178
+ normals[wall] = np.array([0.0, 0.0, 1.0], dtype=np.float32)
179
+
180
+ geometry = {
181
+ "provider": "synthetic",
182
+ "points": points,
183
+ "normals": normals,
184
+ "validMask": mask > 0,
185
+ "intrinsics": np.eye(3, dtype=np.float32),
186
+ }
187
+
188
+ original_min = app.SURFACE_MIN_PLANE_PIXELS
189
+ app.SURFACE_MIN_PLANE_PIXELS = 1000
190
+ try:
191
+ surface_indices = np.flatnonzero(mask.ravel()).astype(np.uint32)
192
+ mapping = app.build_surface_uv_mapping(mask, surface_indices, geometry)
193
+ finally:
194
+ app.SURFACE_MIN_PLANE_PIXELS = original_min
195
+
196
+ self.assertIsNotNone(mapping)
197
+ self.assertGreaterEqual(len(mapping["planes"]), 2)
198
+ self.assertEqual(mapping["uv"].shape, (len(surface_indices), 2))
199
+ self.assertTrue(np.isfinite(mapping["uv"]).all())
200
+ self.assertGreaterEqual(len(set(mapping["planeIds"].tolist())), 2)
201
+ self.assertTrue(any(plane["isFloor"] for plane in mapping["planes"]))
202
+
203
+ def test_surface_mapping_falls_back_when_normals_are_missing(self):
204
+ height, width = 120, 120
205
+ yy, xx = np.mgrid[0:height, 0:width]
206
+ mask = (yy >= 40).astype(np.uint8)
207
+
208
+ points = np.zeros((height, width, 3), dtype=np.float32)
209
+ floor = mask.astype(bool)
210
+ points[floor, 0] = (xx[floor] - width / 2) / 45.0
211
+ points[floor, 1] = 1.0
212
+ points[floor, 2] = (yy[floor] - 40) / 45.0 + 1.0
213
+ normals = np.zeros_like(points)
214
+
215
+ geometry = {
216
+ "provider": "synthetic",
217
+ "points": points,
218
+ "normals": normals,
219
+ "validMask": mask > 0,
220
+ "intrinsics": np.eye(3, dtype=np.float32),
221
+ }
222
+
223
+ original_min = app.SURFACE_MIN_PLANE_PIXELS
224
+ app.SURFACE_MIN_PLANE_PIXELS = 1000
225
+ try:
226
+ surface_indices = np.flatnonzero(mask.ravel()).astype(np.uint32)
227
+ mapping = app.build_surface_uv_mapping(mask, surface_indices, geometry)
228
+ finally:
229
+ app.SURFACE_MIN_PLANE_PIXELS = original_min
230
+
231
+ self.assertIsNotNone(mapping)
232
+ self.assertGreaterEqual(len(mapping["planes"]), 1)
233
+ self.assertFalse(mapping["normalsReliable"])
234
+ self.assertIn("distance-only", {plane["fitMode"] for plane in mapping["planes"]})
235
+ self.assertEqual(mapping["uv"].shape, (len(surface_indices), 2))
236
+ self.assertTrue(np.isfinite(mapping["uv"]).all())
237
+
238
+
239
+ if __name__ == "__main__":
240
+ unittest.main()
visualizer.gpu.toml CHANGED
@@ -4,19 +4,33 @@
4
 
5
  [models]
6
  segmentation_model = "oneformer"
 
 
7
  oneformer_model_name = "shi-labs/oneformer_ade20k_swin_large"
8
  mask2former_model_name = "facebook/mask2former-swin-small-ade-semantic"
9
  segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
10
- depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Small-hf"
11
  intrinsic_model_version = "v2"
12
- # R1-5 — MoGe-2 point-map geometry (CUDA-only; falls back to depth on failure)
13
- geometry_model = "moge"
14
- moge_model_name = "Ruicheng/moge-2-vitl-normal"
15
 
16
  [runtime]
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"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  [models]
6
  segmentation_model = "oneformer"
7
+ geometry_model = "moge"
8
+ moge_model_name = "Ruicheng/moge-2-vitl-normal"
9
  oneformer_model_name = "shi-labs/oneformer_ade20k_swin_large"
10
  mask2former_model_name = "facebook/mask2former-swin-small-ade-semantic"
11
  segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
12
+ depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Large-hf"
13
  intrinsic_model_version = "v2"
 
 
 
14
 
15
  [runtime]
16
  enable_depth_estimation = true
 
17
  enable_moge_geometry = true
18
+ enable_plane_fit = true
19
  enable_multi_plane_surfaces = true
20
+ enable_intrinsic_shading = true
21
+ enable_shading_transfer = true
22
  data_dir = "data"
23
+
24
+ [surface_mapping]
25
+ ransac_distance_threshold = 0.04
26
+ max_planes = 5
27
+ normal_angle_threshold_degrees = 35
28
+ normal_smoothing_kernel = 5
29
+ min_plane_pixels = 1500
30
+ edge_close_ratio = 0.006
31
+ edge_kernel_ratio = 0.004
32
+ edge_dilation_iterations = 1
33
+ uv_min_coverage = 0.995
34
+ uv_max_bad_neighbor_ratio = 0.035
35
+ uv_max_jump_ratio = 8.0
36
+ uv_absolute_jump_meters = 0.35
visualizer.hf.toml CHANGED
@@ -1,20 +1,36 @@
1
- # Preset for Hugging Face Spaces (CPU-friendly with depth & shading enabled)
2
  # Run with:
3
  # VISUALIZER_CONFIG=visualizer.hf.toml uvicorn app:app --host 0.0.0.0 --port 7860
4
 
5
  [models]
6
  segmentation_model = "oneformer"
7
- oneformer_model_name = "shi-labs/oneformer_ade20k_swin_large"
8
- depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Small-hf"
9
- intrinsic_model_version = "v2"
10
- # R1-5 — MoGe-2 point-map geometry (CUDA-only at runtime; depth fallback)
11
  geometry_model = "moge"
12
  moge_model_name = "Ruicheng/moge-2-vitl-normal"
 
 
 
 
 
13
 
14
  [runtime]
15
  enable_depth_estimation = true
16
- enable_intrinsic_shading = true
17
  enable_moge_geometry = true
18
- # R1-6 (Pull 2) — per-region plane charts for disjoint floor regions
19
  enable_multi_plane_surfaces = true
 
 
20
  data_dir = "data"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Preset for Hugging Face GPU Spaces.
2
  # Run with:
3
  # VISUALIZER_CONFIG=visualizer.hf.toml uvicorn app:app --host 0.0.0.0 --port 7860
4
 
5
  [models]
6
  segmentation_model = "oneformer"
 
 
 
 
7
  geometry_model = "moge"
8
  moge_model_name = "Ruicheng/moge-2-vitl-normal"
9
+ oneformer_model_name = "shi-labs/oneformer_ade20k_swin_large"
10
+ mask2former_model_name = "facebook/mask2former-swin-small-ade-semantic"
11
+ segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
12
+ depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Large-hf"
13
+ intrinsic_model_version = "v2"
14
 
15
  [runtime]
16
  enable_depth_estimation = true
 
17
  enable_moge_geometry = true
18
+ enable_plane_fit = true
19
  enable_multi_plane_surfaces = true
20
+ enable_intrinsic_shading = true
21
+ enable_shading_transfer = true
22
  data_dir = "data"
23
+
24
+ [surface_mapping]
25
+ ransac_distance_threshold = 0.04
26
+ max_planes = 5
27
+ normal_angle_threshold_degrees = 35
28
+ normal_smoothing_kernel = 5
29
+ min_plane_pixels = 1500
30
+ edge_close_ratio = 0.006
31
+ edge_kernel_ratio = 0.004
32
+ edge_dilation_iterations = 1
33
+ uv_min_coverage = 0.995
34
+ uv_max_bad_neighbor_ratio = 0.035
35
+ uv_max_jump_ratio = 8.0
36
+ uv_absolute_jump_meters = 0.35
visualizer.local.toml CHANGED
@@ -5,9 +5,26 @@
5
  [models]
6
  segmentation_model = "segformer"
7
  segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
8
- depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Small-hf"
9
 
10
  [runtime]
11
  enable_depth_estimation = false
 
 
12
  enable_intrinsic_shading = false
 
13
  data_dir = "data"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  [models]
6
  segmentation_model = "segformer"
7
  segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
8
+ depth_model_name = "Intel/dpt-large"
9
 
10
  [runtime]
11
  enable_depth_estimation = false
12
+ enable_plane_fit = true
13
+ enable_multi_plane_surfaces = true
14
  enable_intrinsic_shading = false
15
+ enable_shading_transfer = true
16
  data_dir = "data"
17
+
18
+ [surface_mapping]
19
+ ransac_distance_threshold = 0.04
20
+ max_planes = 5
21
+ normal_angle_threshold_degrees = 35
22
+ normal_smoothing_kernel = 5
23
+ min_plane_pixels = 1500
24
+ edge_close_ratio = 0.006
25
+ edge_kernel_ratio = 0.004
26
+ edge_dilation_iterations = 1
27
+ uv_min_coverage = 0.995
28
+ uv_max_bad_neighbor_ratio = 0.035
29
+ uv_max_jump_ratio = 8.0
30
+ uv_absolute_jump_meters = 0.35
visualizer.segformer.toml CHANGED
@@ -6,9 +6,26 @@
6
  [models]
7
  segmentation_model = "segformer"
8
  segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
9
- depth_model_name = "depth-anything/Depth-Anything-V2-Metric-Indoor-Small-hf"
10
 
11
  [runtime]
12
  enable_depth_estimation = false
 
 
13
  enable_intrinsic_shading = false
 
14
  data_dir = "data"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  [models]
7
  segmentation_model = "segformer"
8
  segformer_model_name = "nvidia/segformer-b2-finetuned-ade-512-512"
9
+ depth_model_name = "Intel/dpt-large"
10
 
11
  [runtime]
12
  enable_depth_estimation = false
13
+ enable_plane_fit = true
14
+ enable_multi_plane_surfaces = true
15
  enable_intrinsic_shading = false
16
+ enable_shading_transfer = true
17
  data_dir = "data"
18
+
19
+ [surface_mapping]
20
+ ransac_distance_threshold = 0.04
21
+ max_planes = 5
22
+ normal_angle_threshold_degrees = 35
23
+ normal_smoothing_kernel = 5
24
+ min_plane_pixels = 1500
25
+ edge_close_ratio = 0.006
26
+ edge_kernel_ratio = 0.004
27
+ edge_dilation_iterations = 1
28
+ uv_min_coverage = 0.995
29
+ uv_max_bad_neighbor_ratio = 0.035
30
+ uv_max_jump_ratio = 8.0
31
+ uv_absolute_jump_meters = 0.35