Update my_solution.py
Browse files- my_solution.py +18 -14
my_solution.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
# Description: This file contains the handcrafted solution for the task of wireframe reconstruction
|
| 2 |
-
|
| 3 |
import io
|
| 4 |
from PIL import Image as PImage
|
| 5 |
import numpy as np
|
|
@@ -11,8 +9,8 @@ from scipy.spatial.distance import cdist
|
|
| 11 |
from hoho.read_write_colmap import read_cameras_binary, read_images_binary, read_points3D_binary
|
| 12 |
from hoho.color_mappings import gestalt_color_mapping, ade20k_color_mapping
|
| 13 |
|
| 14 |
-
from
|
| 15 |
-
|
| 16 |
|
| 17 |
def convert_entry_to_human_readable(entry):
|
| 18 |
out = {}
|
|
@@ -35,25 +33,31 @@ def convert_entry_to_human_readable(entry):
|
|
| 35 |
|
| 36 |
|
| 37 |
def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
|
| 38 |
-
return entry['__key__'],
|
|
|
|
| 39 |
try:
|
| 40 |
solver = GeomSolver(entry)
|
| 41 |
vertices, edges = solver.get_vertices()
|
| 42 |
except:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
vertices =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
if (len(edges) < 1) and (len(vertices) >= 2):
|
| 51 |
# print("Added only edges")
|
| 52 |
-
|
| 53 |
|
| 54 |
if (len(vertices) < 2) or (len(edges) < 1):
|
| 55 |
# print("Added empty solution")
|
| 56 |
-
vertices, edges =
|
| 57 |
|
| 58 |
if visualize:
|
| 59 |
from hoho.viz3d import plot_estimate_and_gt
|
|
@@ -62,5 +66,5 @@ def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
|
|
| 62 |
entry['wf_vertices'],
|
| 63 |
entry['wf_edges'])
|
| 64 |
if vertices.shape[-1] != 3:
|
| 65 |
-
vertices, edges =
|
| 66 |
return entry['__key__'], vertices, edges
|
|
|
|
|
|
|
|
|
|
| 1 |
import io
|
| 2 |
from PIL import Image as PImage
|
| 3 |
import numpy as np
|
|
|
|
| 9 |
from hoho.read_write_colmap import read_cameras_binary, read_images_binary, read_points3D_binary
|
| 10 |
from hoho.color_mappings import gestalt_color_mapping, ade20k_color_mapping
|
| 11 |
|
| 12 |
+
from geom_solver import GeomSolver, my_empty_solution
|
| 13 |
+
|
| 14 |
|
| 15 |
def convert_entry_to_human_readable(entry):
|
| 16 |
out = {}
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
|
| 36 |
+
# return (entry['__key__'], *my_empty_solution())
|
| 37 |
+
vertices0, edges0 = my_empty_solution()
|
| 38 |
try:
|
| 39 |
solver = GeomSolver(entry)
|
| 40 |
vertices, edges = solver.get_vertices()
|
| 41 |
except:
|
| 42 |
+
vertices, edges = vertices0, edges0
|
| 43 |
+
|
| 44 |
+
if vertices.shape[0] < vertices0.shape[0]:
|
| 45 |
+
verts_new = vertices0
|
| 46 |
+
verts_new[:vertices.shape[0]] = vertices
|
| 47 |
+
vertices = verts_new
|
| 48 |
+
|
| 49 |
+
# if len(vertices) == 1:
|
| 50 |
+
# # print("Added one more vertex")
|
| 51 |
+
# vertices = np.concatenate((vertices, np.zeros((1,3))))
|
| 52 |
+
# edges = [(0,0)]
|
| 53 |
|
| 54 |
if (len(edges) < 1) and (len(vertices) >= 2):
|
| 55 |
# print("Added only edges")
|
| 56 |
+
edges = edges0
|
| 57 |
|
| 58 |
if (len(vertices) < 2) or (len(edges) < 1):
|
| 59 |
# print("Added empty solution")
|
| 60 |
+
vertices, edges = vertices0, edges0
|
| 61 |
|
| 62 |
if visualize:
|
| 63 |
from hoho.viz3d import plot_estimate_and_gt
|
|
|
|
| 66 |
entry['wf_vertices'],
|
| 67 |
entry['wf_edges'])
|
| 68 |
if vertices.shape[-1] != 3:
|
| 69 |
+
vertices, edges = vertices0, edges0
|
| 70 |
return entry['__key__'], vertices, edges
|