kcml commited on
Commit
d425c00
·
1 Parent(s): b601e2b

ADE category statistics

Browse files
Files changed (1) hide show
  1. handcrafted_solution.py +24 -2
handcrafted_solution.py CHANGED
@@ -121,6 +121,23 @@ def get_uv_depth(vertices, depth):
121
  vertex_depth = depth[(uv_int[:, 1] , uv_int[:, 0])]
122
  return uv, vertex_depth
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  def merge_vertices_3d(vert_edge_per_image, th=0.1):
126
  '''Merge vertices that are close to each other in 3D space and are of same types'''
@@ -202,12 +219,15 @@ def prune_not_connected(all_3d_vertices, connections_3d):
202
  def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
203
  good_entry = convert_entry_to_human_readable(entry)
204
  vert_edge_per_image = {}
205
- for i, (gest, depth, K, R, t) in enumerate(zip(good_entry['gestalt'],
 
206
  good_entry['depthcm'],
207
  good_entry['K'],
208
  good_entry['R'],
209
  good_entry['t']
210
  )):
 
 
211
  gest_seg = gest.resize(depth.size)
212
  gest_seg_np = np.array(gest_seg).astype(np.uint8)
213
  # Metric3D
@@ -217,7 +237,8 @@ def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
217
  print (f'Not enough vertices or connections in image {i}')
218
  vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
219
  continue
220
- uv, depth_vert = get_uv_depth(vertices, depth_np)
 
221
  # Normalize the uv to the camera intrinsics
222
  xy_local = np.ones((len(uv), 3))
223
  xy_local[:, 0] = (uv[:, 0] - K[0,2]) / K[0,0]
@@ -237,6 +258,7 @@ def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
237
  print (f'Not enough vertices or connections in the 3D vertices')
238
  return (good_entry['__key__'], *empty_solution())
239
  if visualize:
 
240
  from hoho.viz3d import plot_estimate_and_gt
241
  plot_estimate_and_gt( all_3d_vertices_clean,
242
  connections_3d_clean,
 
121
  vertex_depth = depth[(uv_int[:, 1] , uv_int[:, 0])]
122
  return uv, vertex_depth
123
 
124
+ def get_uv_dept_category(vertices, depth, ade_seg):
125
+ '''Get the depth of the vertices from the depth image'''
126
+ uv = []
127
+ for v in vertices:
128
+ uv.append(v['xy'])
129
+ uv = np.array(uv)
130
+ uv_int = uv.astype(np.int32)
131
+ H, W = depth.shape[:2]
132
+ uv_int[:, 0] = np.clip( uv_int[:, 0], 0, W-1)
133
+ uv_int[:, 1] = np.clip( uv_int[:, 1], 0, H-1)
134
+ vertex_depth = depth[(uv_int[:, 1] , uv_int[:, 0])]
135
+ vertex_category = ade_seg[(uv_int[:, 1] , uv_int[:, 0])]
136
+ taget_color = [[120,120,120], [180, 120, 120], [255,9,224]]
137
+ filter_ind = [i for i, ele in enumerate(vertex_category) if ele in taget_color]
138
+ print(f'retain {len(filter_ind)} idx')
139
+ print(vertex_category[filter_ind])
140
+ return uv[filter_ind], vertex_depth[filter_ind], vertex_category[filter_ind]
141
 
142
  def merge_vertices_3d(vert_edge_per_image, th=0.1):
143
  '''Merge vertices that are close to each other in 3D space and are of same types'''
 
219
  def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
220
  good_entry = convert_entry_to_human_readable(entry)
221
  vert_edge_per_image = {}
222
+ for i, (ade, gest, depth, K, R, t) in enumerate(zip(good_entry['ade20k'],
223
+ good_entry['gestalt'],
224
  good_entry['depthcm'],
225
  good_entry['K'],
226
  good_entry['R'],
227
  good_entry['t']
228
  )):
229
+ ade_seg = ade.resize(depth.size)
230
+ ade_seg_np = np.array(ade_seg).astype(np.uint8)
231
  gest_seg = gest.resize(depth.size)
232
  gest_seg_np = np.array(gest_seg).astype(np.uint8)
233
  # Metric3D
 
237
  print (f'Not enough vertices or connections in image {i}')
238
  vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
239
  continue
240
+ #uv, depth_vert = get_uv_depth(vertices, depth_np)
241
+ uv, depth_vert, ade_category_vert = get_uv_dept_category(vertices, depth_np, ade_seg_np)
242
  # Normalize the uv to the camera intrinsics
243
  xy_local = np.ones((len(uv), 3))
244
  xy_local[:, 0] = (uv[:, 0] - K[0,2]) / K[0,0]
 
258
  print (f'Not enough vertices or connections in the 3D vertices')
259
  return (good_entry['__key__'], *empty_solution())
260
  if visualize:
261
+ print(f"num of est: {len(all_3d_vertices_clean)}, num of gt:{len(good_entry['wf_vertices'])}")
262
  from hoho.viz3d import plot_estimate_and_gt
263
  plot_estimate_and_gt( all_3d_vertices_clean,
264
  connections_3d_clean,