MCPcopy Create free account
hub / github.com/AiuniAI/Unique3D / geo_reconstruct

Function geo_reconstruct

scripts/multiview_inference.py:63–98  ·  view source on GitHub ↗
(rgb_pils, normal_pils, front_pil, do_refine=False, predict_normal=True, expansion_weight=0.1, init_type="std")

Source from the content-addressed store, hash-verified

61 return out_img_list
62import time
63def geo_reconstruct(rgb_pils, normal_pils, front_pil, do_refine=False, predict_normal=True, expansion_weight=0.1, init_type="std"):
64 if front_pil.size[0] <= 512:
65 front_pil = run_sr_fast([front_pil])[0]
66 if do_refine:
67 refined_rgbs = refine_rgb(rgb_pils, front_pil) # 6s
68 else:
69 refined_rgbs = [rgb.resize((512, 512), resample=Image.LANCZOS) for rgb in rgb_pils]
70 img_list = [front_pil] + run_sr_fast(refined_rgbs[1:])
71
72 if predict_normal:
73 rm_normals = predict_normals([img.resize((512, 512), resample=Image.LANCZOS) for img in img_list], guidance_scale=1.5)
74 else:
75 rm_normals = simple_remove([img.resize((512, 512), resample=Image.LANCZOS) for img in normal_pils])
76 # transfer the alpha channel of rm_normals to img_list
77 for idx, img in enumerate(rm_normals):
78 if idx == 0 and img_list[0].mode == "RGBA":
79 temp = img_list[0].resize((2048, 2048))
80 rm_normals[0] = Image.fromarray(np.concatenate([np.array(rm_normals[0])[:, :, :3], np.array(temp)[:, :, 3:4]], axis=-1))
81 continue
82 img_list[idx] = Image.fromarray(np.concatenate([np.array(img_list[idx]), np.array(img)[:, :, 3:4]], axis=-1))
83 assert img_list[0].mode == "RGBA"
84 assert np.mean(np.array(img_list[0])[..., 3]) < 250
85
86 img_list = [img_list[0]] + erode_alpha(img_list[1:])
87 normal_stg1 = [img.resize((512, 512)) for img in rm_normals]
88 if init_type in ["std", "thin"]:
89 meshes = fast_geo(normal_stg1[0], normal_stg1[2], normal_stg1[1], init_type=init_type)
90 _ = multiview_color_projection(meshes, rgb_pils, resolution=512, device="cuda", complete_unseen=False, confidence_threshold=0.1) # just check for validation, may throw error
91 vertices, faces, _ = from_py3d_mesh(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 vertices, faces = run_mesh_refine(vertices, faces, rm_normals, 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)
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

Callers 2

generate3dv2Function · 0.90
multiview_to_mesh_v2Function · 0.90

Calls 13

run_sr_fastFunction · 0.90
predict_normalsFunction · 0.90
simple_removeFunction · 0.90
from_py3d_meshFunction · 0.90
reconstruct_stage1Function · 0.90
run_mesh_refineFunction · 0.90
simple_clean_meshFunction · 0.90
to_pyml_meshFunction · 0.90
get_cameras_listFunction · 0.90
refine_rgbFunction · 0.85
erode_alphaFunction · 0.85

Tested by

no test coverage detected