MCPcopy Create free account
hub / github.com/OpenImagingLab/4DSloMo / create_from_pcd

Method create_from_pcd

scene/gaussian_model.py:254–295  ·  view source on GitHub ↗
(self, pcd : BasicPointCloud, spatial_lr_scale : float)

Source from the content-addressed store, hash-verified

252 self.active_sh_degree_t += 1
253
254 def create_from_pcd(self, pcd : BasicPointCloud, spatial_lr_scale : float):
255 self.spatial_lr_scale = spatial_lr_scale
256 fused_point_cloud = torch.tensor(np.asarray(pcd.points)).float().cuda()
257 fused_color = RGB2SH(torch.tensor(np.asarray(pcd.colors)).float().cuda())
258 features = torch.zeros((fused_color.shape[0], 3, self.get_max_sh_channels)).float().cuda()
259 features[:, :3, 0 ] = fused_color
260 features[:, 3:, 1:] = 0.0
261 if self.gaussian_dim == 4:
262 if pcd.time is None:
263 fused_times = (torch.rand(fused_point_cloud.shape[0], 1, device="cuda") * 1.2 - 0.1) * (self.time_duration[1] - self.time_duration[0]) + self.time_duration[0]
264 else:
265 fused_times = torch.from_numpy(pcd.time).cuda().float()
266
267 print("Number of points at initialisation : ", fused_point_cloud.shape[0])
268
269 dist2 = torch.clamp_min(distCUDA2(torch.from_numpy(np.asarray(pcd.points)).float().cuda()), 0.0000001)
270 scales = torch.log(torch.sqrt(dist2))[...,None].repeat(1, 3)
271 rots = torch.zeros((fused_point_cloud.shape[0], 4), device="cuda")
272 rots[:, 0] = 1
273 if self.gaussian_dim == 4:
274 # dist_t = torch.clamp_min(distCUDA2(fused_times.repeat(1,3)), 1e-10)[...,None]
275 dist_t = torch.zeros_like(fused_times, device="cuda") + (self.time_duration[1] - self.time_duration[0]) / 5
276 scales_t = torch.log(torch.sqrt(dist_t))
277 if self.rot_4d:
278 rots_r = torch.zeros((fused_point_cloud.shape[0], 4), device="cuda")
279 rots_r[:, 0] = 1
280
281 opacities = inverse_sigmoid(0.1 * torch.ones((fused_point_cloud.shape[0], 1), dtype=torch.float, device="cuda"))
282
283 self._xyz = nn.Parameter(fused_point_cloud.requires_grad_(True))
284 self._features_dc = nn.Parameter(features[:,:,0:1].transpose(1, 2).contiguous().requires_grad_(True))
285 self._features_rest = nn.Parameter(features[:,:,1:].transpose(1, 2).contiguous().requires_grad_(True))
286 self._scaling = nn.Parameter(scales.requires_grad_(True))
287 self._rotation = nn.Parameter(rots.requires_grad_(True))
288 self._opacity = nn.Parameter(opacities.requires_grad_(True))
289 self.max_radii2D = torch.zeros((self.get_xyz.shape[0]), device="cuda")
290
291 if self.gaussian_dim == 4:
292 self._t = nn.Parameter(fused_times.requires_grad_(True))
293 self._scaling_t = nn.Parameter(scales_t.requires_grad_(True))
294 if self.rot_4d:
295 self._rotation_r = nn.Parameter(rots_r.requires_grad_(True))
296
297 def create_from_pth(self, path, spatial_lr_scale):
298 assert self.gaussian_dim == 4 and self.rot_4d

Callers 1

__init__Method · 0.80

Calls 3

RGB2SHFunction · 0.90
inverse_sigmoidFunction · 0.90
cudaMethod · 0.80

Tested by

no test coverage detected