forked from vishwa91/MINER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminer_pointcloud.py
97 lines (73 loc) · 3.1 KB
/
miner_pointcloud.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
#!/usr/bin/env python
import os
import sys
import time
import numpy as np
from scipy import io
from scipy import ndimage
from skimage.metrics import structural_similarity as ssim_func
import matplotlib.pyplot as plt
plt.gray()
sys.path.append('modules')
import miner
import volutils
# NOTE: Although we are training on an binary occupancy volume, we found an L2
# loss to be dramatically faster than logistic loss.
if __name__ == '__main__':
expname = 'lucy' # Example file with uniform sampling
configname = 'configs/volume_16x16x16.ini' # Configuration file
target_mse = 2e-4 # Per block stopping threshold
stopping_iou = 0.99 # What IoU to stop at
scale = 0.5 # Set to a smaller value for faster results
nscales = 4 # Number of miner scales
config = miner.load_config(configname)
# Load the data. Uniformly sampled for fast loading and processing
im = io.loadmat('data/%s.mat'%expname)['hypercube'].astype(np.float32)
config.signaltype = 'occupancy'
# This threshold is for marching cubes.
config.mcubes_thres = 0.4
# Load image and scale
im = ndimage.zoom(im/im.max(), [scale, scale, scale], order=0)
H, W, T = im.shape
config.savedir = 'results/%s'%expname
os.makedirs(config.savedir, exist_ok=True)
best_im = np.zeros((H, W, T), dtype=np.float32)
# Now run MINER on volumetric data
tic = time.time()
best_im, info = miner.miner_volfit(im, nscales,
target_mse,
stopping_iou,
config)
nparams = info['nparams']
nparams_array = info['nparams_array']
time_epoch_array = info['time_epoch_array']
time_array = info['time_array']
mse_array = info['mse_array']
total_time = time.time() - tic
os.makedirs('results', exist_ok=True)
mdict = {'mse_array': mse_array,
'time_array': time_array-time_array[0],
'total_time': total_time,
'mse_epoch_array': info['mse_epoch_array'],
'mem_array': info['mem_array'],
'time_epoch_array': time_epoch_array,
'nparams_array': nparams_array,
'nparams': nparams,
'nparams_array': info['nparams_array']}
learn_indices = info['learn_indices_list']
for idx in range(nscales):
mdict['learn_indices%d'%idx] = learn_indices[idx].numpy()
mdict['cubesize'] = np.array([H, W, T])
mdict['ksize'] = config.ksize
io.savemat('results/%s_miner.mat'%expname, mdict)
volutils.march_and_save(best_im, config.mcubes_thres,
'results/%s_miner_volume.dae'%expname,
True)
print('Total time %.2f minutes'%(total_time/60))
print('IoU: ', volutils.get_IoU(best_im, im, config.mcubes_thres))
print('Total pararmeters: %.2f million'%(nparams/1e6))
plt.loglog(time_array-time_array[0], mse_array)
plt.xlabel('Time (s)')
plt.ylabel('MSE')
plt.grid()
plt.show()