Spaces:
Running
on
Zero
Running
on
Zero
set sh degree as 0
Browse files- arguments/__init__.py +2 -2
- scene/gaussian_model.py +16 -16
arguments/__init__.py
CHANGED
@@ -46,7 +46,7 @@ class ParamGroup:
|
|
46 |
|
47 |
class ModelParams(ParamGroup):
|
48 |
def __init__(self, parser, sentinel=False):
|
49 |
-
self.sh_degree =
|
50 |
self._source_path = ""
|
51 |
self._model_path = ""
|
52 |
self._images = "images"
|
@@ -91,7 +91,7 @@ class ModelParams(ParamGroup):
|
|
91 |
},
|
92 |
'Gft':{
|
93 |
'head': ['xyz', 'scaling', 'rotation', 'opacity'],
|
94 |
-
'opt':['f_dc', '
|
95 |
},
|
96 |
'Tft':{
|
97 |
'head': ['f_dc', 'f_rest'],
|
|
|
46 |
|
47 |
class ModelParams(ParamGroup):
|
48 |
def __init__(self, parser, sentinel=False):
|
49 |
+
self.sh_degree = 0
|
50 |
self._source_path = ""
|
51 |
self._model_path = ""
|
52 |
self._images = "images"
|
|
|
91 |
},
|
92 |
'Gft':{
|
93 |
'head': ['xyz', 'scaling', 'rotation', 'opacity'],
|
94 |
+
'opt':['f_dc', 'pc_feat'] #, 'f_rest' delete for vis
|
95 |
},
|
96 |
'Tft':{
|
97 |
'head': ['f_dc', 'f_rest'],
|
scene/gaussian_model.py
CHANGED
@@ -187,8 +187,8 @@ class GaussianModel:
|
|
187 |
@property
|
188 |
def get_features(self):
|
189 |
features_dc = self._features_dc
|
190 |
-
features_rest = self._features_rest
|
191 |
-
return
|
192 |
|
193 |
@property
|
194 |
def get_opacity(self):
|
@@ -285,8 +285,8 @@ class GaussianModel:
|
|
285 |
# All channels except the 3 DC
|
286 |
for i in range(self._features_dc.shape[1]*self._features_dc.shape[2]):
|
287 |
l.append('f_dc_{}'.format(i))
|
288 |
-
for i in range(self._features_rest.shape[1]*self._features_rest.shape[2]):
|
289 |
-
|
290 |
l.append('opacity')
|
291 |
for i in range(self._scaling.shape[1]):
|
292 |
l.append('scale_{}'.format(i))
|
@@ -300,7 +300,7 @@ class GaussianModel:
|
|
300 |
xyz = self._xyz.detach().cpu().numpy()
|
301 |
normals = np.zeros_like(xyz)
|
302 |
f_dc = self._features_dc.detach().transpose(1, 2).flatten(start_dim=1).contiguous().cpu().numpy()
|
303 |
-
f_rest = self._features_rest.detach().transpose(1, 2).flatten(start_dim=1).contiguous().cpu().numpy()
|
304 |
opacities = self._opacity.detach().cpu().numpy()
|
305 |
scale = self._scaling.detach().cpu().numpy()
|
306 |
rotation = self._rotation.detach().cpu().numpy()
|
@@ -308,7 +308,7 @@ class GaussianModel:
|
|
308 |
dtype_full = [(attribute, 'f4') for attribute in self.construct_list_of_attributes()]
|
309 |
|
310 |
elements = np.empty(xyz.shape[0], dtype=dtype_full)
|
311 |
-
attributes = np.concatenate((xyz, normals, f_dc,
|
312 |
elements[:] = list(map(tuple, attributes))
|
313 |
el = PlyElement.describe(elements, 'vertex')
|
314 |
PlyData([el]).write(path)
|
@@ -331,7 +331,7 @@ class GaussianModel:
|
|
331 |
features_dc[:, 1, 0] = np.asarray(plydata.elements[0]["f_dc_1"])
|
332 |
features_dc[:, 2, 0] = np.asarray(plydata.elements[0]["f_dc_2"])
|
333 |
|
334 |
-
extra_f_names = [p.name for p in plydata.elements[0].properties if p.name.startswith("f_rest_")]
|
335 |
extra_f_names = sorted(extra_f_names, key = lambda x: int(x.split('_')[-1]))
|
336 |
assert len(extra_f_names)==3*(self.max_sh_degree + 1) ** 2 - 3
|
337 |
features_extra = np.zeros((xyz.shape[0], len(extra_f_names)))
|
@@ -354,7 +354,7 @@ class GaussianModel:
|
|
354 |
|
355 |
self._xyz = nn.Parameter(torch.tensor(xyz, dtype=torch.float, device="cuda").requires_grad_(True))
|
356 |
self._features_dc = nn.Parameter(torch.tensor(features_dc, dtype=torch.float, device="cuda").transpose(1, 2).contiguous().requires_grad_(True))
|
357 |
-
self._features_rest = nn.Parameter(torch.tensor(features_extra, dtype=torch.float, device="cuda").transpose(1, 2).contiguous().requires_grad_(True))
|
358 |
self._opacity = nn.Parameter(torch.tensor(opacities, dtype=torch.float, device="cuda").requires_grad_(True))
|
359 |
self._scaling = nn.Parameter(torch.tensor(scales, dtype=torch.float, device="cuda").requires_grad_(True))
|
360 |
self._rotation = nn.Parameter(torch.tensor(rots, dtype=torch.float, device="cuda").requires_grad_(True))
|
@@ -526,7 +526,7 @@ class Feat2GaussianModel(GaussianModel):
|
|
526 |
self.active_sh_degree = sh_degree
|
527 |
self.sh_coeffs = ((sh_degree + 1) ** 2) * 3-3
|
528 |
net_width = feat_dim
|
529 |
-
out_dim = {'xyz': 3, 'scaling': 3, 'rotation': 4, 'opacity': 1, 'f_dc': 3, 'f_rest': self.sh_coeffs
|
530 |
for key in gs_params_group.get('head', []):
|
531 |
setattr(self, f'head_{key}', conditionalWarp(layers=[feat_dim, net_width, out_dim[key]], skip=[]).cuda())
|
532 |
|
@@ -536,7 +536,7 @@ class Feat2GaussianModel(GaussianModel):
|
|
536 |
'rotation': '_rotation',
|
537 |
'opacity': '_opacity',
|
538 |
'f_dc': '_features_dc',
|
539 |
-
'f_rest': '_features_rest',
|
540 |
'pc_feat': 'pc_feat',
|
541 |
}
|
542 |
|
@@ -554,7 +554,7 @@ class Feat2GaussianModel(GaussianModel):
|
|
554 |
self.active_sh_degree,
|
555 |
self._xyz,
|
556 |
self._features_dc,
|
557 |
-
self._features_rest,
|
558 |
self._scaling,
|
559 |
self._rotation,
|
560 |
self._opacity,
|
@@ -571,7 +571,7 @@ class Feat2GaussianModel(GaussianModel):
|
|
571 |
(self.active_sh_degree,
|
572 |
self._xyz,
|
573 |
self._features_dc,
|
574 |
-
self._features_rest,
|
575 |
self._scaling,
|
576 |
self._rotation,
|
577 |
self._opacity,
|
@@ -598,8 +598,8 @@ class Feat2GaussianModel(GaussianModel):
|
|
598 |
|
599 |
if key == 'f_dc':
|
600 |
self._features_dc = getattr(self, f'head_{key}')(feat_in, self.param_init[key].view(-1, 3)).reshape(-1, 1, 3)
|
601 |
-
elif key == 'f_rest':
|
602 |
-
|
603 |
else:
|
604 |
setattr(self, f'_{key}', getattr(self, f'head_{key}')(feat_in, self.param_init[key]))
|
605 |
|
@@ -661,7 +661,7 @@ class Feat2GaussianModel(GaussianModel):
|
|
661 |
'rotation': rots,
|
662 |
'opacity': opacities,
|
663 |
'f_dc': features[:, :, 0:1].transpose(1, 2).contiguous(),
|
664 |
-
'f_rest': features[:, :, 1:].transpose(1, 2).contiguous(),
|
665 |
'pc_feat': fused_point_feat,
|
666 |
}
|
667 |
|
@@ -696,7 +696,7 @@ class Feat2GaussianModel(GaussianModel):
|
|
696 |
self.param_lr = {
|
697 |
"xyz": training_args.position_lr_init * self.spatial_lr_scale,
|
698 |
"f_dc": training_args.feature_lr,
|
699 |
-
"f_rest": training_args.feature_sh_lr,
|
700 |
"opacity": training_args.opacity_lr,
|
701 |
"scaling": training_args.scaling_lr,
|
702 |
"rotation": training_args.rotation_lr
|
|
|
187 |
@property
|
188 |
def get_features(self):
|
189 |
features_dc = self._features_dc
|
190 |
+
# features_rest = self._features_rest
|
191 |
+
return features_dc
|
192 |
|
193 |
@property
|
194 |
def get_opacity(self):
|
|
|
285 |
# All channels except the 3 DC
|
286 |
for i in range(self._features_dc.shape[1]*self._features_dc.shape[2]):
|
287 |
l.append('f_dc_{}'.format(i))
|
288 |
+
# for i in range(self._features_rest.shape[1]*self._features_rest.shape[2]):
|
289 |
+
# l.append('f_rest_{}'.format(i))
|
290 |
l.append('opacity')
|
291 |
for i in range(self._scaling.shape[1]):
|
292 |
l.append('scale_{}'.format(i))
|
|
|
300 |
xyz = self._xyz.detach().cpu().numpy()
|
301 |
normals = np.zeros_like(xyz)
|
302 |
f_dc = self._features_dc.detach().transpose(1, 2).flatten(start_dim=1).contiguous().cpu().numpy()
|
303 |
+
# f_rest = self._features_rest.detach().transpose(1, 2).flatten(start_dim=1).contiguous().cpu().numpy()
|
304 |
opacities = self._opacity.detach().cpu().numpy()
|
305 |
scale = self._scaling.detach().cpu().numpy()
|
306 |
rotation = self._rotation.detach().cpu().numpy()
|
|
|
308 |
dtype_full = [(attribute, 'f4') for attribute in self.construct_list_of_attributes()]
|
309 |
|
310 |
elements = np.empty(xyz.shape[0], dtype=dtype_full)
|
311 |
+
attributes = np.concatenate((xyz, normals, f_dc, opacities, scale, rotation), axis=1) # f_rest,
|
312 |
elements[:] = list(map(tuple, attributes))
|
313 |
el = PlyElement.describe(elements, 'vertex')
|
314 |
PlyData([el]).write(path)
|
|
|
331 |
features_dc[:, 1, 0] = np.asarray(plydata.elements[0]["f_dc_1"])
|
332 |
features_dc[:, 2, 0] = np.asarray(plydata.elements[0]["f_dc_2"])
|
333 |
|
334 |
+
# extra_f_names = [p.name for p in plydata.elements[0].properties if p.name.startswith("f_rest_")]
|
335 |
extra_f_names = sorted(extra_f_names, key = lambda x: int(x.split('_')[-1]))
|
336 |
assert len(extra_f_names)==3*(self.max_sh_degree + 1) ** 2 - 3
|
337 |
features_extra = np.zeros((xyz.shape[0], len(extra_f_names)))
|
|
|
354 |
|
355 |
self._xyz = nn.Parameter(torch.tensor(xyz, dtype=torch.float, device="cuda").requires_grad_(True))
|
356 |
self._features_dc = nn.Parameter(torch.tensor(features_dc, dtype=torch.float, device="cuda").transpose(1, 2).contiguous().requires_grad_(True))
|
357 |
+
# self._features_rest = nn.Parameter(torch.tensor(features_extra, dtype=torch.float, device="cuda").transpose(1, 2).contiguous().requires_grad_(True))
|
358 |
self._opacity = nn.Parameter(torch.tensor(opacities, dtype=torch.float, device="cuda").requires_grad_(True))
|
359 |
self._scaling = nn.Parameter(torch.tensor(scales, dtype=torch.float, device="cuda").requires_grad_(True))
|
360 |
self._rotation = nn.Parameter(torch.tensor(rots, dtype=torch.float, device="cuda").requires_grad_(True))
|
|
|
526 |
self.active_sh_degree = sh_degree
|
527 |
self.sh_coeffs = ((sh_degree + 1) ** 2) * 3-3
|
528 |
net_width = feat_dim
|
529 |
+
out_dim = {'xyz': 3, 'scaling': 3, 'rotation': 4, 'opacity': 1, 'f_dc': 3} # , 'f_rest': self.sh_coeffs
|
530 |
for key in gs_params_group.get('head', []):
|
531 |
setattr(self, f'head_{key}', conditionalWarp(layers=[feat_dim, net_width, out_dim[key]], skip=[]).cuda())
|
532 |
|
|
|
536 |
'rotation': '_rotation',
|
537 |
'opacity': '_opacity',
|
538 |
'f_dc': '_features_dc',
|
539 |
+
# 'f_rest': '_features_rest',
|
540 |
'pc_feat': 'pc_feat',
|
541 |
}
|
542 |
|
|
|
554 |
self.active_sh_degree,
|
555 |
self._xyz,
|
556 |
self._features_dc,
|
557 |
+
# self._features_rest,
|
558 |
self._scaling,
|
559 |
self._rotation,
|
560 |
self._opacity,
|
|
|
571 |
(self.active_sh_degree,
|
572 |
self._xyz,
|
573 |
self._features_dc,
|
574 |
+
# self._features_rest,
|
575 |
self._scaling,
|
576 |
self._rotation,
|
577 |
self._opacity,
|
|
|
598 |
|
599 |
if key == 'f_dc':
|
600 |
self._features_dc = getattr(self, f'head_{key}')(feat_in, self.param_init[key].view(-1, 3)).reshape(-1, 1, 3)
|
601 |
+
# elif key == 'f_rest':
|
602 |
+
# self._features_rest = getattr(self, f'head_{key}')(feat_in.detach(), self.param_init[key].view(-1, self.sh_coeffs)).reshape(-1, self.sh_coeffs // 3, 3)
|
603 |
else:
|
604 |
setattr(self, f'_{key}', getattr(self, f'head_{key}')(feat_in, self.param_init[key]))
|
605 |
|
|
|
661 |
'rotation': rots,
|
662 |
'opacity': opacities,
|
663 |
'f_dc': features[:, :, 0:1].transpose(1, 2).contiguous(),
|
664 |
+
# 'f_rest': features[:, :, 1:].transpose(1, 2).contiguous(),
|
665 |
'pc_feat': fused_point_feat,
|
666 |
}
|
667 |
|
|
|
696 |
self.param_lr = {
|
697 |
"xyz": training_args.position_lr_init * self.spatial_lr_scale,
|
698 |
"f_dc": training_args.feature_lr,
|
699 |
+
# "f_rest": training_args.feature_sh_lr,
|
700 |
"opacity": training_args.opacity_lr,
|
701 |
"scaling": training_args.scaling_lr,
|
702 |
"rotation": training_args.rotation_lr
|