MCPcopy Create free account
hub / github.com/NVlabs/InstantSplat / evaluate

Function evaluate

metrics.py:35–125  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

33
34
35def evaluate(args):
36
37 full_dict = {}
38 per_view_dict = {}
39 print("")
40
41 for scene_dir in args.model_paths:
42 try:
43 print("Scene:", scene_dir)
44 full_dict[scene_dir] = {}
45 per_view_dict[scene_dir] = {}
46
47 test_dir = Path(scene_dir) / "test"
48
49 for method in os.listdir(test_dir):
50 print("Method:", method)
51
52 full_dict[scene_dir][method] = {}
53 per_view_dict[scene_dir][method] = {}
54
55 # ------------------------------ (1) image evaluation ------------------------------ #
56 method_dir = test_dir / method
57 out_f = open(method_dir / 'metrics.txt', 'w')
58 gt_dir = method_dir/ "gt"
59 renders_dir = method_dir / "renders"
60 renders, gts, image_names = readImages(renders_dir, gt_dir)
61
62 ssims = []
63 psnrs = []
64 lpipss = []
65
66 for idx in tqdm(range(len(renders)), desc="Metric evaluation progress"):
67 s=ssim(renders[idx], gts[idx])
68 p=psnr(renders[idx], gts[idx])
69 l=lpips(renders[idx], gts[idx], net_type='vgg')
70 out_f.write(f"image name{image_names[idx]}, image idx: {idx}, PSNR: {p.item():.2f}, SSIM: {s:.4f}, LPIPS: {l.item():.4f}\n")
71 ssims.append(s)
72 psnrs.append(p)
73 lpipss.append(l)
74
75 print(" SSIM : {:>12.7f}".format(torch.tensor(ssims).mean(), ".5"))
76 print(" PSNR : {:>12.7f}".format(torch.tensor(psnrs).mean(), ".5"))
77 print(" LPIPS: {:>12.7f}".format(torch.tensor(lpipss).mean(), ".5"))
78
79 full_dict[scene_dir][method].update({"SSIM": torch.tensor(ssims).mean().item(),
80 "PSNR": torch.tensor(psnrs).mean().item(),
81 "LPIPS": torch.tensor(lpipss).mean().item()})
82 per_view_dict[scene_dir][method].update({"SSIM": {name: ssim for ssim, name in zip(torch.tensor(ssims).tolist(), image_names)},
83 "PSNR": {name: psnr for psnr, name in zip(torch.tensor(psnrs).tolist(), image_names)},
84 "LPIPS": {name: lp for lp, name in zip(torch.tensor(lpipss).tolist(), image_names)}})
85
86 # ------------------------------ (2) pose evaluation ------------------------------ #
87 # load GT Colmap poses
88 pose_dir = Path(scene_dir) / "pose"
89 pose_path = pose_dir / method
90 pose_optimized = np.load(pose_path / f'pose_optimized.npy')
91 pose_colmap = read_colmap_gt_pose(args.source_path)
92 gt_train_pose, _ = split_train_test(pose_colmap, llffhold=8, n_views=args.n_views, verbose=False)

Callers 1

metrics.pyFile · 0.85

Calls 12

readImagesFunction · 0.90
ssimFunction · 0.90
psnrFunction · 0.90
lpipsFunction · 0.90
read_colmap_gt_poseFunction · 0.90
split_train_testFunction · 0.90
align_poseFunction · 0.90
align_ate_c2b_use_a2bFunction · 0.90
compute_ATEFunction · 0.90
compute_rpeFunction · 0.90
plot_poseFunction · 0.90
writeMethod · 0.80

Tested by

no test coverage detected