s194649 commited on
Commit
6eb6376
·
1 Parent(s): 9f0c4b3

default value and mask reconstruction

Browse files
Files changed (2) hide show
  1. app.py +23 -4
  2. inference.py +4 -4
app.py CHANGED
@@ -74,16 +74,16 @@ with block:
74
  )
75
  with gr.Row():
76
  max_depth = gr.Slider(
77
- minimum=0, maximum=10, step=0.01, default=1, label="Max Depth"
78
  )
79
  min_depth = gr.Slider(
80
- minimum=0, maximum=10, step=0.01, default=0.1, label="Min Depth"
81
  )
82
  n_samples = gr.Slider(
83
  minimum=1e3,
84
  maximum=1e6,
85
  step=1e3,
86
- default=1e3,
87
  label="Number of Samples",
88
  )
89
  cube_size = gr.Slider(
@@ -94,7 +94,10 @@ with block:
94
  label="Cube size",
95
  )
96
  depth_reconstruction_btn = gr.Button(
97
- "Depth Reconstruction", variant="primary"
 
 
 
98
  )
99
 
100
  sam_decode_btn = gr.Button("Predict using points!", variant="primary")
@@ -269,6 +272,22 @@ with block:
269
  on_depth_reconstruction_btn_click, components, [pcl_figure], queue=False
270
  )
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  def on_sam_sgmt_everything_btn_click(inputs):
273
  print("segmenting everything")
274
  image = inputs[input_image]
 
74
  )
75
  with gr.Row():
76
  max_depth = gr.Slider(
77
+ minimum=0, maximum=10, value=3, step=0.01, label="Max Depth"
78
  )
79
  min_depth = gr.Slider(
80
+ minimum=0, maximum=10, step=0.01, value=1, label="Min Depth"
81
  )
82
  n_samples = gr.Slider(
83
  minimum=1e3,
84
  maximum=1e6,
85
  step=1e3,
86
+ value=1e5,
87
  label="Number of Samples",
88
  )
89
  cube_size = gr.Slider(
 
94
  label="Cube size",
95
  )
96
  depth_reconstruction_btn = gr.Button(
97
+ "3D Reconstruction", variant="primary"
98
+ )
99
+ depth_reconstruction_mask_btn = gr.Button(
100
+ "Mask Reconstruction", variant="primary"
101
  )
102
 
103
  sam_decode_btn = gr.Button("Predict using points!", variant="primary")
 
272
  on_depth_reconstruction_btn_click, components, [pcl_figure], queue=False
273
  )
274
 
275
+ def on_depth_reconstruction_mask_btn_click(inputs):
276
+ print("depth reconstruction")
277
+ path = dpt.generate_obj_masks(
278
+ image=inputs[input_image],
279
+ cube_size=inputs[cube_size],
280
+ n_samples=inputs[n_samples],
281
+ masks=inputs[masks],
282
+ min_depth=inputs[min_depth],
283
+ max_depth=inputs[max_depth],
284
+ )
285
+ return {pcl_figure: path}
286
+
287
+ depth_reconstruction_mask_btn.click(
288
+ on_depth_reconstruction_mask_btn_click, components, [pcl_figure], queue=False
289
+ )
290
+
291
  def on_sam_sgmt_everything_btn_click(inputs):
292
  print("segmenting everything")
293
  image = inputs[input_image]
inference.py CHANGED
@@ -229,16 +229,16 @@ class DepthPredictor:
229
  ):
230
  # Generate a point cloud
231
  depth = self.predict(image)
232
- # depth = map_image_range(depth, min_depth, max_depth)
233
  image = np.array(image)
234
  mesh = o3d.geometry.TriangleMesh()
235
  # Create cubes and add them to the mesh
236
  print(len(masks))
237
- cs = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]
238
  for c, (mask, _) in zip(cs, masks):
239
  points, _ = PCL(mask, depth)
240
- # idxs = np.random.choice(len(points), int(n_samples))
241
- # points = points[idxs]
242
  for point in points:
243
  cube = o3d.geometry.TriangleMesh.create_box(
244
  width=cube_size, height=cube_size, depth=cube_size
 
229
  ):
230
  # Generate a point cloud
231
  depth = self.predict(image)
232
+ depth = map_image_range(depth, min_depth, max_depth)
233
  image = np.array(image)
234
  mesh = o3d.geometry.TriangleMesh()
235
  # Create cubes and add them to the mesh
236
  print(len(masks))
237
+ cs = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
238
  for c, (mask, _) in zip(cs, masks):
239
  points, _ = PCL(mask, depth)
240
+ idxs = np.random.choice(len(points), int(n_samples))
241
+ points = points[idxs]
242
  for point in points:
243
  cube = o3d.geometry.TriangleMesh.create_box(
244
  width=cube_size, height=cube_size, depth=cube_size