github-actions[bot] commited on
Commit
0f988fe
·
1 Parent(s): 441abd1

Automated Deploy: d9c36ec28af55b09571a9753beea9774ce67021f

Browse files
services/jobs/conversion.py CHANGED
@@ -87,39 +87,9 @@ def run_conversion_task(job_id: str, upload_path: Path):
87
  estimatedRemainingMs=estimate_ms,
88
  )
89
 
90
- # ── Phase 1: Fast preview (outside GPU lock if possible) ──
91
- try:
92
- from services.pipeline.preview_builder import build_preview_bundle
93
-
94
- t_preview = time.perf_counter()
95
- update_conversion_job(
96
- job_id,
97
- status=JobStatus.PROCESSING,
98
- phase=PipelinePhase.SEGMENTATION,
99
- progress=0,
100
- message="Quick preview\u2026",
101
- startedAt=datetime.now(timezone.utc).isoformat(),
102
- )
103
- preview_bundle = build_preview_bundle(image_bytes)
104
- preview_binary = build_manifest_segmentation_bundle(
105
- preview_bundle, job_id, image_url=image_url, include_image=False,
106
- )
107
- (JOB_DIR / f"{job_id}.vizbundle").write_bytes(preview_binary)
108
-
109
- preview_ms = (time.perf_counter() - t_preview) * 1000
110
- job = read_job(job_id)
111
- job["status"] = JobStatus.PREVIEW_READY
112
- job["phase"] = "preview-ready"
113
- job["progress"] = 40
114
- job["message"] = "Preview ready \u2014 enhancing quality\u2026"
115
- job["previewDurationMs"] = round(preview_ms)
116
- job["outputFormat"] = "split-vizbundle"
117
- write_job(job)
118
- print(f"[JOB {job_id[:8]}] Preview ready in {preview_ms / 1000:.2f}s", flush=True)
119
- except Exception as preview_exc:
120
- print(f"[JOB {job_id[:8]}] Preview failed ({preview_exc}), continuing with full pipeline.", flush=True)
121
-
122
- # ── Phase 2: Full HD pipeline ──
123
  gpu_wait_started = time.perf_counter()
124
  with CONVERSION_GPU_LOCK:
125
  gpu_queue_wait_ms = (time.perf_counter() - gpu_wait_started) * 1000
@@ -128,7 +98,7 @@ def run_conversion_task(job_id: str, upload_path: Path):
128
  job_id,
129
  status=JobStatus.PROCESSING,
130
  phase=PipelinePhase.SEGMENTATION,
131
- progress=40,
132
  phase_progress=0,
133
  message="Analyzing floor (HD)\u2026",
134
  estimatedTotalMs=estimate_ms,
@@ -142,13 +112,11 @@ def run_conversion_task(job_id: str, upload_path: Path):
142
  completed_phases.add(phase)
143
  elapsed_ms = (time.perf_counter() - t_start) * 1000
144
  remaining_ms = max(0, estimate_ms - elapsed_ms)
145
- base_progress = 40 # preview accounts for 0-40%
146
  hd_progress = weighted_conversion_progress(completed_phases, phase, phase_progress)
147
- overall = base_progress + round(hd_progress * 0.6) # HD is 40-100%
148
  update_conversion_job(
149
  job_id,
150
  phase=phase,
151
- progress=overall,
152
  phase_progress=round(phase_progress),
153
  message=f"Enhancing {phase.replace('-', ' ')}\u2026",
154
  estimatedRemainingMs=round(remaining_ms),
 
87
  estimatedRemainingMs=estimate_ms,
88
  )
89
 
90
+ # Run one authoritative HD pass. The former preview repeated
91
+ # segmentation and full-resolution CPU work, then was normally missed
92
+ # before the status returned to PROCESSING.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  gpu_wait_started = time.perf_counter()
94
  with CONVERSION_GPU_LOCK:
95
  gpu_queue_wait_ms = (time.perf_counter() - gpu_wait_started) * 1000
 
98
  job_id,
99
  status=JobStatus.PROCESSING,
100
  phase=PipelinePhase.SEGMENTATION,
101
+ progress=0,
102
  phase_progress=0,
103
  message="Analyzing floor (HD)\u2026",
104
  estimatedTotalMs=estimate_ms,
 
112
  completed_phases.add(phase)
113
  elapsed_ms = (time.perf_counter() - t_start) * 1000
114
  remaining_ms = max(0, estimate_ms - elapsed_ms)
 
115
  hd_progress = weighted_conversion_progress(completed_phases, phase, phase_progress)
 
116
  update_conversion_job(
117
  job_id,
118
  phase=phase,
119
+ progress=hd_progress,
120
  phase_progress=round(phase_progress),
121
  message=f"Enhancing {phase.replace('-', ' ')}\u2026",
122
  estimatedRemainingMs=round(remaining_ms),
services/pipeline/packaging.py CHANGED
@@ -84,6 +84,52 @@ def make_binary_ref(path: str, data: bytes, dtype: str) -> dict:
84
  }
85
 
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  def encode_mask_bitset(mask_bytes: bytes, pixel_count: int) -> bytes:
88
  """Encode uint32 pixel indices as an exact, least-significant-bit-first bitset."""
89
  indices = np.frombuffer(mask_bytes, dtype=np.uint32)
@@ -143,7 +189,6 @@ def build_manifest_segmentation_bundle(
143
  }
144
 
145
  lazy_asset_fields = {
146
- "surfaceUv": ("surface-uv.f32", "float32"),
147
  "surfacePlaneIds": ("surface-plane-ids.u8", "uint8"),
148
  "shadeMap": ("shade.u8", "uint8"),
149
  "showroomShadeMap": ("showroom-shade.u8", "uint8"),
@@ -170,6 +215,18 @@ def build_manifest_segmentation_bundle(
170
  f"{len(mask_bytes)} -> {len(mask_bitset)} bytes",
171
  flush=True,
172
  )
 
 
 
 
 
 
 
 
 
 
 
 
173
  for field, (filename, dtype) in lazy_asset_fields.items():
174
  value = segment.get(field)
175
  if value is None:
 
84
  }
85
 
86
 
87
+ def encode_surface_uv_asset(value) -> tuple[bytes, dict]:
88
+ """Quantize smooth metric UV pairs and delta-code them for HTTP gzip."""
89
+ if isinstance(value, np.ndarray):
90
+ surface_uv = np.asarray(value, dtype=np.float32).reshape(-1)
91
+ elif isinstance(value, str):
92
+ surface_uv = np.frombuffer(base64.b64decode(value), dtype=np.float32)
93
+ else:
94
+ surface_uv = np.frombuffer(bytes(value), dtype=np.float32)
95
+
96
+ if surface_uv.size == 0 or surface_uv.size % 2:
97
+ data = surface_uv.astype("<f4", copy=False).tobytes()
98
+ return data, {"dtype": "float32"}
99
+
100
+ uv_pairs = surface_uv.reshape(-1, 2)
101
+ valid_pairs = np.isfinite(uv_pairs).all(axis=1)
102
+ if not valid_pairs.any():
103
+ data = surface_uv.astype("<f4", copy=False).tobytes()
104
+ return data, {"dtype": "float32"}
105
+
106
+ finite_uv = uv_pairs[valid_pairs]
107
+ uv_offset = finite_uv.min(axis=0).astype(np.float64)
108
+ uv_max = finite_uv.max(axis=0).astype(np.float64)
109
+ # Reserve 65535/65535 as the invalid-UV sentinel.
110
+ uv_scale = (uv_max - uv_offset) / 65534.0
111
+ safe_scale = np.where(uv_scale > 0, uv_scale, 1.0)
112
+ quantized = np.full(uv_pairs.shape, 65535, dtype=np.uint16)
113
+ finite_quantized = np.rint((finite_uv - uv_offset) / safe_scale)
114
+ quantized[valid_pairs] = np.clip(finite_quantized, 0, 65534).astype(np.uint16)
115
+
116
+ delta = np.empty_like(quantized)
117
+ if len(quantized):
118
+ delta[0] = quantized[0]
119
+ if len(quantized) > 1:
120
+ difference = quantized[1:].astype(np.int32) - quantized[:-1].astype(np.int32)
121
+ delta[1:] = np.bitwise_and(difference, 0xFFFF).astype(np.uint16)
122
+
123
+ data = delta.astype("<u2", copy=False).tobytes()
124
+ return data, {
125
+ "dtype": "uint16",
126
+ "encoding": "delta-quantized-uv-v1",
127
+ "elementCount": int(surface_uv.size),
128
+ "uvOffset": [float(uv_offset[0]), float(uv_offset[1])],
129
+ "uvScale": [float(uv_scale[0]), float(uv_scale[1])],
130
+ }
131
+
132
+
133
  def encode_mask_bitset(mask_bytes: bytes, pixel_count: int) -> bytes:
134
  """Encode uint32 pixel indices as an exact, least-significant-bit-first bitset."""
135
  indices = np.frombuffer(mask_bytes, dtype=np.uint32)
 
189
  }
190
 
191
  lazy_asset_fields = {
 
192
  "surfacePlaneIds": ("surface-plane-ids.u8", "uint8"),
193
  "shadeMap": ("shade.u8", "uint8"),
194
  "showroomShadeMap": ("showroom-shade.u8", "uint8"),
 
215
  f"{len(mask_bytes)} -> {len(mask_bitset)} bytes",
216
  flush=True,
217
  )
218
+ surface_uv = segment.get("surfaceUv")
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_name = f"s{segment_index}-surface-uv.{extension}"
223
+ (asset_dir / asset_name).write_bytes(data)
224
+ segment_metadata["surfaceUv"] = {
225
+ **make_binary_ref(asset_name, data, encoding_metadata["dtype"]),
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)
232
  if value is None: