junaid-simamdigital commited on
Commit
094eff3
·
verified ·
1 Parent(s): 57d2890

Initial ZeroGPU Simam3D runtime

Browse files
Files changed (1) hide show
  1. demo_pipeline.py +85 -0
demo_pipeline.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Run a deterministic CPU-only Simam3D geometry demo."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import hashlib
7
+ import json
8
+ from pathlib import Path
9
+
10
+ import numpy as np
11
+
12
+ from simam3d_core import (
13
+ fuse_point_views,
14
+ fusion_metrics,
15
+ synthetic_orbit_poses,
16
+ write_confidence_ply,
17
+ write_gaussian_ply,
18
+ )
19
+
20
+
21
+ def build_demo_views(size: int = 48):
22
+ yy, xx = np.mgrid[0:size, 0:size]
23
+ depth = (0.25 + 0.65 * ((xx / max(size - 1, 1) - 0.5) ** 2 + (yy / max(size - 1, 1) - 0.5) ** 2)).astype(np.float32)
24
+ views = []
25
+ poses = synthetic_orbit_poses(3)
26
+ for index, pose in enumerate(poses):
27
+ colors = np.zeros((size, size, 3), dtype=np.uint8)
28
+ colors[..., index] = 220
29
+ colors[..., (index + 1) % 3] = (xx * 255 // max(size - 1, 1)).astype(np.uint8)
30
+ confidence = np.full_like(depth, 1.0 - index * 0.1)
31
+ views.append((depth, confidence, None, pose, colors))
32
+ return views
33
+
34
+
35
+ def run_demo(output_dir: str | Path) -> dict:
36
+ output_dir = Path(output_dir)
37
+ output_dir.mkdir(parents=True, exist_ok=True)
38
+ result = fuse_point_views(build_demo_views(), voxel_size=0.03, max_points=20_000)
39
+ fused_path = output_dir / "simam3d_demo_fused.ply"
40
+ gaussian_path = output_dir / "simam3d_demo_gaussians.ply"
41
+ write_confidence_ply(fused_path, result.points, result.colors, result.weights, result.source_views, result.source_masks)
42
+ write_gaussian_ply(gaussian_path, result.points, result.colors, result.weights, result.source_views, result.source_masks)
43
+ summary = {"mode": "deterministic_cpu_demo", "metrics": fusion_metrics(result), "outputs": [str(fused_path), str(gaussian_path)]}
44
+ summary_path = output_dir / "simam3d_demo_summary.json"
45
+ summary_path.write_text(json.dumps(summary, indent=2), encoding="utf-8")
46
+ outputs = [fused_path, gaussian_path, summary_path]
47
+ manifest = {
48
+ "project": "Simam3D",
49
+ "version": "0.3.0",
50
+ "manifest_schema_version": 3,
51
+ "run_id": "deterministic-demo",
52
+ "backend": "Deterministic export smoke test (no AI)",
53
+ "model": "none (deterministic demo)",
54
+ "runtime": "CPU",
55
+ "view_count": 3,
56
+ "claims": {
57
+ "observed_input_geometry": False,
58
+ "generated_novel_views": False,
59
+ "metric_scale_reconstruction": False,
60
+ "learned_gaussian_optimization": False,
61
+ "reveal_content_is_verified": False,
62
+ },
63
+ "metrics": {"fused_point_count": summary["metrics"]["point_count"], **summary["metrics"]},
64
+ "outputs": [path.name for path in outputs],
65
+ "output_sha256": {
66
+ path.name: hashlib.sha256(path.read_bytes()).hexdigest() for path in outputs
67
+ },
68
+ }
69
+ manifest_path = output_dir / "simam3d_demo_run.json"
70
+ manifest_path.write_text(json.dumps(manifest, indent=2), encoding="utf-8")
71
+ summary["manifest"] = str(manifest_path)
72
+ return summary
73
+
74
+
75
+ def main(argv: list[str] | None = None) -> int:
76
+ parser = argparse.ArgumentParser(description=__doc__)
77
+ parser.add_argument("--output", type=Path, default=Path("demo_output"))
78
+ args = parser.parse_args(argv)
79
+ summary = run_demo(args.output)
80
+ print(json.dumps(summary, indent=2))
81
+ return 0
82
+
83
+
84
+ if __name__ == "__main__":
85
+ raise SystemExit(main())