ostapagon commited on
Commit
bf3db5b
·
1 Parent(s): 8f71ae1

Try this wheels

Browse files
Files changed (2) hide show
  1. demo/gs_train.py +112 -3
  2. requirements.txt +1 -1
demo/gs_train.py CHANGED
@@ -12,6 +12,7 @@ from demo_globals import DEVICE
12
  import spaces
13
  from simple_knn._C import distCUDA2
14
 
 
15
  @dataclass
16
  class PipelineParams:
17
  convert_SHs_python: bool = False
@@ -78,7 +79,7 @@ def train(
78
 
79
  # Import necessary modules from the gaussian-splatting directory
80
  from utils.loss_utils import l1_loss, ssim
81
- from gaussian_renderer import render
82
  from scene import Scene, GaussianModel
83
  from utils.general_utils import safe_state
84
  from utils.image_utils import psnr
@@ -132,6 +133,114 @@ def train(
132
  random_background=random_background
133
  )
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  args = TrainingArgs()
136
 
137
  testing_iterations = args.test_iterations
@@ -280,8 +389,8 @@ def train(
280
  view.projection_matrix = getProjectionMatrix(znear=view.znear, zfar=view.zfar, fovX=view.FoVx, fovY=view.FoVy).transpose(0,1).cuda().float()
281
  view.full_proj_transform = (view.world_view_transform.unsqueeze(0).bmm(view.projection_matrix.unsqueeze(0))).squeeze(0)
282
 
283
- print("background.device: ", background.device)
284
- print("view.device: ", view.original_image.device)
285
  render_pkg = render(view, gaussians, pipeline, background)
286
  rendering = render_pkg["render"]
287
  torchvision.utils.save_image(rendering, os.path.join(render_path, '{0:05d}'.format(idx) + ".png"))
 
12
  import spaces
13
  from simple_knn._C import distCUDA2
14
 
15
+
16
  @dataclass
17
  class PipelineParams:
18
  convert_SHs_python: bool = False
 
79
 
80
  # Import necessary modules from the gaussian-splatting directory
81
  from utils.loss_utils import l1_loss, ssim
82
+ # from gaussian_renderer import render
83
  from scene import Scene, GaussianModel
84
  from utils.general_utils import safe_state
85
  from utils.image_utils import psnr
 
133
  random_background=random_background
134
  )
135
 
136
+
137
+ #
138
+ # Copyright (C) 2023, Inria
139
+ # GRAPHDECO research group, https://team.inria.fr/graphdeco
140
+ # All rights reserved.
141
+ #
142
+ # This software is free for non-commercial, research and evaluation use
143
+ # under the terms of the LICENSE.md file.
144
+ #
145
+ # For inquiries contact [email protected]
146
+ #
147
+ print("local_renderer")
148
+ import torch
149
+ import math
150
+ from diff_gaussian_rasterization import GaussianRasterizationSettings, GaussianRasterizer
151
+ from scene.gaussian_model import GaussianModel
152
+ from utils.sh_utils import eval_sh
153
+
154
+ def render(viewpoint_camera, pc : GaussianModel, pipe, bg_color : torch.Tensor, scaling_modifier = 1.0, override_color = None):
155
+ """
156
+ Render the scene.
157
+
158
+ Background tensor (bg_color) must be on GPU!
159
+ """
160
+
161
+ # Create zero tensor. We will use it to make pytorch return gradients of the 2D (screen-space) means
162
+ screenspace_points = torch.zeros_like(pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda") + 0
163
+ try:
164
+ screenspace_points.retain_grad()
165
+ except:
166
+ pass
167
+
168
+ # Set up rasterization configuration
169
+ tanfovx = math.tan(viewpoint_camera.FoVx * 0.5)
170
+ tanfovy = math.tan(viewpoint_camera.FoVy * 0.5)
171
+
172
+ kernel_size = 0.1
173
+ subpixel_offset = torch.zeros((int(viewpoint_camera.image_height), int(viewpoint_camera.image_width), 2), dtype=torch.float32, device="cuda")
174
+
175
+ raster_settings = GaussianRasterizationSettings(
176
+ image_height=int(viewpoint_camera.image_height),
177
+ image_width=int(viewpoint_camera.image_width),
178
+ tanfovx=tanfovx,
179
+ tanfovy=tanfovy,
180
+ kernel_size=kernel_size,
181
+ subpixel_offset=subpixel_offset,
182
+ bg=bg_color,
183
+ scale_modifier=scaling_modifier,
184
+ viewmatrix=viewpoint_camera.world_view_transform,
185
+ projmatrix=viewpoint_camera.full_proj_transform,
186
+ sh_degree=pc.active_sh_degree,
187
+ campos=viewpoint_camera.camera_center,
188
+ prefiltered=False,
189
+ debug=pipe.debug
190
+ )
191
+
192
+ rasterizer = GaussianRasterizer(raster_settings=raster_settings)
193
+
194
+ means3D = pc.get_xyz
195
+ means2D = screenspace_points
196
+ opacity = pc.get_opacity
197
+
198
+ # If precomputed 3d covariance is provided, use it. If not, then it will be computed from
199
+ # scaling / rotation by the rasterizer.
200
+ scales = None
201
+ rotations = None
202
+ cov3D_precomp = None
203
+ if pipe.compute_cov3D_python:
204
+ cov3D_precomp = pc.get_covariance(scaling_modifier)
205
+ else:
206
+ scales = pc.get_scaling
207
+ rotations = pc.get_rotation
208
+
209
+ # If precomputed colors are provided, use them. Otherwise, if it is desired to precompute colors
210
+ # from SHs in Python, do it. If not, then SH -> RGB conversion will be done by rasterizer.
211
+ shs = None
212
+ colors_precomp = None
213
+ if override_color is None:
214
+ if pipe.convert_SHs_python:
215
+ shs_view = pc.get_features.transpose(1, 2).view(-1, 3, (pc.max_sh_degree+1)**2)
216
+ dir_pp = (pc.get_xyz - viewpoint_camera.camera_center.repeat(pc.get_features.shape[0], 1))
217
+ dir_pp_normalized = dir_pp/dir_pp.norm(dim=1, keepdim=True)
218
+ sh2rgb = eval_sh(pc.active_sh_degree, shs_view, dir_pp_normalized)
219
+ colors_precomp = torch.clamp_min(sh2rgb + 0.5, 0.0)
220
+ else:
221
+ shs = pc.get_features
222
+ else:
223
+ colors_precomp = override_color
224
+
225
+ # Rasterize visible Gaussians to image, obtain their radii (on screen).
226
+ rendered_image, radii = rasterizer(
227
+ means3D = means3D,
228
+ means2D = means2D,
229
+ shs = shs,
230
+ colors_precomp = colors_precomp,
231
+ opacities = opacity,
232
+ scales = scales,
233
+ rotations = rotations,
234
+ cov3D_precomp = cov3D_precomp)
235
+
236
+ # Those Gaussians that were frustum culled or had a radius of 0 were not visible.
237
+ # They will be excluded from value updates used in the splitting criteria.
238
+ return {"render": rendered_image,
239
+ "viewspace_points": screenspace_points,
240
+ "visibility_filter" : radii > 0,
241
+ "radii": radii}
242
+
243
+
244
  args = TrainingArgs()
245
 
246
  testing_iterations = args.test_iterations
 
389
  view.projection_matrix = getProjectionMatrix(znear=view.znear, zfar=view.zfar, fovX=view.FoVx, fovY=view.FoVy).transpose(0,1).cuda().float()
390
  view.full_proj_transform = (view.world_view_transform.unsqueeze(0).bmm(view.projection_matrix.unsqueeze(0))).squeeze(0)
391
 
392
+ # print("background.device: ", background.device)
393
+ # print("view.device: ", view.original_image.device)
394
  render_pkg = render(view, gaussians, pipeline, background)
395
  rendering = render_pkg["render"]
396
  torchvision.utils.save_image(rendering, os.path.join(render_path, '{0:05d}'.format(idx) + ".png"))
requirements.txt CHANGED
@@ -33,4 +33,4 @@ ipywidgets
33
  jupyterlab
34
  sql
35
 
36
- https://huggingface.co/spaces/ostapagon/mast3r-3dgs/resolve/main/wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl?download=true
 
33
  jupyterlab
34
  sql
35
 
36
+ https://huggingface.co/spaces/JeffreyXiang/TRELLIS/resolve/main/wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl?download=true