MCPcopy Create free account
hub / github.com/DIVE128/DMVSNet / test

Method test

model.py:302–390  ·  view source on GitHub ↗
(self,parameters=True)

Source from the content-addressed store, hash-verified

300
301 @torch.no_grad()
302 def test(self,parameters=True):
303 self.network.eval()
304
305 if self.args.testpath_single_scene:
306 self.args.datapath = os.path.dirname(self.args.testpath_single_scene)
307
308 if self.args.testlist != "all":
309 with open(self.args.testlist) as f:
310 content = f.readlines()
311 testlist = [line.rstrip() for line in content]
312
313 else:
314 # for tanks & temples or eth3d or colmap
315 testlist = [e for e in os.listdir(self.args.datapath) if os.path.isdir(os.path.join(self.args.datapath, e))] \
316 if not self.args.testpath_single_scene else [os.path.basename(self.args.testpath_single_scene)]
317
318 print(testlist)
319
320 num_stage = len(self.args.ndepths)
321
322 # step1. save all the depth maps and the masks in outputs directory
323 for scene in testlist:
324
325 if scene in tank_cfg.scenes:
326 scene_cfg = getattr(tank_cfg, scene)
327 self.args.max_h = scene_cfg.max_h
328 self.args.max_w = scene_cfg.max_w
329
330 TestImgLoader, _ = get_loader(self.args, self.args.datapath, [scene], self.args.num_view, mode="test")
331
332 for batch_idx, sample in enumerate(TestImgLoader):
333 sample_cuda = tocuda(sample)
334 start_time = time.time()
335
336 outputs = self.network(sample_cuda["imgs"], sample_cuda["proj_matrices"], sample_cuda["depth_values"])
337
338 if parameters==True:
339 macs, params = profile(self.network, inputs=(sample_cuda["imgs"], sample_cuda["proj_matrices"], sample_cuda["depth_values"], ))
340
341 print("params:{},macs:{}".format( params,macs))
342 parameters=False
343
344
345 end_time = time.time()
346
347 outputs = tensor2numpy(outputs)
348 del sample_cuda
349 filenames = sample["filename"]
350 cams = sample["proj_matrices"]["stage{}".format(num_stage)].numpy()
351 imgs = sample["imgs"].numpy()
352 print('Iter {}/{}, Time:{} Res:{}'.format(batch_idx, len(TestImgLoader), end_time - start_time, imgs[0].shape))
353
354 # save depth maps and confidence maps
355 for filename, cam, img, depth_est, photometric_confidence \
356 in zip(filenames, cams, imgs, outputs["depth"],
357 outputs["photometric_confidence"]
358 ):
359

Callers 1

mainMethod · 0.95

Calls 8

get_loaderFunction · 0.90
save_pfmFunction · 0.90
pcd_filterFunction · 0.90
dypcd_filterFunction · 0.90
printFunction · 0.85
tensor2numpyFunction · 0.85
write_camFunction · 0.85
tocudaFunction · 0.70

Tested by

no test coverage detected