Skip to content

Commit 589cc74

Browse files
committed
[yfl] add 3dgs rendering backend
1 parent fe4f58b commit 589cc74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+5039
-6
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ pip install -r requirements.txt
2929
imageio_download_bin freeimage
3030
```
3131

32+
### Step 2: Faster alternative of McNeRF, 3D Gaussians splatting
33+
This requires the your CUDA NVCC version matches your pytorch cuda version.
34+
```bash
35+
cd chatsim/background/gaussian-splatting/
36+
pip install submodules/simple-knn
37+
```
38+
3239
### Step 2: Install McNeRF
3340
The installation is the same as [F2-NeRF](https://github.com/totoro97/f2-nerf). Please go through the following steps.
3441

@@ -260,7 +267,7 @@ data
260267
|-- shutters # normalized exposure time (mean=0 std=1)
261268
|-- tracking_info.pkl # tracking data
262269
|-- vehi2veh0.npy # transformation matrix from i-th frame's vehicle coordinate to the first frame's vehicle
263-
|-- sparse/0 # calibration files from COLMAP (intermediate file, not required by simulation inference)
270+
|-- colmap/sparse_undistorted # calibration files from COLMAP (intermediate file, only required when using 3dgs rendering)
264271
`-- camera.xml # calibration file from Metashape (intermediate file, not required by simulation inference)
265272
coordinate.
266273
```
@@ -275,7 +282,7 @@ data
275282
**`cams_meta.npy` instruction**
276283
```
277284
cams_meta.shape = (N, 27)
278-
cams_meta[:, 0 :12]: flatten camera poses in RUB
285+
cams_meta[:, 0 :12]: flatten camera poses in RUB, world coordinate is the starting frame's vehicle coordinate.
279286
cams_meta[:, 12:21]: flatten camse intrinsics
280287
cams_meta[:, 21:25]: distortion params [k1, k2, p1, p2]
281288
cams_meta[:, 25:27]: bounds [z_near, z_far] (not used.)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
This is a 3dgs version of our background rendering, which offers real-time performance
3+
"""
4+
import numpy as np
5+
from termcolor import colored
6+
import imageio.v2 as imageio
7+
import os
8+
9+
class BackgroundRendering3DGSAgent:
10+
def __init__(self, config):
11+
self.config = config
12+
13+
self.is_wide_angle = config["nerf_config"]['is_wide_angle']
14+
15+
self.gs_dir = config["gs_config"]['gs_dir']
16+
self.model_folder = os.path.join(config["gs_config"]['gs_dir'],
17+
config["gs_config"]["output_folder"],
18+
config["gs_config"]["gs_model_name"])
19+
self.gs_novel_view_dir = os.path.join(self.model_folder, "chatsim_novel_views")
20+
21+
def func_render_background(self, scene):
22+
"""
23+
Call the NeRF, store results in scene.current_images
24+
"""
25+
# first update scene.is_ego_motion
26+
scene.is_ego_motion = not np.all(scene.current_extrinsics == scene.current_extrinsics[0])
27+
28+
if scene.is_ego_motion:
29+
print(f"{colored('[Background Gaussian Splatting]', 'red', attrs=['bold'])} is_ego_motion is True, rendering multiple frames")
30+
31+
camera_extrinsics = scene.current_extrinsics[:, :3, :] # [N_frames, 3, 4]
32+
camera_intrinsics = scene.intrinsics # [3, 3]
33+
else:
34+
print(f"{colored('[Background Gaussian Splatting]', 'red', attrs=['bold'])} is_ego_motion is False, rendering one frame")
35+
camera_extrinsics = scene.current_extrinsics[0:1, :3, :] # [1, 3, 4]
36+
camera_intrinsics = scene.intrinsics # [3, 3]
37+
38+
np.savez(os.path.join(self.model_folder, 'chatsim_extint.npz'),
39+
camera_extrinsics = camera_extrinsics,
40+
camera_intrinsics = camera_intrinsics,
41+
H = scene.height,
42+
W = scene.width
43+
)
44+
45+
# remove previous rendered images
46+
if os.path.exists(self.gs_novel_view_dir) and len(os.listdir(self.gs_novel_view_dir)) > 0:
47+
os.system(f"rm -r {self.gs_novel_view_dir}/*")
48+
49+
current_dir = os.getcwd()
50+
os.chdir(self.gs_dir) # do not generate intermediate file at root directory
51+
render_command = f'python render_chatsim.py \
52+
--model_path {self.model_folder}'
53+
54+
os.system(render_command)
55+
os.chdir(current_dir)
56+
57+
scene.current_images = [] # to be updated
58+
img_path_list = os.listdir(self.gs_novel_view_dir)
59+
img_path_list.sort(key=lambda x:int(x[:-4]))
60+
61+
for img_path in img_path_list:
62+
scene.current_images.append(imageio.imread(os.path.join(self.gs_novel_view_dir, img_path))[:, :scene.width])
63+
64+
if not scene.is_ego_motion:
65+
scene.current_images = scene.current_images * scene.frames
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.pyc
2+
.vscode
3+
output
4+
build
5+
diff_rasterization/diff_rast.egg-info
6+
diff_rasterization/dist
7+
tensorboard_3d
8+
screenshots
9+
data
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
Gaussian-Splatting License
2+
===========================
3+
4+
**Inria** and **the Max Planck Institut for Informatik (MPII)** hold all the ownership rights on the *Software* named **gaussian-splatting**.
5+
The *Software* is in the process of being registered with the Agence pour la Protection des
6+
Programmes (APP).
7+
8+
The *Software* is still being developed by the *Licensor*.
9+
10+
*Licensor*'s goal is to allow the research community to use, test and evaluate
11+
the *Software*.
12+
13+
## 1. Definitions
14+
15+
*Licensee* means any person or entity that uses the *Software* and distributes
16+
its *Work*.
17+
18+
*Licensor* means the owners of the *Software*, i.e Inria and MPII
19+
20+
*Software* means the original work of authorship made available under this
21+
License ie gaussian-splatting.
22+
23+
*Work* means the *Software* and any additions to or derivative works of the
24+
*Software* that are made available under this License.
25+
26+
27+
## 2. Purpose
28+
This license is intended to define the rights granted to the *Licensee* by
29+
Licensors under the *Software*.
30+
31+
## 3. Rights granted
32+
33+
For the above reasons Licensors have decided to distribute the *Software*.
34+
Licensors grant non-exclusive rights to use the *Software* for research purposes
35+
to research users (both academic and industrial), free of charge, without right
36+
to sublicense.. The *Software* may be used "non-commercially", i.e., for research
37+
and/or evaluation purposes only.
38+
39+
Subject to the terms and conditions of this License, you are granted a
40+
non-exclusive, royalty-free, license to reproduce, prepare derivative works of,
41+
publicly display, publicly perform and distribute its *Work* and any resulting
42+
derivative works in any form.
43+
44+
## 4. Limitations
45+
46+
**4.1 Redistribution.** You may reproduce or distribute the *Work* only if (a) you do
47+
so under this License, (b) you include a complete copy of this License with
48+
your distribution, and (c) you retain without modification any copyright,
49+
patent, trademark, or attribution notices that are present in the *Work*.
50+
51+
**4.2 Derivative Works.** You may specify that additional or different terms apply
52+
to the use, reproduction, and distribution of your derivative works of the *Work*
53+
("Your Terms") only if (a) Your Terms provide that the use limitation in
54+
Section 2 applies to your derivative works, and (b) you identify the specific
55+
derivative works that are subject to Your Terms. Notwithstanding Your Terms,
56+
this License (including the redistribution requirements in Section 3.1) will
57+
continue to apply to the *Work* itself.
58+
59+
**4.3** Any other use without of prior consent of Licensors is prohibited. Research
60+
users explicitly acknowledge having received from Licensors all information
61+
allowing to appreciate the adequacy between of the *Software* and their needs and
62+
to undertake all necessary precautions for its execution and use.
63+
64+
**4.4** The *Software* is provided both as a compiled library file and as source
65+
code. In case of using the *Software* for a publication or other results obtained
66+
through the use of the *Software*, users are strongly encouraged to cite the
67+
corresponding publications as explained in the documentation of the *Software*.
68+
69+
## 5. Disclaimer
70+
71+
THE USER CANNOT USE, EXPLOIT OR DISTRIBUTE THE *SOFTWARE* FOR COMMERCIAL PURPOSES
72+
WITHOUT PRIOR AND EXPLICIT CONSENT OF LICENSORS. YOU MUST CONTACT INRIA FOR ANY
73+
UNAUTHORIZED USE: [email protected] . ANY SUCH ACTION WILL
74+
CONSTITUTE A FORGERY. THIS *SOFTWARE* IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES
75+
OF ANY NATURE AND ANY EXPRESS OR IMPLIED WARRANTIES, WITH REGARDS TO COMMERCIAL
76+
USE, PROFESSIONNAL USE, LEGAL OR NOT, OR OTHER, OR COMMERCIALISATION OR
77+
ADAPTATION. UNLESS EXPLICITLY PROVIDED BY LAW, IN NO EVENT, SHALL INRIA OR THE
78+
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
79+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
80+
GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION)
81+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
82+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING FROM, OUT OF OR
83+
IN CONNECTION WITH THE *SOFTWARE* OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE*.
84+
85+
## 6. Files subject to permissive licenses
86+
The contents of the file ```utils/loss_utils.py``` are based on publicly available code authored by Evan Su, which falls under the permissive MIT license.
87+
88+
Title: pytorch-ssim\
89+
Project code: https://github.com/Po-Hsun-Su/pytorch-ssim\
90+
Copyright Evan Su, 2017\
91+
License: https://github.com/Po-Hsun-Su/pytorch-ssim/blob/master/LICENSE.txt (MIT)

0 commit comments

Comments
 (0)