empty conn; clean_pcd using OPTICS, excl noise with a bit optimization; 10 cores
Browse files- handcrafted_solution.py +9 -32
- script.py +1 -1
handcrafted_solution.py
CHANGED
@@ -486,6 +486,7 @@ def get_vertices_and_edges_from_two_segmentations(ade_seg_np, gest_seg_np, edge_
|
|
486 |
|
487 |
connections, line_img = Ridge_connects_two_apex_points(gest_seg_np, color_th, apex_pts, edge_th)
|
488 |
'''
|
|
|
489 |
def classifyPairs(apex_pts, apex_pts_idxs, gest_seg_np, apex_mask, eave_end_mask):
|
490 |
conn = []
|
491 |
# Plot all possible connection pixels in one mask
|
@@ -538,36 +539,10 @@ def get_vertices_and_edges_from_two_segmentations(ade_seg_np, gest_seg_np, edge_
|
|
538 |
filename_edges_map = f'edges_map_{rid}.jpg'
|
539 |
if 'line_img' in locals():
|
540 |
cv2.imwrite(filename_edges_map, line_img)
|
541 |
-
|
542 |
-
|
543 |
return vertices, connections
|
544 |
|
545 |
-
def get_uv_dept_category(vertices, depth, ade_seg):
|
546 |
-
'''Get the depth of the vertices from the depth image'''
|
547 |
-
uv = []
|
548 |
-
for v in vertices:
|
549 |
-
uv.append(v['xy'])
|
550 |
-
uv = np.array(uv)
|
551 |
-
uv_int = uv.astype(np.int32)
|
552 |
-
H, W = depth.shape[:2]
|
553 |
-
uv_int[:, 0] = np.clip( uv_int[:, 0], 0, W-1)
|
554 |
-
uv_int[:, 1] = np.clip( uv_int[:, 1], 0, H-1)
|
555 |
-
vertex_depth = depth[(uv_int[:, 1] , uv_int[:, 0])]
|
556 |
-
vertex_category = ade_seg[(uv_int[:, 1] , uv_int[:, 0])]
|
557 |
-
target_color = set([(120,120,120), (180, 120, 120), (255,9,224)])
|
558 |
-
#filter_ind = [i for i, ele in enumerate(vertex_category) if tuple(ele) in target_color]
|
559 |
-
filter_ind = []
|
560 |
-
for i, ele in enumerate(vertex_category):
|
561 |
-
if tuple(ele) in target_color:
|
562 |
-
filter_ind.append(i)
|
563 |
-
|
564 |
-
print(f'retain {len(filter_ind)} idx')
|
565 |
-
print(vertex_category[filter_ind])
|
566 |
-
#print(vertices)
|
567 |
-
#print(filter_ind)
|
568 |
-
vertices = [vertices[i] for i in filter_ind]
|
569 |
-
return uv[filter_ind], vertex_depth[filter_ind], vertex_category[filter_ind], vertices
|
570 |
-
|
571 |
def merge_vertices_3d(vert_edge_per_image, th=0.1):
|
572 |
'''Merge vertices that are close to each other in 3D space and are of same types'''
|
573 |
all_3d_vertices = []
|
@@ -800,7 +775,7 @@ def clean_PCD(XYZ, rgb):
|
|
800 |
largest_blob = k
|
801 |
|
802 |
for k in unique_labels:
|
803 |
-
|
804 |
'''
|
805 |
if k == -1:
|
806 |
retain_class_mask = retain_class_mask | class_member_mask
|
@@ -814,9 +789,10 @@ def clean_PCD(XYZ, rgb):
|
|
814 |
retain_class_mask = retain_class_mask | class_member_mask
|
815 |
'''
|
816 |
if k == largest_blob:
|
|
|
817 |
retain_class_mask = retain_class_mask | class_member_mask
|
818 |
-
pt_k = XYZ[class_member_mask]
|
819 |
-
lowest_z = min(pt_k[:,2])
|
820 |
break
|
821 |
|
822 |
XYZ = XYZ[retain_class_mask]
|
@@ -895,9 +871,10 @@ def predict(entry, visualize=False, prune_dist_thr=600, depth_scale=2.5, ) -> Tu
|
|
895 |
#all_3d_vertices_clean, connections_3d_clean = prune_not_connected(all_3d_vertices, connections_3d)
|
896 |
#all_3d_vertices, connections_3d = prune_tall_short(all_3d_vertices, connections_3d, lowest_z, 1000, 0)
|
897 |
|
898 |
-
|
899 |
if len(all_3d_vertices)>35:
|
900 |
all_3d_vertices, connections_3d = prune_not_connected(all_3d_vertices, connections_3d)
|
|
|
901 |
if len(all_3d_vertices)>10:
|
902 |
all_3d_vertices_clean, connections_3d_clean = prune_far(all_3d_vertices, connections_3d, prune_dist_thr=prune_dist_thr)
|
903 |
else:
|
|
|
486 |
|
487 |
connections, line_img = Ridge_connects_two_apex_points(gest_seg_np, color_th, apex_pts, edge_th)
|
488 |
'''
|
489 |
+
'''
|
490 |
def classifyPairs(apex_pts, apex_pts_idxs, gest_seg_np, apex_mask, eave_end_mask):
|
491 |
conn = []
|
492 |
# Plot all possible connection pixels in one mask
|
|
|
539 |
filename_edges_map = f'edges_map_{rid}.jpg'
|
540 |
if 'line_img' in locals():
|
541 |
cv2.imwrite(filename_edges_map, line_img)
|
542 |
+
'''
|
543 |
+
connections = []
|
544 |
return vertices, connections
|
545 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
546 |
def merge_vertices_3d(vert_edge_per_image, th=0.1):
|
547 |
'''Merge vertices that are close to each other in 3D space and are of same types'''
|
548 |
all_3d_vertices = []
|
|
|
775 |
largest_blob = k
|
776 |
|
777 |
for k in unique_labels:
|
778 |
+
|
779 |
'''
|
780 |
if k == -1:
|
781 |
retain_class_mask = retain_class_mask | class_member_mask
|
|
|
789 |
retain_class_mask = retain_class_mask | class_member_mask
|
790 |
'''
|
791 |
if k == largest_blob:
|
792 |
+
class_member_mask = labels == k
|
793 |
retain_class_mask = retain_class_mask | class_member_mask
|
794 |
+
#pt_k = XYZ[class_member_mask]
|
795 |
+
#lowest_z = min(pt_k[:,2])
|
796 |
break
|
797 |
|
798 |
XYZ = XYZ[retain_class_mask]
|
|
|
871 |
#all_3d_vertices_clean, connections_3d_clean = prune_not_connected(all_3d_vertices, connections_3d)
|
872 |
#all_3d_vertices, connections_3d = prune_tall_short(all_3d_vertices, connections_3d, lowest_z, 1000, 0)
|
873 |
|
874 |
+
'''
|
875 |
if len(all_3d_vertices)>35:
|
876 |
all_3d_vertices, connections_3d = prune_not_connected(all_3d_vertices, connections_3d)
|
877 |
+
'''
|
878 |
if len(all_3d_vertices)>10:
|
879 |
all_3d_vertices_clean, connections_3d_clean = prune_far(all_3d_vertices, connections_3d, prune_dist_thr=prune_dist_thr)
|
880 |
else:
|
script.py
CHANGED
@@ -146,7 +146,7 @@ if __name__ == "__main__":
|
|
146 |
print('------------ Now you can do your solution ---------------')
|
147 |
solution = []
|
148 |
from concurrent.futures import ProcessPoolExecutor
|
149 |
-
with ProcessPoolExecutor(max_workers=
|
150 |
results = []
|
151 |
for i, sample in enumerate(tqdm(dataset)):
|
152 |
results.append(pool.submit(predict, sample, visualize=False))
|
|
|
146 |
print('------------ Now you can do your solution ---------------')
|
147 |
solution = []
|
148 |
from concurrent.futures import ProcessPoolExecutor
|
149 |
+
with ProcessPoolExecutor(max_workers=10) as pool:
|
150 |
results = []
|
151 |
for i, sample in enumerate(tqdm(dataset)):
|
152 |
results.append(pool.submit(predict, sample, visualize=False))
|