Spaces:
Running
on
Zero
Running
on
Zero
lemonaddie
commited on
Update app_recon.py
Browse files- app_recon.py +11 -3
app_recon.py
CHANGED
@@ -75,6 +75,9 @@ pipe = DepthNormalEstimationPipeline(vae=vae,
|
|
75 |
unet=unet,
|
76 |
scheduler=scheduler)
|
77 |
|
|
|
|
|
|
|
78 |
try:
|
79 |
import xformers
|
80 |
pipe.enable_xformers_memory_efficient_attention()
|
@@ -159,6 +162,7 @@ def depth_normal(img_path,
|
|
159 |
normal_np = pipe_out.normal_np
|
160 |
|
161 |
path_output_dir = os.path.splitext(os.path.basename(img_path))[0] + datetime.now().strftime('%Y%m%d-%H%M%S')
|
|
|
162 |
os.makedirs(path_output_dir, exist_ok=True)
|
163 |
|
164 |
name_base = os.path.splitext(os.path.basename(img_path))[0]
|
@@ -199,7 +203,10 @@ def reconstruction(image_file, files):
|
|
199 |
|
200 |
masked_image, mask = seg_foreground(image_file)
|
201 |
|
202 |
-
|
|
|
|
|
|
|
203 |
depth_np = np.load(files[0])
|
204 |
normal_np = np.load(files[1])
|
205 |
|
@@ -211,7 +218,7 @@ def reconstruction(image_file, files):
|
|
211 |
|
212 |
normal_np[:, :, 0] *= -1
|
213 |
_, surface, _, _, _ = bilateral_normal_integration_function(normal_np, mask_output_temp, k=2, K=None, max_iter=100, tol=1e-4, cg_max_iter=5000, cg_tol=1e-3)
|
214 |
-
ply_path = os.path.join(dir_name, f"{name_base}_recon.ply")
|
215 |
surface.save(ply_path, binary=False)
|
216 |
|
217 |
obj_path = ply_path.replace('ply', 'obj')
|
@@ -224,6 +231,7 @@ def reconstruction(image_file, files):
|
|
224 |
|
225 |
return obj_path, [ply_path], masked_image
|
226 |
|
|
|
227 |
def run_demo():
|
228 |
|
229 |
|
@@ -342,7 +350,7 @@ def run_demo():
|
|
342 |
outputs=[depth, normal, files]
|
343 |
)
|
344 |
recon_btn.click(fn=reconstruction,
|
345 |
-
inputs=[input_image,
|
346 |
outputs=[reconstructed_3d, reconstructed_file, masked_image]
|
347 |
)
|
348 |
demo.queue().launch(share=True, max_threads=80)
|
|
|
75 |
unet=unet,
|
76 |
scheduler=scheduler)
|
77 |
|
78 |
+
|
79 |
+
outputs_dir = "./outs"
|
80 |
+
|
81 |
try:
|
82 |
import xformers
|
83 |
pipe.enable_xformers_memory_efficient_attention()
|
|
|
162 |
normal_np = pipe_out.normal_np
|
163 |
|
164 |
path_output_dir = os.path.splitext(os.path.basename(img_path))[0] + datetime.now().strftime('%Y%m%d-%H%M%S')
|
165 |
+
path_output_dir = os.path.join(path_output_dir, outputs_dir)
|
166 |
os.makedirs(path_output_dir, exist_ok=True)
|
167 |
|
168 |
name_base = os.path.splitext(os.path.basename(img_path))[0]
|
|
|
203 |
|
204 |
masked_image, mask = seg_foreground(image_file)
|
205 |
|
206 |
+
# import pdb
|
207 |
+
# pdb.set_trace()
|
208 |
+
|
209 |
+
mask = np.array(mask) > 0.5
|
210 |
depth_np = np.load(files[0])
|
211 |
normal_np = np.load(files[1])
|
212 |
|
|
|
218 |
|
219 |
normal_np[:, :, 0] *= -1
|
220 |
_, surface, _, _, _ = bilateral_normal_integration_function(normal_np, mask_output_temp, k=2, K=None, max_iter=100, tol=1e-4, cg_max_iter=5000, cg_tol=1e-3)
|
221 |
+
ply_path = os.path.join(outputs_dir, dir_name, f"{name_base}_recon.ply")
|
222 |
surface.save(ply_path, binary=False)
|
223 |
|
224 |
obj_path = ply_path.replace('ply', 'obj')
|
|
|
231 |
|
232 |
return obj_path, [ply_path], masked_image
|
233 |
|
234 |
+
# @spaces.GPU
|
235 |
def run_demo():
|
236 |
|
237 |
|
|
|
350 |
outputs=[depth, normal, files]
|
351 |
)
|
352 |
recon_btn.click(fn=reconstruction,
|
353 |
+
inputs=[input_image, files],
|
354 |
outputs=[reconstructed_3d, reconstructed_file, masked_image]
|
355 |
)
|
356 |
demo.queue().launch(share=True, max_threads=80)
|