Denys Rozumnyi
commited on
Commit
·
8681fd1
1
Parent(s):
fae3cfc
update
Browse files- geom_solver.py +18 -8
- testing.ipynb +0 -0
geom_solver.py
CHANGED
|
@@ -16,11 +16,11 @@ def my_empty_solution():
|
|
| 16 |
class GeomSolver(object):
|
| 17 |
|
| 18 |
def __init__(self):
|
| 19 |
-
self.min_vertices =
|
| 20 |
-
self.mean_vertices = 18
|
| 21 |
-
self.max_vertices =
|
| 22 |
-
self.kmeans_th =
|
| 23 |
-
self.point_dist_th =
|
| 24 |
self.th_min_support = 3
|
| 25 |
self.clr_th = 2.5
|
| 26 |
self.device = 'cuda:0'
|
|
@@ -72,11 +72,14 @@ class GeomSolver(object):
|
|
| 72 |
|
| 73 |
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, 0.3)
|
| 74 |
flags = cv2.KMEANS_RANDOM_CENTERS
|
|
|
|
| 75 |
centers = np.zeros((0, 3))
|
| 76 |
assigned_points = []
|
| 77 |
if len(self.xyz[selected_points][dense_pnts]) == 0:
|
| 78 |
return centers, assigned_points
|
| 79 |
-
|
|
|
|
|
|
|
| 80 |
retval, temp_bestLabels, temp_centers = cv2.kmeans(self.xyz[selected_points][dense_pnts].astype(np.float32), tempi, None, criteria, 200,flags)
|
| 81 |
cpnts = torch.from_numpy(temp_centers.astype(np.float32))[None]
|
| 82 |
bdists, inds, nn = ball_query(cpnts, cpnts, K=2, radius=1.2*self.kmeans_th)
|
|
@@ -90,7 +93,6 @@ class GeomSolver(object):
|
|
| 90 |
if centers.shape[0] == 0:
|
| 91 |
centers, bestLabels = temp_centers, temp_bestLabels
|
| 92 |
|
| 93 |
-
point_inds = np.arange(self.xyz.shape[0])
|
| 94 |
centers_selected = []
|
| 95 |
for ci in range(centers.shape[0]):
|
| 96 |
assigned_inds = point_inds[selected_points][dense_pnts][bestLabels[:,0] == ci]
|
|
@@ -98,6 +100,12 @@ class GeomSolver(object):
|
|
| 98 |
continue
|
| 99 |
centers_selected.append(centers[ci])
|
| 100 |
assigned_points.append(assigned_inds)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
centers_selected = np.stack(centers_selected)
|
| 102 |
return centers_selected, assigned_points
|
| 103 |
|
|
@@ -143,7 +151,8 @@ class GeomSolver(object):
|
|
| 143 |
self.vertices = centers
|
| 144 |
nvert = centers.shape[0]
|
| 145 |
# desired_vertices = (self.xyz[:,-1] > z_th).sum() // 300
|
| 146 |
-
desired_vertices = 2*nvert
|
|
|
|
| 147 |
if desired_vertices < self.min_vertices:
|
| 148 |
desired_vertices = self.mean_vertices
|
| 149 |
if desired_vertices > self.max_vertices:
|
|
@@ -206,6 +215,7 @@ class GeomSolver(object):
|
|
| 206 |
|
| 207 |
edges = []
|
| 208 |
thresholds_min_mean = {0 : [5, 7], 1 : [9, 25], 2: [30, 1000]}
|
|
|
|
| 209 |
for i in range(pyt_centers.shape[0]):
|
| 210 |
for j in range(i+1, pyt_centers.shape[0]):
|
| 211 |
etype = (self.is_apex[i] + self.is_apex[j])
|
|
|
|
| 16 |
class GeomSolver(object):
|
| 17 |
|
| 18 |
def __init__(self):
|
| 19 |
+
self.min_vertices = 10
|
| 20 |
+
self.mean_vertices = 18
|
| 21 |
+
self.max_vertices = 30
|
| 22 |
+
self.kmeans_th = 200
|
| 23 |
+
self.point_dist_th = 50
|
| 24 |
self.th_min_support = 3
|
| 25 |
self.clr_th = 2.5
|
| 26 |
self.device = 'cuda:0'
|
|
|
|
| 72 |
|
| 73 |
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, 0.3)
|
| 74 |
flags = cv2.KMEANS_RANDOM_CENTERS
|
| 75 |
+
point_inds = np.arange(self.xyz.shape[0])
|
| 76 |
centers = np.zeros((0, 3))
|
| 77 |
assigned_points = []
|
| 78 |
if len(self.xyz[selected_points][dense_pnts]) == 0:
|
| 79 |
return centers, assigned_points
|
| 80 |
+
if len(self.xyz[selected_points][dense_pnts]) == 1:
|
| 81 |
+
return self.xyz[selected_points][dense_pnts], [point_inds[selected_points][dense_pnts]]
|
| 82 |
+
for tempi in range(1, 30):
|
| 83 |
retval, temp_bestLabels, temp_centers = cv2.kmeans(self.xyz[selected_points][dense_pnts].astype(np.float32), tempi, None, criteria, 200,flags)
|
| 84 |
cpnts = torch.from_numpy(temp_centers.astype(np.float32))[None]
|
| 85 |
bdists, inds, nn = ball_query(cpnts, cpnts, K=2, radius=1.2*self.kmeans_th)
|
|
|
|
| 93 |
if centers.shape[0] == 0:
|
| 94 |
centers, bestLabels = temp_centers, temp_bestLabels
|
| 95 |
|
|
|
|
| 96 |
centers_selected = []
|
| 97 |
for ci in range(centers.shape[0]):
|
| 98 |
assigned_inds = point_inds[selected_points][dense_pnts][bestLabels[:,0] == ci]
|
|
|
|
| 100 |
continue
|
| 101 |
centers_selected.append(centers[ci])
|
| 102 |
assigned_points.append(assigned_inds)
|
| 103 |
+
if len(centers_selected) == 0:
|
| 104 |
+
print("Not centers with enough support!")
|
| 105 |
+
for ci in range(centers.shape[0]):
|
| 106 |
+
assigned_inds = point_inds[selected_points][dense_pnts][bestLabels[:,0] == ci]
|
| 107 |
+
assigned_points.append(assigned_inds)
|
| 108 |
+
return centers, assigned_points
|
| 109 |
centers_selected = np.stack(centers_selected)
|
| 110 |
return centers_selected, assigned_points
|
| 111 |
|
|
|
|
| 151 |
self.vertices = centers
|
| 152 |
nvert = centers.shape[0]
|
| 153 |
# desired_vertices = (self.xyz[:,-1] > z_th).sum() // 300
|
| 154 |
+
desired_vertices = 2*nvert
|
| 155 |
+
# desired_vertices = self.mean_vertices
|
| 156 |
if desired_vertices < self.min_vertices:
|
| 157 |
desired_vertices = self.mean_vertices
|
| 158 |
if desired_vertices > self.max_vertices:
|
|
|
|
| 215 |
|
| 216 |
edges = []
|
| 217 |
thresholds_min_mean = {0 : [5, 7], 1 : [9, 25], 2: [30, 1000]}
|
| 218 |
+
# thresholds_min_mean = {0 : [1, 7], 1 : [1, 25], 2: [1, 1000]}
|
| 219 |
for i in range(pyt_centers.shape[0]):
|
| 220 |
for j in range(i+1, pyt_centers.shape[0]):
|
| 221 |
etype = (self.is_apex[i] + self.is_apex[j])
|
testing.ipynb
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|