-
Notifications
You must be signed in to change notification settings - Fork 21
/
utils.py
37 lines (31 loc) · 1.41 KB
/
utils.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
import numpy as np
import torch
def init_regul(source_vertices, source_faces):
sommet_A_source = source_vertices[source_faces[:, 0]]
sommet_B_source = source_vertices[source_faces[:, 1]]
sommet_C_source = source_vertices[source_faces[:, 2]]
target = []
target.append(np.sqrt( np.sum((sommet_A_source - sommet_B_source) ** 2, axis=1)))
target.append(np.sqrt( np.sum((sommet_B_source - sommet_C_source) ** 2, axis=1)))
target.append(np.sqrt( np.sum((sommet_A_source - sommet_C_source) ** 2, axis=1)))
return target
def get_target(vertice, face, size):
target = init_regul(vertice,face)
target = np.array(target)
target = torch.from_numpy(target).float().cuda()
#target = target+0.0001
target = target.unsqueeze(1).expand(3,size,-1)
return target
def compute_score(points, faces, target):
score = 0
sommet_A = points[:,faces[:, 0]]
sommet_B = points[:,faces[:, 1]]
sommet_C = points[:,faces[:, 2]]
score = torch.abs(torch.sqrt(torch.sum((sommet_A - sommet_B) ** 2, dim=2)) / target[0] -1)
score = score + torch.abs(torch.sqrt(torch.sum((sommet_B - sommet_C) ** 2, dim=2)) / target[1] -1)
score = score + torch.abs(torch.sqrt(torch.sum((sommet_A - sommet_C) ** 2, dim=2)) / target[2] -1)
return torch.mean(score)
def weights_init(m):
classname = m.__class__.__name__
if classname.find('Conv') != -1:
m.weight.data.normal_(0.0, 0.02)