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

Function render_virtual_imgs

script/feature/misc.py:254–289  ·  view source on GitHub ↗

render nerfw imgs, save unscaled pose and results

(args, pose_perturb, img_idxs, hwf, device, render_kwargs_test, world_setup_dict)

Source from the content-addressed store, hash-verified

252 return targets, rgbs, poses, img_idxs
253
254def render_virtual_imgs(args, pose_perturb, img_idxs, hwf, device, render_kwargs_test, world_setup_dict):
255 ''' render nerfw imgs, save unscaled pose and results'''
256 H, W, focal = hwf
257 rgb_list = []
258
259 # inference nerfw and save rgb, target, pose
260 for batch_idx in range(pose_perturb.shape[0]):
261 # if batch_idx % 10 == 0:
262 # print("renders RVS {}/total {}".format(batch_idx, pose_perturb.shape[0]))
263
264 pose = pose_perturb[batch_idx]
265 img_idx = img_idxs[batch_idx].to(device)
266 pose_nerf = pose.clone()
267
268 # rescale the predicted pose to nerf scales
269 pose_nerf = fix_coord_supp(args, pose_nerf[None,...].cpu(), world_setup_dict)
270
271 # generate nerf image
272 with torch.no_grad():
273 torch.set_default_tensor_type('torch.cuda.FloatTensor')
274 if args.tinyimg:
275 rgb, _, _, _ = render(int(H//args.tinyscale), int(W//args.tinyscale), focal/args.tinyscale, chunk=args.chunk, c2w=pose_nerf[0,:3,:4].to(device), retraw=False, img_idx=img_idx, **render_kwargs_test)
276 # convert rgb to B,C,H,W
277 rgb = rgb[None,...].permute(0,3,1,2)
278 # upsample rgb to hwf size
279 rgb = torch.nn.Upsample(size=(H, W), mode='bicubic')(rgb)
280 # convert rgb back to H,W,C format
281 rgb = rgb[0].permute(1,2,0)
282
283 else:
284 rgb, _, _, _ = render(H, W, focal, chunk=args.chunk, c2w=pose_nerf[0,:3,:4].to(device), retraw=False, img_idx=img_idx, **render_kwargs_test)
285 torch.set_default_tensor_type('torch.FloatTensor')
286 rgb_list.append(rgb.cpu())
287
288 rgbs = torch.stack(rgb_list).detach()
289 return rgbs
290
291
292class UnNormalize(object):

Callers 1

train_featureFunction · 0.85

Calls 2

fix_coord_suppFunction · 0.90
renderFunction · 0.90

Tested by

no test coverage detected