MCPcopy Create free account
hub / github.com/ActiveVisionLab/DFNet / forward

Method forward

script/models/nerfw.py:297–354  ·  view source on GitHub ↗

Encodes input (xyz+dir) to rgb+sigma (not ready to render yet). For rendering this ray, please see rendering.py Inputs: x: the embedded vector of position (+ direction + appearance + transient) sigma_only: whether to infer sigma only. has

(self, x, sigma_only=False, output_transient=True)

Source from the content-addressed store, hash-verified

295 self.transient_beta = nn.Sequential(nn.Linear(W//2, 1), nn.Softplus())
296
297 def forward(self, x, sigma_only=False, output_transient=True):
298 """
299 Encodes input (xyz+dir) to rgb+sigma (not ready to render yet).
300 For rendering this ray, please see rendering.py
301
302 Inputs:
303 x: the embedded vector of position (+ direction + appearance + transient)
304 sigma_only: whether to infer sigma only.
305 has_transient: whether to infer the transient component.
306
307 Outputs (concatenated):
308 if sigma_ony:
309 static_sigma
310 elif output_transient:
311 static_rgb, static_sigma, transient_rgb, transient_sigma, transient_beta
312 else:
313 static_rgb, static_sigma
314 """
315 if sigma_only:
316 input_xyz = x
317 elif output_transient:
318 input_xyz, input_dir_a, input_t = \
319 torch.split(x, [self.in_channels_xyz,
320 self.in_channels_dir+self.in_channels_a,
321 self.in_channels_t], dim=-1)
322 else:
323 input_xyz, input_dir_a = \
324 torch.split(x, [self.in_channels_xyz,
325 self.in_channels_dir+self.in_channels_a], dim=-1)
326 xyz_ = input_xyz
327 for i in range(self.D):
328 if i in self.skips:
329 xyz_ = torch.cat([input_xyz, xyz_], 1)
330 xyz_ = getattr(self, f"xyz_encoding_{i+1}")(xyz_)
331
332 static_sigma = self.static_sigma(xyz_) # (B, 1)
333 if sigma_only:
334 return static_sigma
335
336 xyz_encoding_final = self.xyz_encoding_final(xyz_)
337 dir_encoding_input = torch.cat([xyz_encoding_final, input_dir_a], 1)
338 dir_encoding = self.dir_encoding(dir_encoding_input)
339 static_rgb = self.static_rgb(dir_encoding) # (B, 3)
340 static = torch.cat([static_rgb, static_sigma], 1) # (B, 4)
341
342 if not output_transient:
343 return static
344
345 transient_encoding_input = torch.cat([xyz_encoding_final, input_t], 1)
346 transient_encoding = self.transient_encoding(transient_encoding_input)
347 transient_sigma = self.transient_sigma(transient_encoding) # (B, 1)
348 transient_rgb = self.transient_rgb(transient_encoding) # (B, 3)
349 transient_beta = self.transient_beta(transient_encoding) # (B, 1)
350
351 transient = torch.cat([transient_rgb, transient_sigma,
352 transient_beta], 1) # (B, 5)
353
354 return torch.cat([static, transient], 1) # (B, 9)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected