-
Notifications
You must be signed in to change notification settings - Fork 0
/
f1_cd_emd.py
125 lines (108 loc) · 5.6 KB
/
f1_cd_emd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from tqdm import tqdm
import os
import trimesh
from eval_util import obj_data_to_mesh3d, FSCORE, CD, EMD, get_normalize_mesh, HTML_rendering
import numpy as np
import sys
num_sample_points = 2048
batch_no_vec = [100,201,300,400,500,550, 1150]
for i in tqdm(range(len(batch_no_vec))):
print('Collect GT surface samples...', end=' ')
obj_file_gt = './obj/gt/chair_gt_' + str(batch_no_vec[i]).zfill(4) + '.obj'
with open(obj_file_gt, 'r', encoding='utf8') as f_gt:
obj_data_gt = f_gt.read()
pc_gt_surf,_ = obj_data_to_mesh3d(obj_data_gt)
choice_gt = np.random.randint(pc_gt_surf.shape[0], size=num_sample_points)
PC_GT = pc_gt_surf[choice_gt, ...]
print('done.')
print('Collect OURS surface samples...', end=' ')
# NORMALIZED and CLEANED
#obj_file_ours_norm = "./obj_cleaned/ours/chair_ours_norm_" + str(batch_no_vec[i]).zfill(4) + ".obj"
# with open(obj_file_ours_norm, 'r', encoding='utf8') as f_ours:
# obj_data_ours = f_ours.read()
# pc_ours_surf,_ = obj_data_to_mesh3d(obj_data_ours)
# One more normalization
# obj_file_ours = "obj_cleaned/ours/chair_ours_norm_" + str(batch_no_vec[i]).zfill(4) + ".obj"
# obj_file_ours_cleaned_norm, centroid, m = get_normalize_mesh(obj_file_ours, "obj/chair_ours_cleaned_normalized_" + str(batch_no_vec[i]).zfill(4) + ".obj")
obj_file_ours = "./obj_cleaned/localonly/chair_ours_normalized_" + str(batch_no_vec[i]).zfill(4) + ".obj"
obj_file_ours_cleaned_norm, centroid, m = get_normalize_mesh(obj_file_ours, "obj_cleaned/localonly/chair_final_" + str(batch_no_vec[i]).zfill(4) + ".obj")
with open(obj_file_ours_cleaned_norm, 'r', encoding='utf8') as f_ours:
obj_data_ours = f_ours.read()
pc_ours_surf,_ = obj_data_to_mesh3d(obj_data_ours)
choice_ours = np.random.randint(pc_ours_surf.shape[0], size=num_sample_points)
PC_OURS = pc_ours_surf[choice_ours, ...]
print('done.')
print('Collect THEIRS surface samples...', end=' ')
# obj_file_theirs = '../DISN_xar/demo/chair_theirs.obj'
obj_file_theirs_norm = "./obj/theirs/chair_theirs_norm_" + str(batch_no_vec[i]).zfill(4) + ".obj"
with open(obj_file_theirs_norm, 'r', encoding='utf8') as f_theirs:
obj_data_theirs = f_theirs.read()
pc_theirs_surf,_ = obj_data_to_mesh3d(obj_data_theirs)
choice_theirs = np.random.randint(pc_theirs_surf.shape[0], size=num_sample_points)
PC_THEIRS = pc_theirs_surf[choice_theirs, ...]
PC_THEIRS[:, [0,2]] = PC_THEIRS[:, [2,0]]
print('Ground Truth')
print(PC_GT[:10])
print('Ours')
print(PC_OURS[:10])
print('Theirs')
print(PC_THEIRS[:10])
print('--------------------------------------------------------------------------------')
print('FSCORE')
x_side = np.max(PC_GT[:,0]) - np.min(PC_GT[:,0])
y_side = np.max(PC_GT[:,1]) - np.min(PC_GT[:,1])
z_side = np.max(PC_GT[:,2]) - np.min(PC_GT[:,2])
SIDE_LEN = max(x_side, y_side, z_side)
ratios = [0.01, 0.02, 0.05, 0.10, 0.20]
print('Threshold(%)', end='\t')
for r in ratios:
pr = 100*r
print('%3.1f' % pr, end='\t')
print()
print('--------------------------------------------------------------------------------')
print('OURS ', end='\t')
for r in ratios:
print('%5.3f' % FSCORE(PC_OURS , PC_GT, SIDE_LEN * r), end='\t')
print()
print('THEIRS ', end='\t')
for r in ratios:
print('%5.3f' % FSCORE(PC_THEIRS, PC_GT, SIDE_LEN * r), end='\t')
print('\n--------------------------------------------------------------------------------')
#ours
print('Our Distances:')
cd = CD(PC_OURS, PC_GT)
print('Chamfer Distance : %f' % cd)
emd = EMD(PC_OURS, PC_GT)
print('Earth Mover\'s Distance: %f' % emd)
print('--------------------------------------------------------------------------------')
#Theirs
print('Their Distances:')
cd = CD(PC_THEIRS, PC_GT)
print('Chamfer Distance : %f' % cd)
emd = EMD(PC_THEIRS, PC_GT)
print('Earth Mover\'s Distance: %f' % emd)
print('--------------------------------------------------------------------------------')
# Renderings
# with open(obj_file_gt, 'r', encoding='utf8') as f_gt:
# obj_data_gt = f_gt.read()
# verts_gt , simplices_gt = obj_data_to_mesh3d(obj_data_gt)
# print('GT shape')
# print(verts_gt.shape)
# print(simplices_gt.shape)
with open(obj_file_ours_cleaned_norm, 'r', encoding='utf8') as f_ours:
obj_data_ours = f_ours.read()
verts_ours , simplices_ours = obj_data_to_mesh3d(obj_data_ours)
print('OURS shape')
print(verts_ours.shape)
print(simplices_ours.shape)
# with open(obj_file_theirs_norm, 'r', encoding='utf8') as f_theirs:
# obj_data_theirs = f_theirs.read()
# verts_theirs, simplices_theirs = obj_data_to_mesh3d(obj_data_theirs)
# print('THEIRS shape')
# print(verts_theirs.shape)
# print(simplices_theirs.shape)
# verts_theirs[:, [0,2]] = verts_theirs[:, [2,0]]
#HTML_rendering('GT_' + str(batch_no_vec[i]).zfill(4), verts_gt , simplices_gt )
HTML_rendering('OURS_LOCALONLY_' + str(batch_no_vec[i]).zfill(4), verts_ours , simplices_ours )
#HTML_rendering('THEIRS_' + str(batch_no_vec[i]).zfill(4), verts_theirs, simplices_theirs)
print('done.')