Yuliang commited on
Commit
12822cb
·
1 Parent(s): 1dfc359

change gsplat to diff

Browse files
Files changed (6) hide show
  1. .gitignore +3 -1
  2. app.py +1 -0
  3. command +0 -33
  4. gaussian_renderer/__init__.py +128 -130
  5. run_video.py +2 -2
  6. train_feat2gs.py +2 -2
.gitignore CHANGED
@@ -20,4 +20,6 @@ build/
20
  *.mp4
21
  .vs
22
  /exp/
23
- /dev/
 
 
 
20
  *.mp4
21
  .vs
22
  /exp/
23
+ /dev/
24
+ gradio_cached_examples/
25
+ gradio_cache_folder/
app.py CHANGED
@@ -12,6 +12,7 @@ import gradio as gr
12
  import uuid
13
  import spaces
14
 
 
15
  subprocess.run(shlex.split("pip install wheel/simple_knn-0.0.0-cp310-cp310-linux_x86_64.whl"))
16
  subprocess.run(shlex.split("pip install wheel/curope-0.0.0-cp310-cp310-linux_x86_64.whl"))
17
 
 
12
  import uuid
13
  import spaces
14
 
15
+ subprocess.run(shlex.split("pip install wheel/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl"))
16
  subprocess.run(shlex.split("pip install wheel/simple_knn-0.0.0-cp310-cp310-linux_x86_64.whl"))
17
  subprocess.run(shlex.split("pip install wheel/curope-0.0.0-cp310-cp310-linux_x86_64.whl"))
18
 
command DELETED
@@ -1,33 +0,0 @@
1
- conda activate feat2gs
2
- cd Feat2GS/
3
-
4
- bash scripts/run_feat2gs_eval_parallel.sh
5
- bash scripts/run_feat2gs_eval.sh
6
- bash scripts/run_instantsplat_eval_parallel.sh
7
- bash scripts/run_feat2gs_eval_dtu_parallel.sh
8
-
9
- python video/generate_video.py
10
-
11
- bash scripts/run_all_trajectories.sh
12
- bash scripts/run_video_render.sh
13
- bash scripts/run_video_render_instantsplat.sh
14
- bash scripts/run_video_render_dtu.sh
15
-
16
- tensorboard --logdir=/home/chenyue/output/Feat2gs/output/eval/ --port=7001
17
-
18
- cd /home/chenyue/output/Feat2gs/output/eval/Tanks/Train/6_views/feat2gs-G/dust3r/
19
- tensorboard --logdir_spec \
20
- radio:radio,\
21
- dust3r:dust3r,\
22
- dino_b16:dino_b16,\
23
- mast3r:mast3r,\
24
- dift:dift,\
25
- dinov2:dinov2_b14,\
26
- clip:clip_b16,\
27
- mae:mae_b16,\
28
- midas:midas_l16,\
29
- sam:sam_base,\
30
- iuvrgb:iuvrgb \
31
- --port 7002
32
-
33
- CUDA_VISIBLE_DEVICES=7 gradio demo.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
gaussian_renderer/__init__.py CHANGED
@@ -18,142 +18,140 @@ from utils.graphics_utils import depth_to_normal
18
 
19
  ### if use [diff-gaussian-rasterization](https://github.com/graphdeco-inria/diff-gaussian-rasterization)
20
 
21
- # from diff_gaussian_rasterization import (
22
- # GaussianRasterizationSettings,
23
- # GaussianRasterizer,
24
- # )
25
- # from utils.sh_utils import eval_sh
26
-
27
- # def render(
28
- # viewpoint_camera,
29
- # pc: GaussianModel,
30
- # pipe,
31
- # bg_color: torch.Tensor,
32
- # scaling_modifier=1.0,
33
- # override_color=None,
34
- # camera_pose=None,
35
- # ):
36
- # """
37
- # Render the scene.
38
-
39
- # Background tensor (bg_color) must be on GPU!
40
- # """
41
-
42
- # # Create zero tensor. We will use it to make pytorch return gradients of the 2D (screen-space) means
43
- # screenspace_points = (
44
- # torch.zeros_like(
45
- # pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda"
46
- # )
47
- # + 0
48
- # )
49
- # try:
50
- # screenspace_points.retain_grad()
51
- # except:
52
- # pass
53
-
54
- # # Set up rasterization configuration
55
- # tanfovx = math.tan(viewpoint_camera.FoVx * 0.5)
56
- # tanfovy = math.tan(viewpoint_camera.FoVy * 0.5)
57
-
58
- # # Set camera pose as identity. Then, we will transform the Gaussians around camera_pose
59
- # w2c = torch.eye(4).cuda()
60
- # projmatrix = (
61
- # w2c.unsqueeze(0).bmm(viewpoint_camera.projection_matrix.unsqueeze(0))
62
- # ).squeeze(0)
63
- # camera_pos = w2c.inverse()[3, :3]
64
- # raster_settings = GaussianRasterizationSettings(
65
- # image_height=int(viewpoint_camera.image_height),
66
- # image_width=int(viewpoint_camera.image_width),
67
- # tanfovx=tanfovx,
68
- # tanfovy=tanfovy,
69
- # bg=bg_color,
70
- # scale_modifier=scaling_modifier,
71
- # # viewmatrix=viewpoint_camera.world_view_transform,
72
- # # projmatrix=viewpoint_camera.full_proj_transform,
73
- # viewmatrix=w2c,
74
- # projmatrix=projmatrix,
75
- # sh_degree=pc.active_sh_degree,
76
- # # campos=viewpoint_camera.camera_center,
77
- # campos=camera_pos,
78
- # prefiltered=False,
79
- # debug=pipe.debug,
80
- # )
81
-
82
- # rasterizer = GaussianRasterizer(raster_settings=raster_settings)
83
-
84
- # # means3D = pc.get_xyz
85
- # rel_w2c = get_camera_from_tensor(camera_pose)
86
- # # Transform mean and rot of Gaussians to camera frame
87
- # gaussians_xyz = pc._xyz.clone()
88
- # gaussians_rot = pc._rotation.clone()
89
-
90
- # xyz_ones = torch.ones(gaussians_xyz.shape[0], 1).cuda().float()
91
- # xyz_homo = torch.cat((gaussians_xyz, xyz_ones), dim=1)
92
- # gaussians_xyz_trans = (rel_w2c @ xyz_homo.T).T[:, :3]
93
- # gaussians_rot_trans = quadmultiply(camera_pose[:4], gaussians_rot)
94
- # means3D = gaussians_xyz_trans
95
- # means2D = screenspace_points
96
- # opacity = pc.get_opacity
97
-
98
- # # If precomputed 3d covariance is provided, use it. If not, then it will be computed from
99
- # # scaling / rotation by the rasterizer.
100
- # scales = None
101
- # rotations = None
102
- # cov3D_precomp = None
103
- # if pipe.compute_cov3D_python:
104
- # cov3D_precomp = pc.get_covariance(scaling_modifier)
105
- # else:
106
- # scales = pc.get_scaling
107
- # rotations = gaussians_rot_trans # pc.get_rotation
108
-
109
- # # If precomputed colors are provided, use them. Otherwise, if it is desired to precompute colors
110
- # # from SHs in Python, do it. If not, then SH -> RGB conversion will be done by rasterizer.
111
- # shs = None
112
- # colors_precomp = None
113
- # if override_color is None:
114
- # if pipe.convert_SHs_python:
115
- # shs_view = pc.get_features.transpose(1, 2).view(
116
- # -1, 3, (pc.max_sh_degree + 1) ** 2
117
- # )
118
- # dir_pp = pc.get_xyz - viewpoint_camera.camera_center.repeat(
119
- # pc.get_features.shape[0], 1
120
- # )
121
- # dir_pp_normalized = dir_pp / dir_pp.norm(dim=1, keepdim=True)
122
- # sh2rgb = eval_sh(pc.active_sh_degree, shs_view, dir_pp_normalized)
123
- # colors_precomp = torch.clamp_min(sh2rgb + 0.5, 0.0)
124
- # else:
125
- # shs = pc.get_features
126
- # else:
127
- # colors_precomp = override_color
128
-
129
- # # Rasterize visible Gaussians to image, obtain their radii (on screen).
130
- # rendered_image, radii = rasterizer(
131
- # means3D=means3D,
132
- # means2D=means2D,
133
- # shs=shs,
134
- # colors_precomp=colors_precomp,
135
- # opacities=opacity,
136
- # scales=scales,
137
- # rotations=rotations,
138
- # cov3D_precomp=cov3D_precomp,
139
- # )
140
-
141
- # # Those Gaussians that were frustum culled or had a radius of 0 were not visible.
142
- # # They will be excluded from value updates used in the splitting criteria.
143
- # return {
144
- # "render": rendered_image,
145
- # "viewspace_points": screenspace_points,
146
- # "visibility_filter": radii > 0,
147
- # "radii": radii,
148
- # }
149
 
150
 
151
  ### if use [gsplat](https://github.com/nerfstudio-project/gsplat)
152
 
153
  from gsplat import rasterization
154
- import spaces
155
 
156
- @spaces.GPU(duration=150)
157
  def render_gsplat(
158
  viewpoint_camera,
159
  pc : GaussianModel,
 
18
 
19
  ### if use [diff-gaussian-rasterization](https://github.com/graphdeco-inria/diff-gaussian-rasterization)
20
 
21
+ from diff_gaussian_rasterization import (
22
+ GaussianRasterizationSettings,
23
+ GaussianRasterizer,
24
+ )
25
+ from utils.sh_utils import eval_sh
26
+
27
+ def render(
28
+ viewpoint_camera,
29
+ pc: GaussianModel,
30
+ pipe,
31
+ bg_color: torch.Tensor,
32
+ scaling_modifier=1.0,
33
+ override_color=None,
34
+ camera_pose=None,
35
+ ):
36
+ """
37
+ Render the scene.
38
+
39
+ Background tensor (bg_color) must be on GPU!
40
+ """
41
+
42
+ # Create zero tensor. We will use it to make pytorch return gradients of the 2D (screen-space) means
43
+ screenspace_points = (
44
+ torch.zeros_like(
45
+ pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda"
46
+ )
47
+ + 0
48
+ )
49
+ try:
50
+ screenspace_points.retain_grad()
51
+ except:
52
+ pass
53
+
54
+ # Set up rasterization configuration
55
+ tanfovx = math.tan(viewpoint_camera.FoVx * 0.5)
56
+ tanfovy = math.tan(viewpoint_camera.FoVy * 0.5)
57
+
58
+ # Set camera pose as identity. Then, we will transform the Gaussians around camera_pose
59
+ w2c = torch.eye(4).cuda()
60
+ projmatrix = (
61
+ w2c.unsqueeze(0).bmm(viewpoint_camera.projection_matrix.unsqueeze(0))
62
+ ).squeeze(0)
63
+ camera_pos = w2c.inverse()[3, :3]
64
+ raster_settings = GaussianRasterizationSettings(
65
+ image_height=int(viewpoint_camera.image_height),
66
+ image_width=int(viewpoint_camera.image_width),
67
+ tanfovx=tanfovx,
68
+ tanfovy=tanfovy,
69
+ bg=bg_color,
70
+ scale_modifier=scaling_modifier,
71
+ # viewmatrix=viewpoint_camera.world_view_transform,
72
+ # projmatrix=viewpoint_camera.full_proj_transform,
73
+ viewmatrix=w2c,
74
+ projmatrix=projmatrix,
75
+ sh_degree=pc.active_sh_degree,
76
+ # campos=viewpoint_camera.camera_center,
77
+ campos=camera_pos,
78
+ prefiltered=False,
79
+ debug=pipe.debug,
80
+ )
81
+
82
+ rasterizer = GaussianRasterizer(raster_settings=raster_settings)
83
+
84
+ # means3D = pc.get_xyz
85
+ rel_w2c = get_camera_from_tensor(camera_pose)
86
+ # Transform mean and rot of Gaussians to camera frame
87
+ gaussians_xyz = pc._xyz.clone()
88
+ gaussians_rot = pc._rotation.clone()
89
+
90
+ xyz_ones = torch.ones(gaussians_xyz.shape[0], 1).cuda().float()
91
+ xyz_homo = torch.cat((gaussians_xyz, xyz_ones), dim=1)
92
+ gaussians_xyz_trans = (rel_w2c @ xyz_homo.T).T[:, :3]
93
+ gaussians_rot_trans = quadmultiply(camera_pose[:4], gaussians_rot)
94
+ means3D = gaussians_xyz_trans
95
+ means2D = screenspace_points
96
+ opacity = pc.get_opacity
97
+
98
+ # If precomputed 3d covariance is provided, use it. If not, then it will be computed from
99
+ # scaling / rotation by the rasterizer.
100
+ scales = None
101
+ rotations = None
102
+ cov3D_precomp = None
103
+ if pipe.compute_cov3D_python:
104
+ cov3D_precomp = pc.get_covariance(scaling_modifier)
105
+ else:
106
+ scales = pc.get_scaling
107
+ rotations = gaussians_rot_trans # pc.get_rotation
108
+
109
+ # If precomputed colors are provided, use them. Otherwise, if it is desired to precompute colors
110
+ # from SHs in Python, do it. If not, then SH -> RGB conversion will be done by rasterizer.
111
+ shs = None
112
+ colors_precomp = None
113
+ if override_color is None:
114
+ if pipe.convert_SHs_python:
115
+ shs_view = pc.get_features.transpose(1, 2).view(
116
+ -1, 3, (pc.max_sh_degree + 1) ** 2
117
+ )
118
+ dir_pp = pc.get_xyz - viewpoint_camera.camera_center.repeat(
119
+ pc.get_features.shape[0], 1
120
+ )
121
+ dir_pp_normalized = dir_pp / dir_pp.norm(dim=1, keepdim=True)
122
+ sh2rgb = eval_sh(pc.active_sh_degree, shs_view, dir_pp_normalized)
123
+ colors_precomp = torch.clamp_min(sh2rgb + 0.5, 0.0)
124
+ else:
125
+ shs = pc.get_features
126
+ else:
127
+ colors_precomp = override_color
128
+
129
+ # Rasterize visible Gaussians to image, obtain their radii (on screen).
130
+ rendered_image, radii = rasterizer(
131
+ means3D=means3D,
132
+ means2D=means2D,
133
+ shs=shs,
134
+ colors_precomp=colors_precomp,
135
+ opacities=opacity,
136
+ scales=scales,
137
+ rotations=rotations,
138
+ cov3D_precomp=cov3D_precomp,
139
+ )
140
+
141
+ # Those Gaussians that were frustum culled or had a radius of 0 were not visible.
142
+ # They will be excluded from value updates used in the splitting criteria.
143
+ return {
144
+ "render": rendered_image,
145
+ "viewspace_points": screenspace_points,
146
+ "visibility_filter": radii > 0,
147
+ "radii": radii,
148
+ }
149
 
150
 
151
  ### if use [gsplat](https://github.com/nerfstudio-project/gsplat)
152
 
153
  from gsplat import rasterization
 
154
 
 
155
  def render_gsplat(
156
  viewpoint_camera,
157
  pc : GaussianModel,
run_video.py CHANGED
@@ -18,7 +18,7 @@ import torch
18
  from scene import Scene
19
  import os
20
  from tqdm import tqdm
21
- from gaussian_renderer import render_gsplat
22
  from argparse import ArgumentParser
23
  from arguments import ModelParams, PipelineParams, get_combined_args
24
  from gaussian_renderer import GaussianModel
@@ -201,7 +201,7 @@ def render_sets(dataset: ModelParams, iteration: int, pipeline: PipelineParams,
201
  if args.resize:
202
  view = resize_render(view)
203
 
204
- rendering = render_gsplat(
205
  view, gaussians, pipeline, background, camera_pose=camera_pose
206
  )["render"]
207
 
 
18
  from scene import Scene
19
  import os
20
  from tqdm import tqdm
21
+ from gaussian_renderer import render, render_gsplat
22
  from argparse import ArgumentParser
23
  from arguments import ModelParams, PipelineParams, get_combined_args
24
  from gaussian_renderer import GaussianModel
 
201
  if args.resize:
202
  view = resize_render(view)
203
 
204
+ rendering = render(
205
  view, gaussians, pipeline, background, camera_pose=camera_pose
206
  )["render"]
207
 
train_feat2gs.py CHANGED
@@ -14,7 +14,7 @@ import numpy as np
14
  import torch
15
  from random import randint
16
  from utils.loss_utils import l1_loss, ssim
17
- from gaussian_renderer import render_gsplat
18
  import sys
19
  from scene import Scene, Feat2GaussianModel
20
  from argparse import ArgumentParser
@@ -133,7 +133,7 @@ def training(dataset, opt, pipe, testing_iterations, saving_iterations, checkpoi
133
  Ll1 = torch.tensor(0)
134
 
135
  if iteration > warm_iter:
136
- render_pkg = render_gsplat(viewpoint_cam, gaussians, pipe, bg, camera_pose=pose)
137
  image, viewspace_point_tensor, visibility_filter, radii = render_pkg["render"], render_pkg["viewspace_points"], render_pkg["visibility_filter"], render_pkg["radii"]
138
 
139
  # Loss
 
14
  import torch
15
  from random import randint
16
  from utils.loss_utils import l1_loss, ssim
17
+ from gaussian_renderer import render, render_gsplat
18
  import sys
19
  from scene import Scene, Feat2GaussianModel
20
  from argparse import ArgumentParser
 
133
  Ll1 = torch.tensor(0)
134
 
135
  if iteration > warm_iter:
136
+ render_pkg = render(viewpoint_cam, gaussians, pipe, bg, camera_pose=pose)
137
  image, viewspace_point_tensor, visibility_filter, radii = render_pkg["render"], render_pkg["viewspace_points"], render_pkg["visibility_filter"], render_pkg["radii"]
138
 
139
  # Loss