Denys Rozumnyi commited on
Commit
51d388e
2 Parent(s): 3313152 c5e4aa9
Files changed (3) hide show
  1. .gitignore +5 -0
  2. geom_solver.py +14 -4
  3. my_solution.py +17 -13
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ __pycache__*
2
+ .ipynb_checkpoints/*
3
+ EDA.ipynb
4
+ data/*
5
+ notebooks/*
geom_solver.py CHANGED
@@ -8,6 +8,18 @@ import torch
8
  from pytorch3d.renderer import PerspectiveCameras
9
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  class GeomSolver(object):
12
 
13
  def __init__(self, entry):
@@ -110,11 +122,9 @@ class GeomSolver(object):
110
  def get_vertices(self, visualize=False):
111
  if visualize:
112
  from hoho.viz3d import plot_estimate_and_gt
113
- plot_estimate_and_gt(self.vertices, [(0,1)], self.human_entry['wf_vertices'], self.human_entry['wf_edges'])
114
  if self.vertices.shape[0] == 0:
115
  return my_empty_solution()
116
- return self.vertices, [(0, len(self.vertices)-1)]
117
-
118
-
119
 
120
 
 
8
  from pytorch3d.renderer import PerspectiveCameras
9
 
10
 
11
+ def my_empty_solution():
12
+ '''Return a minimal valid solution, i.e. 2 vertices and 1 edge.'''
13
+ # return np.zeros((1,3)), [(0, 0)]
14
+ return np.zeros((18,3)), [(0, 1)]
15
+
16
+
17
+ def mean_solution(pcloud):
18
+ mean_point = pcloud.mean(axis=0)
19
+ verts = mean_point.repeat(0, 2)
20
+ return verts, [(0, 0)]
21
+
22
+
23
  class GeomSolver(object):
24
 
25
  def __init__(self, entry):
 
122
  def get_vertices(self, visualize=False):
123
  if visualize:
124
  from hoho.viz3d import plot_estimate_and_gt
125
+ plot_estimate_and_gt(self.vertices, [(0,0)], self.human_entry['wf_vertices'], self.human_entry['wf_edges'])
126
  if self.vertices.shape[0] == 0:
127
  return my_empty_solution()
128
+ return self.vertices, [(0, 0)]
 
 
129
 
130
 
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 helpers import my_empty_solution
15
- from geom_solver import GeomSolver
16
 
17
  def convert_entry_to_human_readable(entry):
18
  out = {}
@@ -36,24 +34,30 @@ def convert_entry_to_human_readable(entry):
36
 
37
  def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
38
  # return (entry['__key__'], *my_empty_solution())
 
39
  try:
40
  solver = GeomSolver(entry)
41
  vertices, edges = solver.get_vertices()
42
  except:
43
- # print("Error")
44
- vertices, edges = my_empty_solution()
45
-
46
- if len(vertices) == 1:
47
- # print("Added one more vertex")
48
- vertices = np.concatenate((vertices, np.zeros((1,3))))
 
 
 
 
 
49
 
50
  if (len(edges) < 1) and (len(vertices) >= 2):
51
  # print("Added only edges")
52
- _, edges = my_empty_solution()
53
 
54
  if (len(vertices) < 2) or (len(edges) < 1):
55
  # print("Added empty solution")
56
- vertices, edges = my_empty_solution()
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 = my_empty_solution()
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 = {}
 
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