(self, feats, timestamp=None)
| 275 | |
| 276 | @autocast('cuda', enabled=False) |
| 277 | def forward(self, feats, timestamp=None): |
| 278 | # [B, V, N, D] |
| 279 | assert feats.shape[-1] == self.embed_dim |
| 280 | B = feats.shape[0] |
| 281 | input_views = feats.shape[1] |
| 282 | N = feats.shape[1] * feats.shape[2] * self.ratio * self.n_sample |
| 283 | feats = feats.type(torch.float32) |
| 284 | feats = rearrange(feats, 'b v n d -> (b v) n d') |
| 285 | |
| 286 | gsparams = {} |
| 287 | prior_params = {} |
| 288 | for key in self.fix_keys: |
| 289 | if key == "scale": |
| 290 | fix_v = 0.03 * torch.ones(B, N, 3).to(feats.device) |
| 291 | elif key == "rot_static": |
| 292 | fix_v = torch.zeros(B, N, 4).to(feats.device) |
| 293 | fix_v[:, :, 0] = 1. |
| 294 | elif key == "rot_dynamic": |
| 295 | fix_v = torch.zeros(B, N, 4).to(feats.device) |
| 296 | elif key == "xyz_dynamic": |
| 297 | fix_v = torch.zeros(B, N, self.key_dims[key]//3, 3).to(feats.device) |
| 298 | elif key == "opacity_dynamic": |
| 299 | fix_v = torch.ones(B, N, 1).to(feats.device) |
| 300 | else: |
| 301 | raise NotImplementedError |
| 302 | gsparams[key] = fix_v |
| 303 | |
| 304 | def reorder(v): |
| 305 | # [B*V, H*W, d*r*r] |
| 306 | v = rearrange(v, 'B (h w) D -> B D h w', h=self.actual_h, w=self.actual_w).contiguous() |
| 307 | v = self.pixelshuffle(v) # [B*V, d, H*r, W*r] |
| 308 | v = rearrange(v, '(b v) d h w -> b (v h w) d', v=input_views) |
| 309 | return v |
| 310 | |
| 311 | for key in self.pred_keys: |
| 312 | v = feats |
| 313 | v = self.gs_layer[key](v) |
| 314 | v = reorder(v) |
| 315 | |
| 316 | gsparams[key] = self.key_activation(v, key) |
| 317 | |
| 318 | for key in self.sample_keys: |
| 319 | logits_pred = torch.ones(feats.shape[0], feats.shape[1], 1).to(feats.device).float() |
| 320 | activation = "tanh" |
| 321 | means = reorder(self.mix_layer[f"{key}_mean"](feats)) # [B, N, nr_mix * dim] |
| 322 | log_scales = reorder(self.mix_layer[f"{key}_scale"](feats)) |
| 323 | logits, means, log_scales = self.prior.expand_params(logits_pred, means, log_scales, mean_activation=activation) |
| 324 | prior_params[key] = {"logits": logits, "means": means, "log_scales": log_scales} # [B, N*r, dim, nr_mix] |
| 325 | |
| 326 | if key == "xyz_static": |
| 327 | val, probs = self.prior.sample(logits, means, log_scales) |
| 328 | x_pred, y_pred, z_pred = val.chunk(3, dim=-1) |
| 329 | y_val = (0.5 + y_pred * 0.5) |
| 330 | assert y_val.min() >= 0. and y_val.max() <= 1., f"y_val: {y_val.min()}, {y_val.max()}" |
| 331 | x_offset = self.x_max * x_pred |
| 332 | z_offset = self.z_max * z_pred |
| 333 | x_map = self.x_map.repeat(self.opt.input_frames).reshape(1, -1, 1) |
| 334 | z_map = self.z_map.repeat(self.opt.input_frames).reshape(1, -1, 1) |
nothing calls this directly
no test coverage detected