MCPcopy Index your code
hub / github.com/ActiveVisionLab/DFNet / render_rays

Function render_rays

script/models/rendering.py:245–337  ·  view source on GitHub ↗
(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,
                i_epoch=-1,
                embedding_a=None,
                embedding_t=None,
                test_time=False)

Source from the content-addressed store, hash-verified

243 return rgb_map, disp_map, acc_map, weights, depth_map, transient_sigmas, beta
244
245def render_rays(ray_batch,
246 network_fn,
247 network_query_fn,
248 N_samples,
249 retraw=False,
250 lindisp=False,
251 perturb=0.,
252 N_importance=0,
253 network_fine=None,
254 white_bkgd=False,
255 raw_noise_std=0.,
256 verbose=False,
257 pytest=False,
258 i_epoch=-1,
259 embedding_a=None,
260 embedding_t=None,
261 test_time=False):
262 N_rays = ray_batch.shape[0]
263 rays_o, rays_d = ray_batch[:,0:3], ray_batch[:,3:6] # [N_rays, 3] each
264 viewdirs = ray_batch[:,8:11] if ray_batch.shape[-1] > 8 else None
265 bounds = torch.reshape(ray_batch[...,6:8], [-1,1,2])
266 near, far = bounds[...,0], bounds[...,1] # [-1,1]
267 img_idxs = ray_batch[...,11:] # same as ts from nerf_pl-nerfw code [N_rays]
268
269 t_vals = torch.linspace(0., 1., steps=N_samples)
270 if not lindisp:
271 z_vals = near * (1.-t_vals) + far * (t_vals) # sample in depth
272 else:
273 z_vals = 1./(1./near * (1.-t_vals) + 1./far * (t_vals)) # sample in diparity disparity = 1/depth
274
275 z_vals = z_vals.expand([N_rays, N_samples])
276
277 if perturb > 0.:
278 # get intervals between samples
279 mids = .5 * (z_vals[...,1:] + z_vals[...,:-1]) # find mid points of each interval
280 upper = torch.cat([mids, z_vals[...,-1:]], -1)
281 lower = torch.cat([z_vals[...,:1], mids], -1)
282 # stratified samples in those intervals
283 t_rand = torch.rand(z_vals.shape) # randomly choose in intervals
284
285 z_vals = lower + (upper - lower) * t_rand
286
287 pts = rays_o[...,None,:] + rays_d[...,None,:] * z_vals[...,:,None] # [N_rays, N_samples, 3] # Sample 3D point print it out, [batchsize, 64 samples, 3 axis]
288 # inference coarse MLPs
289 if i_epoch>=0: # Coarse-to-fine
290 raw = network_query_fn(pts, viewdirs, None, network_fn, 'coarse', None, None, False, test_time=test_time, epoch=i_epoch)
291 else:
292 raw = network_query_fn(pts, viewdirs, None, network_fn, 'coarse', None, None, False, test_time=test_time)
293
294
295 rgb_map, disp_map, acc_map, weights, depth_map, _, _ = raw2outputs_NeRFW(raw, z_vals, rays_d, raw_noise_std, white_bkgd, test_time=test_time, typ="coarse")
296 if N_importance > 0:
297
298 rgb_map_0, disp_map_0, acc_map_0 = rgb_map, disp_map, acc_map
299
300 z_vals_mid = .5 * (z_vals[...,1:] + z_vals[...,:-1])
301 z_samples = sample_pdf(z_vals_mid, weights[...,1:-1], N_importance, det=(perturb==0.), pytest=pytest)
302 z_samples = z_samples.detach()

Callers 1

batchify_raysFunction · 0.85

Calls 2

raw2outputs_NeRFWFunction · 0.85
sample_pdfFunction · 0.85

Tested by

no test coverage detected