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

Function eval_on_batch

script/feature/direct_feature_matching.py:178–213  ·  view source on GitHub ↗

Perform 1 step of eval

(args, data, model, feat_model, pose, img_idx, hwf, half_res, device, world_setup_dict, **render_kwargs_test)

Source from the content-addressed store, hash-verified

176 return batch_rays, target_s
177
178def eval_on_batch(args, data, model, feat_model, pose, img_idx, hwf, half_res, device, world_setup_dict, **render_kwargs_test):
179 ''' Perform 1 step of eval'''
180 with torch.no_grad():
181 H, W, focal = hwf
182 _, pose_ = inference_pose_regression(args, data, device, model)
183 device_cpu = torch.device('cpu')
184 pose_ = pose_.to(device_cpu) # put predict pose back to cpu
185 pose_nerf = pose_.clone()
186
187 if args.NeRFH:
188 # rescale the predicted pose to nerf scales
189 pose_nerf = fix_coord_supp(args, pose_nerf, world_setup_dict, device=device_cpu)
190
191 half_res=False # no need to use half_res for inference
192 batch_rays, target = prepare_batch_render(args, pose_nerf, args.batch_size, data, H, W, focal, half_res)
193 batch_rays = batch_rays.to(device)
194 target = target.to(device)
195 pose = pose.to(device)
196 img_idx = img_idx.to(device)
197 pose_nerf = pose_nerf.to(device)
198
199 # every new tensor from onward is in GPU
200 torch.set_default_tensor_type('torch.cuda.FloatTensor')
201 rgb, disp, acc, extras = render(H, W, focal, chunk=args.chunk, rays=batch_rays, img_idx=img_idx, **render_kwargs_test)
202
203 loss = PoseLoss(args, pose_, pose, device)
204 psnr = mse2psnr(img2mse(rgb, target))
205
206 # end of every new tensor from onward is in GPU
207 torch.set_default_tensor_type('torch.FloatTensor')
208
209 iter_loss = loss.to(device_cpu).detach().numpy()
210 iter_loss = np.array([iter_loss])
211
212 iter_psnr = psnr.to(device_cpu).detach().numpy()
213 return iter_loss, iter_psnr
214
215def eval_on_epoch(args, data_loaders, model, feat_model, hwf, half_res, device, world_setup_dict, **render_kwargs_test):
216 ''' Perform 1 epoch of training with batch '''

Callers 1

eval_on_epochFunction · 0.70

Calls 5

fix_coord_suppFunction · 0.90
renderFunction · 0.90
prepare_batch_renderFunction · 0.70
PoseLossFunction · 0.70

Tested by

no test coverage detected