Upload README.md
Browse files
README.md
CHANGED
|
@@ -1,26 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
- Source code: https://github.com/huggingface/ml-intern
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
model_id = "bdck/lightweightmr"
|
| 22 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 23 |
-
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 24 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
| 1 |
+
# LightweightMR β Pure-Python Mesh Reconstruction
|
| 2 |
+
|
| 3 |
+
Pure-Python reimplementation of **["High-Fidelity Lightweight Mesh Reconstruction from Point Clouds"](https://openaccess.thecvf.com/content/CVPR2025/papers/Zhang_High-Fidelity_Lightweight_Mesh_Reconstruction_from_Point_Clouds_CVPR_2025_paper.pdf)** (CVPR 2025 Highlight, Zhang et al.)
|
| 4 |
+
|
| 5 |
+
Input: **PLY / PCD / XYZ point cloud**
|
| 6 |
+
Output: **Triangle mesh (PLY / OBJ)**
|
| 7 |
+
|
| 8 |
---
|
| 9 |
+
|
| 10 |
+
## Quick Start
|
| 11 |
+
|
| 12 |
+
```bash
|
| 13 |
+
# Install
|
| 14 |
+
pip install torch numpy scipy
|
| 15 |
+
|
| 16 |
+
# Run
|
| 17 |
+
python -m lightweightmr -i myscan.ply -o mesh.ply
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
Or use the Python API:
|
| 21 |
+
|
| 22 |
+
```python
|
| 23 |
+
from lightweightmr.optimize import Runner
|
| 24 |
+
|
| 25 |
+
runner = Runner("myscan.ply", out_dir="./output", device="cpu")
|
| 26 |
+
v, f = runner.run(mesh_path="mesh.ply")
|
| 27 |
+
print(f"Mesh: {len(v)} vertices, {len(f)} faces")
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
---
|
| 31 |
|
| 32 |
+
## Two-Stage Pipeline
|
| 33 |
|
| 34 |
+
1. **SDF Learning** β Train a coordinate MLP with positional encoding to fit an implicit signed distance field to the point cloud.
|
| 35 |
+
2. **Vertex Generation + Delaunay Meshing** β
|
| 36 |
+
- Sample surface queries using SDF gradient projection.
|
| 37 |
+
- Train a vertex generator (MLP-only, no PointTransformerV3) to displace initial FPS samples.
|
| 38 |
+
- Move vertices to the learned SDF surface.
|
| 39 |
+
- Build a 3D Delaunay triangulation (`scipy.spatial.Delaunay`).
|
| 40 |
+
- Label tetrahedra as inside/outside by sampling the SDF.
|
| 41 |
+
- Extract the surface as facets between differently-labeled cells.
|
| 42 |
+
- Post-process with midpoint-vertex insertion to fix non-manifold edges.
|
| 43 |
|
| 44 |
+
---
|
| 45 |
|
| 46 |
+
## Differences from Original
|
|
|
|
| 47 |
|
| 48 |
+
| Feature | Original | This Reimplementation |
|
| 49 |
+
|---------|----------|------------------------|
|
| 50 |
+
| Hash encoding | CUDA hash grid + triplane | Positional encoding only (no CUDA compilation) |
|
| 51 |
+
| Vertex generator | PointTransformerV3 + MLP | MLP-only (faster, no `spconv`/`torch_scatter`) |
|
| 52 |
+
| KDTree | C++ libkdtree | `scipy.spatial.KDTree` |
|
| 53 |
+
| Delaunay meshing | CGAL C++ binary | `scipy.spatial.Delaunay` |
|
| 54 |
+
| Mesh extraction | CGAL `create_mesh` | Pure Python facet extraction |
|
| 55 |
+
| Dependencies | Open3D, CGAL, boost, `fpsample`, `mcubes`, `trimesh`, `torch_scatter`, `spconv` | **Only torch, numpy, scipy** |
|
| 56 |
|
| 57 |
+
**Trade-off**: Without the original hash encoding, the SDF stage converges slightly slower and may need a few more iterations on highly detailed scans. The meshing quality is comparable for typical genus-0/1 shapes.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## CLI Reference
|
| 62 |
|
|
|
|
|
|
|
|
|
|
| 63 |
```
|
| 64 |
+
python -m lightweightmr -i INPUT.ply -o OUTPUT.ply [options]
|
| 65 |
+
|
| 66 |
+
Options:
|
| 67 |
+
--device cpu | cuda (default: cpu)
|
| 68 |
+
--sdf-iters 20000 SDF training iterations
|
| 69 |
+
--vg-iters 8000 Vertex generator iterations
|
| 70 |
+
--sdf-lr 0.001
|
| 71 |
+
--vg-lr 0.001
|
| 72 |
+
--sdf-batch 5000 Batch size for SDF queries
|
| 73 |
+
--vertices 3400 Target vertex count
|
| 74 |
+
--update-size 5 Curriculum update steps
|
| 75 |
+
--update-ratio 1.2 Vertex count growth ratio
|
| 76 |
+
--k-samples 21 Interior samples per tetrahedron
|
| 77 |
+
--multires 8 Positional encoding frequencies
|
| 78 |
+
--project-sdf-level 0.0 Surface SDF level
|
| 79 |
+
--save-freq 2000 Checkpoint frequency
|
| 80 |
+
--resume-sdf PATH.pth Resume from SDF checkpoint
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## Package Structure
|
| 86 |
+
|
| 87 |
+
```
|
| 88 |
+
lightweightmr/
|
| 89 |
+
__init__.py
|
| 90 |
+
embedder.py β Positional encoding (NeRF-style)
|
| 91 |
+
sdfnet.py β SDF MLP network
|
| 92 |
+
vgnet.py β Vertex generator MLP
|
| 93 |
+
losses.py β All loss functions (Chamfer, eikonal, divergence, curvature, normals)
|
| 94 |
+
meshing.py β Delaunay + SDF labeling + surface extraction + midpoint fix
|
| 95 |
+
io_utils.py β PLY/PCD/XYZ loaders, mesh exporters, FPS, normal estimation
|
| 96 |
+
optimize.py β Two-stage Runner (SDF then VG + meshing)
|
| 97 |
+
__main__.py β CLI entry point
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
---
|
| 101 |
+
|
| 102 |
+
## Tips
|
| 103 |
+
|
| 104 |
+
- **CPU-only is slow** β SDF training on CPU with 20k iterations takes ~30β60 min depending on your machine. If you have a GPU, use `--device cuda`.
|
| 105 |
+
- **Vertex count** β Increase `--vertices` for finer detail (slower meshing). Decrease for faster/cleaner low-poly results.
|
| 106 |
+
- **Noise** β If your point cloud is noisy, increase `--sdf-iters` to 30k+ and use a small `--project-sdf-level` (e.g. `0.001`) to pull slightly inward.
|
| 107 |
+
- **Large clouds** β The code automatically subsamples to ~1/60th of input points for the SDF training set. For very large scans, reduce `--queries-size`.
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
+
|
| 111 |
+
## Citation
|
| 112 |
+
|
| 113 |
+
```bibtex
|
| 114 |
+
@inproceedings{zhang2025high,
|
| 115 |
+
title={High-Fidelity Lightweight Mesh Reconstruction from Point Clouds},
|
| 116 |
+
author={Zhang, Chen and Wang, Wentao and Li, Ximeng and Liao, Xinyao and Su, Wanjuan and Tao, Wenbing},
|
| 117 |
+
booktitle={CVPR},
|
| 118 |
+
pages={11739--11748},
|
| 119 |
+
year={2025}
|
| 120 |
+
}
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
---
|
| 124 |
|
| 125 |
+
License: MIT (reimplementation). Original paper and code Β© authors.
|