Spaces:
Running
on
Zero
Running
on
Zero
fix bug
Browse files
mesh_reconstruction/recon.py
CHANGED
@@ -12,8 +12,8 @@ from scripts.utils import to_py3d_mesh, init_target
|
|
12 |
def reconstruct_stage1(pils: List[Image.Image], steps=100, vertices=None, faces=None, start_edge_len=0.15, end_edge_len=0.005, decay=0.995, return_mesh=True, loss_expansion_weight=0.1, gain=0.1):
|
13 |
vertices, faces = vertices.to("cuda"), faces.to("cuda")
|
14 |
assert len(pils) == 4
|
15 |
-
mv,proj =
|
16 |
-
renderer = Pytorch3DNormalsRenderer(
|
17 |
|
18 |
target_images = init_target(pils, new_bkgd=(0., 0., 0.)) # 4s
|
19 |
# 1. no rotate
|
|
|
12 |
def reconstruct_stage1(pils: List[Image.Image], steps=100, vertices=None, faces=None, start_edge_len=0.15, end_edge_len=0.005, decay=0.995, return_mesh=True, loss_expansion_weight=0.1, gain=0.1):
|
13 |
vertices, faces = vertices.to("cuda"), faces.to("cuda")
|
14 |
assert len(pils) == 4
|
15 |
+
mv,proj = make_star_cameras_orthographic_py3d([0, 270, 180, 90], device="cuda", focal=1., dist=4.0)
|
16 |
+
renderer = Pytorch3DNormalsRenderer(cameras, list(pils[0].size), device="cuda")
|
17 |
|
18 |
target_images = init_target(pils, new_bkgd=(0., 0., 0.)) # 4s
|
19 |
# 1. no rotate
|
mesh_reconstruction/refine.py
CHANGED
@@ -17,8 +17,8 @@ def run_mesh_refine(vertices, faces, pils: List[Image.Image], steps=100, start_e
|
|
17 |
poission_steps = []
|
18 |
|
19 |
assert len(pils) == 4
|
20 |
-
mv,proj =
|
21 |
-
renderer = Pytorch3DNormalsRenderer(
|
22 |
|
23 |
target_images = init_target(pils, new_bkgd=(0., 0., 0.)) # 4s
|
24 |
# 1. no rotate
|
|
|
17 |
poission_steps = []
|
18 |
|
19 |
assert len(pils) == 4
|
20 |
+
mv,proj = make_star_cameras_orthographic_py3d([0, 270, 180, 90], device="cuda", focal=1., dist=4.0)
|
21 |
+
renderer = Pytorch3DNormalsRenderer(cameras, list(pils[0].size), device="cuda")
|
22 |
|
23 |
target_images = init_target(pils, new_bkgd=(0., 0., 0.)) # 4s
|
24 |
# 1. no rotate
|
scripts/multiview_inference.py
CHANGED
@@ -92,7 +92,10 @@ def geo_reconstruct(rgb_pils, normal_pils, front_pil, do_refine=False, predict_n
|
|
92 |
vertices, faces = reconstruct_stage1(normal_stg1, steps=200, vertices=vertices, faces=faces, start_edge_len=0.1, end_edge_len=0.02, gain=0.05, return_mesh=False, loss_expansion_weight=expansion_weight)
|
93 |
elif init_type in ["ball"]:
|
94 |
vertices, faces = reconstruct_stage1(normal_stg1, steps=200, end_edge_len=0.01, return_mesh=False, loss_expansion_weight=expansion_weight)
|
95 |
-
|
|
|
|
|
|
|
96 |
meshes = simple_clean_mesh(to_pyml_mesh(vertices, faces), apply_smooth=True, stepsmoothnum=1, apply_sub_divide=True, sub_divide_threshold=0.25).to("cuda")
|
97 |
new_meshes = multiview_color_projection(meshes, img_list, resolution=1024, device="cuda", complete_unseen=True, confidence_threshold=0.2, cameras_list = get_cameras_list([0, 90, 180, 270], "cuda", focal=1))
|
98 |
return new_meshes
|
|
|
92 |
vertices, faces = reconstruct_stage1(normal_stg1, steps=200, vertices=vertices, faces=faces, start_edge_len=0.1, end_edge_len=0.02, gain=0.05, return_mesh=False, loss_expansion_weight=expansion_weight)
|
93 |
elif init_type in ["ball"]:
|
94 |
vertices, faces = reconstruct_stage1(normal_stg1, steps=200, end_edge_len=0.01, return_mesh=False, loss_expansion_weight=expansion_weight)
|
95 |
+
|
96 |
+
normal_stg2 = [img.resize((1024, 1024)) for img in rm_normals] # reduce computation on huggingface demo, use 1024 instead of 2048
|
97 |
+
|
98 |
+
vertices, faces = run_mesh_refine(vertices, faces, normal_stg2, steps=100, start_edge_len=0.02, end_edge_len=0.005, decay=0.99, update_normal_interval=20, update_warmup=5, return_mesh=False, process_inputs=False, process_outputs=False)
|
99 |
meshes = simple_clean_mesh(to_pyml_mesh(vertices, faces), apply_smooth=True, stepsmoothnum=1, apply_sub_divide=True, sub_divide_threshold=0.25).to("cuda")
|
100 |
new_meshes = multiview_color_projection(meshes, img_list, resolution=1024, device="cuda", complete_unseen=True, confidence_threshold=0.2, cameras_list = get_cameras_list([0, 90, 180, 270], "cuda", focal=1))
|
101 |
return new_meshes
|