-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
43 lines (34 loc) · 1.01 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
import matplotlib
import matplotlib.cm
import numpy as np
def DepthNorm(depth, maxDepth=1000.0):
return maxDepth / depth
class AverageMeter(object):
def __init__(self):
self.reset()
def reset(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0
def update(self, val, n=1):
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
def colorize(value, vmin=10, vmax=1000, cmap='plasma'):
value = value.cpu().numpy()[0,:,:]
# normalize
vmin = value.min() if vmin is None else vmin
vmax = value.max() if vmax is None else vmax
if vmin!=vmax:
value = (value - vmin) / (vmax - vmin) # vmin..vmax
else:
# Avoid 0-division
value = value*0.
# squeeze last dim if it exists
#value = value.squeeze(axis=0)
cmapper = matplotlib.cm.get_cmap(cmap)
value = cmapper(value,bytes=True) # (nxmx4)
img = value[:,:,:3]
return img.transpose((2,0,1))