MCPcopy Create free account
hub / github.com/Sin3DM/Sin3DM / eval_SSFID_given_paths

Function eval_SSFID_given_paths

evaluation/ssfid.py:81–117  ·  view source on GitHub ↗
(data_paths, ref_path, model_out_layer=2, device="cpu")

Source from the content-addressed store, hash-verified

79
80@torch.no_grad()
81def eval_SSFID_given_paths(data_paths, ref_path, model_out_layer=2, device="cpu"):
82 random.seed(1234)
83
84 # load model
85 model = classifier()
86 voxel_size = 128
87 weights_path = 'Clsshapenet_'+str(voxel_size)+'.pth'
88 if not os.path.exists(weights_path):
89 raise RuntimeError(f"'{weights_path}' not exists. Please download it from https://drive.google.com/file/d/1HjnDudrXsNY4CYhIGhH4Q0r3-NBnBaiC/view?usp=sharing.")
90 model.load_state_dict(torch.load(weights_path))
91 model.to(device)
92 model.eval()
93
94 # load reference
95 # gen_data_shape = load_voxgrid(data_paths[0], resolution=128, device=device).shape
96 ref_data = load_sdfgrid2vox(ref_path, resolution=128, device=device).float()
97
98 mu_r, sigma_r = calculate_activation_statistics(ref_data, model, model_out_layer)
99
100 ssfid_values = []
101 for path in tqdm(data_paths, desc="SSFID"):
102 gen_data = load_voxgrid(path, resolution=128, device=device).float()
103
104 if gen_data.shape != ref_data.shape:
105 raise RuntimeError('Generated shape and reference shape shall have equal size.')
106
107 mu_f, sigma_f = calculate_activation_statistics(gen_data, model, model_out_layer)
108
109 ssfid = calculate_frechet_distance(mu_r, sigma_r, mu_f, sigma_f)
110 ssfid_values.append(ssfid)
111
112 ssfid_avg = np.mean(ssfid_values).round(6)
113 ssfid_std = np.std(ssfid_values).round(6)
114
115 eval_results = {'SSFID_avg': ssfid_avg,
116 'SSFID_std': ssfid_std}
117 return eval_results

Callers 1

eval_full.pyFile · 0.90

Calls 6

classifierClass · 0.90
load_sdfgrid2voxFunction · 0.90
load_voxgridFunction · 0.90
tqdmFunction · 0.85

Tested by

no test coverage detected