Spaces:
Runtime error
Runtime error
jens
commited on
Commit
·
2911be1
1
Parent(s):
38b2f3b
fix
Browse files- app.py +4 -3
- inference.py +2 -2
app.py
CHANGED
|
@@ -35,8 +35,9 @@ with block:
|
|
| 35 |
input_image = gr.Image(label='Input', height=512, type='pil')
|
| 36 |
masks_annotated_image = gr.AnnotatedImage(label='Segments', height=512)
|
| 37 |
pcl_figure = gr.Model3D(label="3-D Reconstruction", clear_color=[1.0, 1.0, 1.0, 1.0])
|
|
|
|
| 38 |
#gr.Plot(label='3D Reconstruction')
|
| 39 |
-
#cutout_galary = gr.Gallery(label='Cutouts', object_fit='contain', height=512)
|
| 40 |
with gr.Row():
|
| 41 |
with gr.Column(scale=1):
|
| 42 |
with gr.Row():
|
|
@@ -49,12 +50,12 @@ with block:
|
|
| 49 |
# components
|
| 50 |
components = {point_coords, point_labels, raw_image, masks, cutout_idx, input_image,
|
| 51 |
point_label_radio, text, reset_btn, sam_sgmt_everything_btn,
|
| 52 |
-
sam_decode_btn, depth_reconstruction_btn, masks_annotated_image}
|
| 53 |
def on_depth_reconstruction_btn_click(inputs):
|
| 54 |
print("depth reconstruction")
|
| 55 |
image = inputs[raw_image]
|
| 56 |
# depth reconstruction
|
| 57 |
-
path = dpt.generate_obj(image)
|
| 58 |
return {pcl_figure: path}
|
| 59 |
|
| 60 |
depth_reconstruction_btn.click(on_depth_reconstruction_btn_click, components, [pcl_figure], queue=False)
|
|
|
|
| 35 |
input_image = gr.Image(label='Input', height=512, type='pil')
|
| 36 |
masks_annotated_image = gr.AnnotatedImage(label='Segments', height=512)
|
| 37 |
pcl_figure = gr.Model3D(label="3-D Reconstruction", clear_color=[1.0, 1.0, 1.0, 1.0])
|
| 38 |
+
n_samples = gr.Slider(minimum=1e3, maximum=1e6, step=1e3, default=1e3, label='Number of Samples')
|
| 39 |
#gr.Plot(label='3D Reconstruction')
|
| 40 |
+
#cutout_galary = gr.Gallery(label='Cutouts', object_fit='contain', height=512)
|
| 41 |
with gr.Row():
|
| 42 |
with gr.Column(scale=1):
|
| 43 |
with gr.Row():
|
|
|
|
| 50 |
# components
|
| 51 |
components = {point_coords, point_labels, raw_image, masks, cutout_idx, input_image,
|
| 52 |
point_label_radio, text, reset_btn, sam_sgmt_everything_btn,
|
| 53 |
+
sam_decode_btn, depth_reconstruction_btn, masks_annotated_image, n_samples}
|
| 54 |
def on_depth_reconstruction_btn_click(inputs):
|
| 55 |
print("depth reconstruction")
|
| 56 |
image = inputs[raw_image]
|
| 57 |
# depth reconstruction
|
| 58 |
+
path = dpt.generate_obj(image, inputs[n_samples])
|
| 59 |
return {pcl_figure: path}
|
| 60 |
|
| 61 |
depth_reconstruction_btn.click(on_depth_reconstruction_btn_click, components, [pcl_figure], queue=False)
|
inference.py
CHANGED
|
@@ -70,11 +70,11 @@ class DepthPredictor:
|
|
| 70 |
ax.scatter(points,size=0.01, c=colors, marker='o')
|
| 71 |
return fig
|
| 72 |
|
| 73 |
-
def generate_obj(self, image):
|
| 74 |
# Step 1: Create a point cloud
|
| 75 |
point_cloud, color_array = self.generate_pcl(image)
|
| 76 |
# sample 1000 points
|
| 77 |
-
idxs = np.random.choice(len(point_cloud), int(
|
| 78 |
point_cloud = point_cloud[idxs]
|
| 79 |
color_array = color_array[idxs]
|
| 80 |
# Create a mesh to hold the colored cubes
|
|
|
|
| 70 |
ax.scatter(points,size=0.01, c=colors, marker='o')
|
| 71 |
return fig
|
| 72 |
|
| 73 |
+
def generate_obj(self, image, n_samples):
|
| 74 |
# Step 1: Create a point cloud
|
| 75 |
point_cloud, color_array = self.generate_pcl(image)
|
| 76 |
# sample 1000 points
|
| 77 |
+
idxs = np.random.choice(len(point_cloud), int(n_samples))
|
| 78 |
point_cloud = point_cloud[idxs]
|
| 79 |
color_array = color_array[idxs]
|
| 80 |
# Create a mesh to hold the colored cubes
|