Elffuss BraidHub

kikocis/SpatialLM public

Add example doc using a custom video
Changeset059ffe68fc98c038e7e2ddb6f7f535278114791239fb9d5df32275cd682f9095
AuthorYongsen Mao <sammaoys@gmail.com> · 2025-03-27 10:30 +08:00
CommitterYongsen Mao <sammaoys@gmail.com> · 2025-03-27 10:30 +08:00
Parents321865be151e

Browse the files at this changeset

6 files changed

added EXAMPLE.md +69 −0
@@ -0,0 +1,69 @@
1+# Example using a custom video
2+
3+A new open-source SLAM system [SLAM3R](https://github.com/PKU-VCL-3DV/SLAM3R) just released. We found it is great for reconstructing point clouds from RGB inputs as well. Here we provide an example of how to use it to reconstruct a point cloud from a video, and use our model to estimate the layout of the scene.
4+
5+## 1. Reconstruct a point cloud with SLAM3R
6+
7+Please refer to the [SLAM3R Replica Example](https://github.com/PKU-VCL-3DV/SLAM3R?tab=readme-ov-file#replica-dataset) for the details of how to run SLAM3R on the provided Replica example.
8+
9+You can set `sample_freq` in this [line](https://github.com/PKU-VCL-3DV/SLAM3R/blob/3831478e15b83509f3f317abc1d4f7bd3cc21e2d/scripts/demo_replica.sh#L8) to 2 to decrease the GPU memory usage and speed up the reconstruction. And you can also try increase the `CONF_THRES_L2W` threshold [here](https://github.com/PKU-VCL-3DV/SLAM3R/blob/3831478e15b83509f3f317abc1d4f7bd3cc21e2d/scripts/demo_replica.sh#L22) to get cleaner point cloud.
10+
11+## 2. Align the output point cloud
12+
13+In the current version of SpatialLM, input point clouds are considered axis-aligned where the z-axis is the up axis. The input point clouds should follow the ScanNet scenes orientation convension, which is "_Transforms scans to z-up alignment for scans and tries to align walls to x-y planes._" in [Alignment](https://github.com/ScanNet/ScanNet/tree/master/Alignment). Refer to [Issue #7](https://github.com/manycore-research/SpatialLM/issues/7) for more details.
14+
15+For now, you can choose your way to align the point cloud. We recommend you to check out [VanishingPoint Estimation](https://github.com/yanconglin/VanishingPoint_HoughTransform_GaussianSphere), [Manhattan Frame Estimation from video](https://github.com/jstraub/rtmf), Manhattan Frame Estimation from surface normals (ref paper: Globally Optimal Manhattan Frame Estimation in Real-time, Manhattan World Inference in the Space of Surface Normals) for estimating the Manhattan Frame from image, video or point cloud. And more recent methods such as [U-ARE-ME](https://github.com/callum-rhodes/U-ARE-ME), [Perspective Fields for Single Image Camera Calibration](https://github.com/jinlinyi/PerspectiveFields). Or even use tools like Blender to manually align the point cloud.
16+
17+| Before Alignment | After Alignment |
18+|:---------------:|:---------------:|
19+| ![Point cloud before alignment](./figures/unaligned.jpg) | ![Point cloud after alignment](./figures/aligned.jpg) |
20+
21+## 3. Ensure the scale of the point cloud
22+
23+Our model is trained on point clouds with a metric accurate scale. The value 1 refer to 1 meter in the real world. Although we did some scale augmentation during training, but the size may vary from different SLAM systems.
24+
25+For indoor scenes, you can have a rough estimation of the scale of the scene by the height of the walls. For example, you can resize the aligned point cloud to have a height of 2.5 meters in this example.
26+
27+```python
28+import open3d as o3d
29+from spatiallm.pcd import load_o3d_pcd, get_points_and_colors
30+
31+point_cloud = load_o3d_pcd(point_cloud_file)
32+points, colors = get_points_and_colors(point_cloud)
33+min_z = np.min(points[:, 2])
34+max_z = np.max(points[:, 2])
35+height = max_z - min_z
36+estimated_height = 2.5
37+scale = estimated_height / height
38+points = points * scale
39+
40+# export the point cloud
41+point_cloud = o3d.geometry.PointCloud()
42+point_cloud.points = o3d.utility.Vector3dVector(points)
43+point_cloud.colors = o3d.utility.Vector3dVector(colors.astype(np.float32)/ 255.0)
44+o3d.io.write_point_cloud(f"scaled_point_cloud.ply", point_cloud)
45+```
46+
47+## 4. Run the inference
48+
49+Now we can run the layout estimation with the aligned and scaled point cloud.
50+
51+```bash
52+python inference.py --point_cloud scaled_point_cloud.ply --output replica_layout.txt --model_path manycore-research/SpatialLM-Llama-1B
53+# visualize the layout
54+python visualize.py --point_cloud scaled_point_cloud.ply --layout replica_layout.txt --save replica_layout.rrd
55+rerun replica_layout.rrd
56+```
57+
58+| View 1 | View 2 |
59+|:---------------:|:---------------:|
60+| ![Result view 1](./figures/replica_example1.jpg) | ![Result view 2](./figures/replica_example2.jpg) |
61+
62+## 5. Summary
63+
64+In this example, we demonstrated how to estimate scene layout from a custom video. The workflow involves four main steps: reconstructing a point cloud from video, aligning it to match the ScanNet orientation convention, scale the point cloud to a roughly metric accurate scale, and finally running our layout estimation model. We will keep improving to make these steps more automated, efficient and robust.
65+
66+Note that in this example, one sofa is not detected in the prediction. This is because our training data primarily consists of Chinese residential apartments where living rooms typically feature a single main sofa facing a TV, which is on the other side of the room. The model currently has its limitation on generalize very well to more diverse scenarios, such as non-standard layouts, cluttered spaces, or outdoor environments. We are actively working on it, and will try to improve the model's performance to more diverse scenes in the next release.
67+
68+
69+
modified README.md +4 −0
@@ -117,6 +117,10 @@
117117 python eval.py --metadata SpatialLM-Testset/test.csv --gt_dir SpatialLM-Testset/layout --pred_dir SpatialLM-Testset/pred --label_mapping SpatialLM-Testset/benchmark_categories.tsv
118118 ```
119119
120+### Example using a custom video
121+
122+We provide an example of how to use our model to estimate scene layout starting from a RGB video with the newly released [SLAM3R](https://github.com/PKU-VCL-3DV/SLAM3R) in [EXAMPLE.md](EXAMPLE.md).
123+
120124 ## SpatialLM Testset
121125
122126 We provide a test set of 107 preprocessed point clouds, reconstructed from RGB videos using [MASt3R-SLAM](https://github.com/rmurai0610/MASt3R-SLAM). SpatialLM-Testset is quite challenging compared to prior clean RGBD scans datasets due to the noises and occlusions in the point clouds reconstructed from monocular RGB videos.
added figures/aligned.jpg +0 −0

Binary content is not shown. View the file.

added figures/replica_example1.jpg +0 −0

Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.

added figures/replica_example2.jpg +0 −0

Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.

added figures/unaligned.jpg +0 −0

Binary content is not shown. View the file.