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

Function eval_on_batch

script/dm/direct_pose_model.py:169–206  ·  view source on GitHub ↗

Perform 1 step of eval

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

Source from the content-addressed store, hash-verified

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

Callers 1

eval_on_epochFunction · 0.70

Calls 5

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

Tested by

no test coverage detected