Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -215,6 +215,36 @@ class ReconstructionRunner:
|
|
| 215 |
"source": source,
|
| 216 |
}
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
# ------------------------------------------------------------------
|
| 219 |
# COLMAP integration
|
| 220 |
# ------------------------------------------------------------------
|
|
@@ -229,6 +259,12 @@ class ReconstructionRunner:
|
|
| 229 |
dense_dir = output_dir / "dense"
|
| 230 |
sparse_dir.mkdir(exist_ok=True)
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
commands = [
|
| 233 |
(
|
| 234 |
"Feature extraction",
|
|
@@ -240,7 +276,7 @@ class ReconstructionRunner:
|
|
| 240 |
"--image_path",
|
| 241 |
str(images_dir),
|
| 242 |
"--SiftExtraction.use_gpu",
|
| 243 |
-
|
| 244 |
"--SiftExtraction.max_image_size",
|
| 245 |
str(max_resolution),
|
| 246 |
],
|
|
@@ -253,7 +289,7 @@ class ReconstructionRunner:
|
|
| 253 |
"--database_path",
|
| 254 |
str(database_path),
|
| 255 |
"--SiftMatching.use_gpu",
|
| 256 |
-
|
| 257 |
],
|
| 258 |
),
|
| 259 |
(
|
|
|
|
| 215 |
"source": source,
|
| 216 |
}
|
| 217 |
|
| 218 |
+
def _colmap_gpu_mode(self) -> Tuple[bool, str]:
|
| 219 |
+
"""Determine whether COLMAP should use CUDA acceleration."""
|
| 220 |
+
|
| 221 |
+
override = os.environ.get("HF3D_COLMAP_USE_GPU")
|
| 222 |
+
if override is not None:
|
| 223 |
+
value = override.strip().lower()
|
| 224 |
+
if value in {"1", "true", "yes", "on"}:
|
| 225 |
+
return True, "Forced on via HF3D_COLMAP_USE_GPU"
|
| 226 |
+
if value in {"0", "false", "no", "off"}:
|
| 227 |
+
return False, "Disabled via HF3D_COLMAP_USE_GPU"
|
| 228 |
+
|
| 229 |
+
if shutil.which("nvidia-smi") is None:
|
| 230 |
+
return False, "nvidia-smi not found; assuming CPU-only environment"
|
| 231 |
+
|
| 232 |
+
try:
|
| 233 |
+
probe = subprocess.run(
|
| 234 |
+
["nvidia-smi"],
|
| 235 |
+
stdout=subprocess.PIPE,
|
| 236 |
+
stderr=subprocess.STDOUT,
|
| 237 |
+
text=True,
|
| 238 |
+
timeout=5,
|
| 239 |
+
)
|
| 240 |
+
except Exception:
|
| 241 |
+
return False, "nvidia-smi probe failed; defaulting to CPU"
|
| 242 |
+
|
| 243 |
+
if probe.returncode != 0:
|
| 244 |
+
return False, "nvidia-smi returned non-zero exit code; defaulting to CPU"
|
| 245 |
+
|
| 246 |
+
return True, "Detected NVIDIA GPU via nvidia-smi"
|
| 247 |
+
|
| 248 |
# ------------------------------------------------------------------
|
| 249 |
# COLMAP integration
|
| 250 |
# ------------------------------------------------------------------
|
|
|
|
| 259 |
dense_dir = output_dir / "dense"
|
| 260 |
sparse_dir.mkdir(exist_ok=True)
|
| 261 |
|
| 262 |
+
use_gpu, gpu_reason = self._colmap_gpu_mode()
|
| 263 |
+
logs.append(
|
| 264 |
+
f"COLMAP GPU acceleration: {'enabled' if use_gpu else 'disabled'} ({gpu_reason})."
|
| 265 |
+
)
|
| 266 |
+
gpu_flag = "1" if use_gpu else "0"
|
| 267 |
+
|
| 268 |
commands = [
|
| 269 |
(
|
| 270 |
"Feature extraction",
|
|
|
|
| 276 |
"--image_path",
|
| 277 |
str(images_dir),
|
| 278 |
"--SiftExtraction.use_gpu",
|
| 279 |
+
gpu_flag,
|
| 280 |
"--SiftExtraction.max_image_size",
|
| 281 |
str(max_resolution),
|
| 282 |
],
|
|
|
|
| 289 |
"--database_path",
|
| 290 |
str(database_path),
|
| 291 |
"--SiftMatching.use_gpu",
|
| 292 |
+
gpu_flag,
|
| 293 |
],
|
| 294 |
),
|
| 295 |
(
|