-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
54 lines (38 loc) · 1.35 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# initialize the weighs of the network for Convolutional layers and batchnorm layers
from pytorch3d.ops import knn_points
def weights_init(m):
classname = m.__class__.__name__
if classname.find('Conv') != -1 and classname.find('Conv2d') == -1:
m.weight.data.normal_(0.0, 0.02)
elif classname.find('BatchNorm') != -1 and classname.find('BatchNorm2d') == -1:
m.weight.data.normal_(1.0, 0.02)
m.bias.data.fill_(0)
class AverageValueMeter(object):
"""Computes and stores the average and current value"""
def __init__(self):
self.reset()
def reset(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0.0
def update(self, val, n=1):
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
def import_file(full_name, path):
"""Import a python module from a path. 3.4+ only.
Does not call sys.modules[full_name] = path
"""
from importlib import util
spec = util.spec_from_file_location(full_name, path)
mod = util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
def chemfer_dist(x, y):
x_nn = knn_points(x, y, K=1)
y_nn = knn_points(y, x, K=1)
cham_x = x_nn.dists[..., 0] # (N, P1)
cham_y = y_nn.dists[..., 0] # (N, P2)
return cham_x, cham_y