-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeanAccComplet.py
More file actions
106 lines (81 loc) · 3.03 KB
/
meanAccComplet.py
File metadata and controls
106 lines (81 loc) · 3.03 KB
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
import os
import open3d as o3d
import numpy as np
import faiss
import glob
import numpy as np
import os
import glob
import open3d as o3d
from scipy.ndimage.measurements import label
import open3d as o3d
import cc3d
import numpy as np
import pandas as pd
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from scipy.spatial.ckdtree import cKDTree
from mpl_toolkits.mplot3d import Axes3D
import os
import sys
def computeAcc(componPoints_noGT , componPoints):
d = componPoints.shape[1]
res = faiss.StandardGpuResources()
index_flat = faiss.IndexFlatL2(d) # use a single GPU
gpu_index_flat = faiss.index_cpu_to_gpu(res, 0, index_flat)
# build a flat (CPU) index
gpu_index_flat.add(componPoints.astype(np.float32)) # add vectors to the index
k = 1
D, I = gpu_index_flat.search(componPoints_noGT.astype(np.float32), k) # actual search
count = np.where(D<0.0001)
accuracy = np.shape(count)[1] / np.shape(componPoints_noGT)[0]
complet = np.shape(count)[1] / np.shape(componPoints)[0]
return accuracy, complet
def computeMetrics(pathR, acc, comp, countObj):
localCount = 0
os.chdir( pathS + '/gtCom/')
fGt = len(glob.glob("*.npy"))
gtObjectsDetect = np.zeros((fGt,3))
files = glob.glob("*.npy")
for j in range(1,fGt):
countF = 0
maxAccu = 0
maxComplet = 0
maxMesosOros = 0
componPoints = np.loadtxt(pathS +'/gtCom/'+ str(j) + '.xyz')
localCount = 0
if np.shape(componPoints)[0] > 1000:
localCount = localCount + 1
countObj = countObj + 1
for filename in os.listdir(+pathS +'/computedConnected/'):
if filename!='0comp.xyz':
componPoints_noGT = np.loadtxt(pathS +'/computedConnected/'+filename)
if np.shape(componPoints_noGT)[0]>500:
accuracy, completeness = computeAcc(componPoints_noGT , componPoints)
if completeness > 1:
completeness = 1
if accuracy>1:
accuracy = 1
if (completeness > maxComplet):
maxMesosOros = accuracy+completeness
maxAccu = accuracy
maxComplet = completeness
else:
countF = countF + 1
acc = np.vstack((acc,maxAccu))
comp = np.vstack((comp,maxComplet))
return acc, comp, countObj
if __name__ == '__main__':
file1 = open('validation-only-rescan.txt')
Lines = file1.readlines()
allObjectsDi = 0
allObjectsG = 0
allPercentPerScan = np.zeros((110))
acc = np.array([1])
comp = np.array([1])
countObj=0
for i in range(0, len(Lines)):
pathS = sys.path[0]+ '/' + Lines[i][:len(Lines[i])-1]
print ("Metrics for ", pathS," are computed" )
acc, comp, countObj = computeMetrics(pathS, acc, comp, countObj)