Spaces:
Paused
Paused
Weiyu Liu
commited on
Commit
·
38a6100
1
Parent(s):
3827c6d
update
Browse files
__pycache__/app.cpython-38.pyc
CHANGED
Binary files a/__pycache__/app.cpython-38.pyc and b/__pycache__/app.cpython-38.pyc differ
|
|
app.py
CHANGED
@@ -17,6 +17,7 @@ from StructDiffusion.diffusion.sampler import Sampler
|
|
17 |
from StructDiffusion.diffusion.pose_conversion import get_struct_objs_poses
|
18 |
from StructDiffusion.utils.files import get_checkpoint_path_from_dir
|
19 |
from StructDiffusion.utils.rearrangement import show_pcs_with_trimesh
|
|
|
20 |
|
21 |
|
22 |
def move_pc_and_create_scene_simple(obj_xyzs, struct_pose, pc_poses_in_struct):
|
@@ -78,7 +79,21 @@ class Infer_Wrapper:
|
|
78 |
|
79 |
self.sampler = Sampler(ConditionalPoseDiffusionModel, checkpoint_path, self.device)
|
80 |
|
81 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
# di = np.random.choice(len(self.dataset))
|
84 |
|
@@ -88,7 +103,7 @@ class Infer_Wrapper:
|
|
88 |
batch = self.dataset.single_datum_to_batch(datum, args.num_samples, self.device, inference_mode=True)
|
89 |
|
90 |
num_poses = datum["goal_poses"].shape[0]
|
91 |
-
xs = self.sampler.sample(batch, num_poses)
|
92 |
|
93 |
struct_pose, pc_poses_in_struct = get_struct_objs_poses(xs[0])
|
94 |
new_obj_xyzs = move_pc_and_create_scene_simple(batch["pcs"], struct_pose, pc_poses_in_struct)
|
@@ -110,7 +125,9 @@ class Infer_Wrapper:
|
|
110 |
vis_obj_xyz = vis_obj_xyzs[0]
|
111 |
scene = show_pcs_with_trimesh([xyz[:, :3] for xyz in vis_obj_xyz], [xyz[:, 3:] for xyz in vis_obj_xyz], return_scene=True)
|
112 |
|
113 |
-
|
|
|
|
|
114 |
scene.export(scene_filename)
|
115 |
|
116 |
# pc_filename = "/home/weiyu/Research/StructDiffusion/StructDiffusion/interactive_demo/tmp_data/pc.glb"
|
@@ -161,11 +178,34 @@ cfg = OmegaConf.merge(base_cfg, cfg)
|
|
161 |
|
162 |
infer_wrapper = Infer_Wrapper(args, cfg)
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
)
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
demo.launch()
|
|
|
17 |
from StructDiffusion.diffusion.pose_conversion import get_struct_objs_poses
|
18 |
from StructDiffusion.utils.files import get_checkpoint_path_from_dir
|
19 |
from StructDiffusion.utils.rearrangement import show_pcs_with_trimesh
|
20 |
+
import StructDiffusion.utils.transformations as tra
|
21 |
|
22 |
|
23 |
def move_pc_and_create_scene_simple(obj_xyzs, struct_pose, pc_poses_in_struct):
|
|
|
79 |
|
80 |
self.sampler = Sampler(ConditionalPoseDiffusionModel, checkpoint_path, self.device)
|
81 |
|
82 |
+
def visualize_scene(self, di, session_id):
|
83 |
+
raw_datum = self.dataset.get_raw_data(di)
|
84 |
+
language_command = self.tokenizer.convert_structure_params_to_natural_language(raw_datum["sentence"])
|
85 |
+
|
86 |
+
obj_xyz = raw_datum["pcs"]
|
87 |
+
scene = show_pcs_with_trimesh([xyz[:, :3] for xyz in obj_xyz], [xyz[:, 3:] for xyz in obj_xyz], return_scene=True)
|
88 |
+
|
89 |
+
scene.apply_transform(tra.euler_matrix(np.pi, 0, np.pi/2))
|
90 |
+
|
91 |
+
scene_filename = "./tmp_data/input_scene_{}.glb".format(session_id)
|
92 |
+
scene.export(scene_filename)
|
93 |
+
|
94 |
+
return language_command, scene_filename
|
95 |
+
|
96 |
+
def infer(self, di, session_id, progress=gr.Progress()):
|
97 |
|
98 |
# di = np.random.choice(len(self.dataset))
|
99 |
|
|
|
103 |
batch = self.dataset.single_datum_to_batch(datum, args.num_samples, self.device, inference_mode=True)
|
104 |
|
105 |
num_poses = datum["goal_poses"].shape[0]
|
106 |
+
xs = self.sampler.sample(batch, num_poses, progress)
|
107 |
|
108 |
struct_pose, pc_poses_in_struct = get_struct_objs_poses(xs[0])
|
109 |
new_obj_xyzs = move_pc_and_create_scene_simple(batch["pcs"], struct_pose, pc_poses_in_struct)
|
|
|
125 |
vis_obj_xyz = vis_obj_xyzs[0]
|
126 |
scene = show_pcs_with_trimesh([xyz[:, :3] for xyz in vis_obj_xyz], [xyz[:, 3:] for xyz in vis_obj_xyz], return_scene=True)
|
127 |
|
128 |
+
scene.apply_transform(tra.euler_matrix(np.pi, 0, np.pi/2))
|
129 |
+
|
130 |
+
scene_filename = "./tmp_data/output_scene_{}.glb".format(session_id)
|
131 |
scene.export(scene_filename)
|
132 |
|
133 |
# pc_filename = "/home/weiyu/Research/StructDiffusion/StructDiffusion/interactive_demo/tmp_data/pc.glb"
|
|
|
178 |
|
179 |
infer_wrapper = Infer_Wrapper(args, cfg)
|
180 |
|
181 |
+
# version 0
|
182 |
+
# demo = gr.Interface(
|
183 |
+
# fn=infer_wrapper.run,
|
184 |
+
# inputs=gr.Slider(0, len(infer_wrapper.dataset)),
|
185 |
+
# # clear color range [0-1.0]
|
186 |
+
# outputs=gr.Model3D(clear_color=[0, 0, 0, 0], label="3D Model")
|
187 |
+
# )
|
188 |
+
#
|
189 |
+
# demo.launch()
|
190 |
+
|
191 |
+
# version 1
|
192 |
+
demo = gr.Blocks(theme=gr.themes.Soft())
|
193 |
+
with demo:
|
194 |
+
gr.Markdown("<p style='text-align:center;font-size:18px'><b>StructDiffusion Demo</b></p>")
|
195 |
+
# font-size:18px
|
196 |
+
gr.Markdown("<p style='text-align:center'>StructDiffusion combines a diffusion model and an object-centric transformer to construct structures given partial-view point clouds and high-level language goals.<br><a href='https://structdiffusion.github.io/'>Website</a> | <a href='https://github.com/StructDiffusion/StructDiffusion'>Code</a></p>")
|
197 |
+
|
198 |
+
session_id = gr.State(value=np.random.randint(0, 1000))
|
199 |
+
data_selection = gr.Number(label="Example No.", minimum=0, maximum=len(infer_wrapper.dataset) - 1, precision=0)
|
200 |
+
input_scene = gr.Model3D(clear_color=[0, 0, 0, 0], label="Input 3D Scene")
|
201 |
+
language_command = gr.Textbox(label="Input Language Command")
|
202 |
+
output_scene = gr.Model3D(clear_color=[0, 0, 0, 0], label="Generated 3D Structure")
|
203 |
+
|
204 |
+
b1 = gr.Button("Show Input Language and Scene")
|
205 |
+
b2 = gr.Button("Generate 3D Structure")
|
206 |
+
|
207 |
+
b1.click(infer_wrapper.visualize_scene, inputs=[data_selection, session_id], outputs=[language_command, input_scene])
|
208 |
+
b2.click(infer_wrapper.infer, inputs=[data_selection, session_id], outputs=output_scene)
|
209 |
+
|
210 |
+
demo.queue(concurrency_count=10)
|
211 |
demo.launch()
|
src/StructDiffusion/diffusion/__pycache__/sampler.cpython-38.pyc
CHANGED
Binary files a/src/StructDiffusion/diffusion/__pycache__/sampler.cpython-38.pyc and b/src/StructDiffusion/diffusion/__pycache__/sampler.cpython-38.pyc differ
|
|
src/StructDiffusion/diffusion/sampler.py
CHANGED
@@ -14,7 +14,7 @@ class Sampler:
|
|
14 |
self.backbone.to(device)
|
15 |
self.backbone.eval()
|
16 |
|
17 |
-
def sample(self, batch, num_poses):
|
18 |
|
19 |
noise_schedule = self.model.noise_schedule
|
20 |
|
@@ -23,7 +23,7 @@ class Sampler:
|
|
23 |
x_noisy = torch.randn((B, num_poses, 9), device=self.device)
|
24 |
|
25 |
xs = []
|
26 |
-
for t_index in tqdm(reversed(range(0, noise_schedule.timesteps)),
|
27 |
desc='sampling loop time step', total=noise_schedule.timesteps):
|
28 |
|
29 |
t = torch.full((B,), t_index, device=self.device, dtype=torch.long)
|
|
|
14 |
self.backbone.to(device)
|
15 |
self.backbone.eval()
|
16 |
|
17 |
+
def sample(self, batch, num_poses, progress):
|
18 |
|
19 |
noise_schedule = self.model.noise_schedule
|
20 |
|
|
|
23 |
x_noisy = torch.randn((B, num_poses, 9), device=self.device)
|
24 |
|
25 |
xs = []
|
26 |
+
for t_index in progress.tqdm(reversed(range(0, noise_schedule.timesteps)),
|
27 |
desc='sampling loop time step', total=noise_schedule.timesteps):
|
28 |
|
29 |
t = torch.full((B,), t_index, device=self.device, dtype=torch.long)
|
src/StructDiffusion/utils/__pycache__/rearrangement.cpython-38.pyc
CHANGED
Binary files a/src/StructDiffusion/utils/__pycache__/rearrangement.cpython-38.pyc and b/src/StructDiffusion/utils/__pycache__/rearrangement.cpython-38.pyc differ
|
|
src/StructDiffusion/utils/rearrangement.py
CHANGED
@@ -582,6 +582,7 @@ def show_pcs_with_trimesh(obj_xyzs, obj_rgbs, return_scene=False):
|
|
582 |
RT_4x4 = np.linalg.inv(RT_4x4)
|
583 |
RT_4x4 = RT_4x4 @ np.diag([1, -1, -1, 1])
|
584 |
scene.camera_transform = RT_4x4
|
|
|
585 |
if return_scene:
|
586 |
return scene
|
587 |
else:
|
|
|
582 |
RT_4x4 = np.linalg.inv(RT_4x4)
|
583 |
RT_4x4 = RT_4x4 @ np.diag([1, -1, -1, 1])
|
584 |
scene.camera_transform = RT_4x4
|
585 |
+
|
586 |
if return_scene:
|
587 |
return scene
|
588 |
else:
|