MCPcopy Create free account
hub / github.com/LeapLabTHU/ActiveNeRF / render_rays

Function render_rays

run_nerf.py:319–428  ·  view source on GitHub ↗

Volumetric rendering. Args: ray_batch: array of shape [batch_size, ...]. All information necessary for sampling along a ray, including: ray origin, ray direction, min dist, max dist, and unit-magnitude viewing direction. network_fn: function. Model for predicting

(ray_batch,
                network_fn,
                network_query_fn,
                N_samples,
                retraw=False,
                lindisp=False,
                perturb=0.,
                N_importance=0,
                network_fine=None,
                white_bkgd=False,
                raw_noise_std=0.,
                verbose=False,
                pytest=False)

Source from the content-addressed store, hash-verified

317
318
319def render_rays(ray_batch,
320 network_fn,
321 network_query_fn,
322 N_samples,
323 retraw=False,
324 lindisp=False,
325 perturb=0.,
326 N_importance=0,
327 network_fine=None,
328 white_bkgd=False,
329 raw_noise_std=0.,
330 verbose=False,
331 pytest=False):
332 """Volumetric rendering.
333 Args:
334 ray_batch: array of shape [batch_size, ...]. All information necessary
335 for sampling along a ray, including: ray origin, ray direction, min
336 dist, max dist, and unit-magnitude viewing direction.
337 network_fn: function. Model for predicting RGB and density at each point
338 in space.
339 network_query_fn: function used for passing queries to network_fn.
340 N_samples: int. Number of different times to sample along each ray.
341 retraw: bool. If True, include model's raw, unprocessed predictions.
342 lindisp: bool. If True, sample linearly in inverse depth rather than in depth.
343 perturb: float, 0 or 1. If non-zero, each ray is sampled at stratified
344 random points in time.
345 N_importance: int. Number of additional times to sample along each ray.
346 These samples are only passed to network_fine.
347 network_fine: "fine" network with same spec as network_fn.
348 white_bkgd: bool. If True, assume a white background.
349 raw_noise_std: ...
350 verbose: bool. If True, print more debugging info.
351 Returns:
352 rgb_map: [num_rays, 3]. Estimated RGB color of a ray. Comes from fine model.
353 disp_map: [num_rays]. Disparity map. 1 / depth.
354 acc_map: [num_rays]. Accumulated opacity along each ray. Comes from fine model.
355 raw: [num_rays, num_samples, 4]. Raw predictions from model.
356 rgb0: See rgb_map. Output for coarse model.
357 disp0: See disp_map. Output for coarse model.
358 acc0: See acc_map. Output for coarse model.
359 z_std: [num_rays]. Standard deviation of distances along ray for each
360 sample.
361 """
362 N_rays = ray_batch.shape[0]
363 rays_o, rays_d = ray_batch[:,0:3], ray_batch[:,3:6] # [N_rays, 3] each
364 viewdirs = ray_batch[:,-3:] if ray_batch.shape[-1] > 8 else None
365 bounds = torch.reshape(ray_batch[...,6:8], [-1,1,2])
366 near, far = bounds[...,0], bounds[...,1] # [-1,1]
367
368 t_vals = torch.linspace(0., 1., steps=N_samples)
369 if not lindisp:
370 z_vals = near * (1.-t_vals) + far * (t_vals)
371 else:
372 z_vals = 1./(1./near * (1.-t_vals) + 1./far * (t_vals))
373
374 z_vals = z_vals.expand([N_rays, N_samples])
375
376 if perturb > 0.:

Callers 1

batchify_raysFunction · 0.85

Calls 2

raw2outputsFunction · 0.85
sample_pdfFunction · 0.85

Tested by

no test coverage detected