kaifz commited on
Commit
9d79799
1 Parent(s): e81aaa0

Add application file

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitignore +2 -0
  2. app.py +382 -0
  3. data/0/action-0/gs_pred.splat +0 -0
  4. data/0/action-0/img_0.png +0 -0
  5. data/0/action-0/img_1.png +0 -0
  6. data/0/action-0/img_2.png +0 -0
  7. data/0/action-0/img_3.png +0 -0
  8. data/0/action-0/video_0.mp4 +0 -0
  9. data/0/action-0/video_1.mp4 +0 -0
  10. data/0/action-0/video_2.mp4 +0 -0
  11. data/0/action-0/video_3.mp4 +0 -0
  12. data/0/action-1/gs_pred.splat +0 -0
  13. data/0/action-1/img_0.png +0 -0
  14. data/0/action-1/img_1.png +0 -0
  15. data/0/action-1/img_2.png +0 -0
  16. data/0/action-1/img_3.png +0 -0
  17. data/0/action-1/video_0.mp4 +0 -0
  18. data/0/action-1/video_1.mp4 +0 -0
  19. data/0/action-1/video_2.mp4 +0 -0
  20. data/0/action-1/video_3.mp4 +0 -0
  21. data/0/action-2/gs_pred.splat +0 -0
  22. data/0/action-2/img_0.png +0 -0
  23. data/0/action-2/img_1.png +0 -0
  24. data/0/action-2/img_2.png +0 -0
  25. data/0/action-2/img_3.png +0 -0
  26. data/0/action-2/video_0.mp4 +0 -0
  27. data/0/action-2/video_1.mp4 +0 -0
  28. data/0/action-2/video_2.mp4 +0 -0
  29. data/0/action-2/video_3.mp4 +0 -0
  30. data/0/gs_orig.splat +0 -0
  31. data/0/img_0.png +0 -0
  32. data/0/img_1.png +0 -0
  33. data/0/img_2.png +0 -0
  34. data/0/img_3.png +0 -0
  35. data/1/action-0/gs_pred.splat +0 -0
  36. data/1/action-0/img_0.png +0 -0
  37. data/1/action-0/img_1.png +0 -0
  38. data/1/action-0/img_2.png +0 -0
  39. data/1/action-0/img_3.png +0 -0
  40. data/1/action-0/video_0.mp4 +0 -0
  41. data/1/action-0/video_1.mp4 +0 -0
  42. data/1/action-0/video_2.mp4 +0 -0
  43. data/1/action-0/video_3.mp4 +0 -0
  44. data/1/action-1/gs_pred.splat +0 -0
  45. data/1/action-1/img_0.png +0 -0
  46. data/1/action-1/img_1.png +0 -0
  47. data/1/action-1/img_2.png +0 -0
  48. data/1/action-1/img_3.png +0 -0
  49. data/1/action-1/video_0.mp4 +0 -0
  50. data/1/action-1/video_1.mp4 +0 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ __pycache__/
2
+ .gradio/
app.py ADDED
@@ -0,0 +1,382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import numpy as np
3
+ import gradio as gr
4
+ import torch
5
+ import torch.nn.functional as F
6
+ import open3d as o3d
7
+ import time
8
+ import cv2
9
+ import math
10
+ import os
11
+ import yaml
12
+ import shutil
13
+ import sys
14
+ import glob
15
+ from functools import partial
16
+ import copy
17
+ from PIL import Image
18
+
19
+
20
+ class DynamicsVisualizer:
21
+
22
+ def __init__(self):
23
+ device = torch.device("cpu")
24
+ self.device = device
25
+ self.width = 640
26
+ self.height = 480
27
+
28
+ self.vis_cam_id = 1
29
+ self.bg_id = 0 # 0: black, 1: white
30
+
31
+ self.imgs = None
32
+ self.gs_orig = None
33
+ self.gs_pred = None
34
+ self.actions = None
35
+ self.videos = None
36
+
37
+ self.example_name = None
38
+ self.action_name = None
39
+
40
+ self.form_image_is_set = False
41
+ self.form_video_is_set = False
42
+ self.form_3dgs_orig_is_set = False
43
+ self.form_3dgs_pred_is_set = False
44
+
45
+ def load_example(self):
46
+ example_path = os.path.join('data', self.example_name)
47
+
48
+ self.imgs = [Image.open(os.path.join(example_path, f'img_{i}.png')) for i in range(4)]
49
+ self.gs_orig = os.path.join(example_path, 'gs_orig.splat')
50
+
51
+ def load_action(self):
52
+ action_path = os.path.join('data', self.action_name)
53
+
54
+ self.imgs = [Image.open(os.path.join(action_path, f'img_{i}.png')) for i in range(4)]
55
+ self.videos = [os.path.join(action_path, f'video_{i}.mp4') for i in range(4)]
56
+ self.gs_pred = os.path.join(action_path, 'gs_pred.splat')
57
+
58
+ def reset(self):
59
+ self.imgs = None
60
+ self.gs_orig = None
61
+ self.gs_pred = None
62
+ self.actions = None
63
+ self.videos = None
64
+ self.vis_cam_id = 1
65
+ self.bg_id = 0 # 0: black, 1: white
66
+ self.example_name = None
67
+ self.action_name = None
68
+ form_image = gr.Image(label='Initial state and actions', value=None, width=self.width, height=self.height)
69
+ form_video = gr.Video(label='Predicted video', value=None, width=self.width, height=self.height)
70
+ form_3dgs_orig = gr.Model3D(label='Original Gaussian Splats', value=None)
71
+ form_3dgs_pred = gr.Model3D(label='Predicted Gaussian Splats', value=None)
72
+ self.form_image_is_set = False
73
+ self.form_video_is_set = False
74
+ self.form_3dgs_orig_is_set = False
75
+ self.form_3dgs_pred_is_set = False
76
+ return form_image, form_video, form_3dgs_orig, form_3dgs_pred
77
+
78
+ def on_click_set_example(self, state):
79
+ self.example_name = f"{int(state['example_id'])}"
80
+ self.load_example()
81
+
82
+ init_image = self.imgs[self.vis_cam_id]
83
+ form_image = gr.Image(label='Initial state and actions', value=init_image, width=self.width, height=self.height)
84
+
85
+ form_video = gr.Video(label='Predicted video', value=None, width=self.width, height=self.height)
86
+ form_3dgs_orig = gr.Model3D(label='Original Gaussian Splats', value=self.gs_orig, clear_color=[self.bg_id, self.bg_id, self.bg_id, 0])
87
+ form_3dgs_pred = gr.Model3D(label='Predicted Gaussian Splats', value=None)
88
+
89
+ self.form_image_is_set = True
90
+ self.form_video_is_set = False
91
+ self.form_3dgs_orig_is_set = True
92
+ self.form_3dgs_pred_is_set = False
93
+
94
+ return form_image, form_video, form_3dgs_orig, form_3dgs_pred
95
+
96
+ def on_click_set_action(self, state):
97
+ self.action_name = f"{self.example_name}/action-{int(state['action_id'])}"
98
+ self.load_action()
99
+
100
+ action_image = self.imgs[self.vis_cam_id]
101
+ form_image = gr.Image(label='Initial state and actions', value=action_image, width=self.width, height=self.height)
102
+ self.form_image_is_set = True
103
+
104
+ return form_image
105
+
106
+ def on_click_run(self):
107
+ form_video = gr.Video(label='Predicted video', value=self.videos[self.vis_cam_id], width=self.width, height=self.height)
108
+ form_3dgs_pred = gr.Model3D(label='Predicted Gaussian Splats', value=self.gs_pred, clear_color=[self.bg_id, self.bg_id, self.bg_id, 0])
109
+ self.form_video_is_set = True
110
+ self.form_3dgs_pred_is_set = True
111
+
112
+ return form_video, form_3dgs_pred
113
+
114
+ def on_click_change_view(self, state):
115
+ self.vis_cam_id = int(state['view_id'])
116
+ form_image = gr.Image(label='Initial state and actions', value=self.imgs[self.vis_cam_id], width=self.width, height=self.height)
117
+ if self.form_video_is_set:
118
+ form_video = gr.Video(label='Predicted video', value=self.videos[self.vis_cam_id], width=self.width, height=self.height)
119
+ else:
120
+ form_video = gr.Video(label='Predicted video', value=None, width=self.width, height=self.height)
121
+ return form_image, form_video
122
+
123
+ # def on_click_change_bg(self):
124
+ # if self.bg_id == 0:
125
+ # self.bg_id = 1
126
+ # else:
127
+ # self.bg_id = 0
128
+
129
+ # if self.form_3dgs_orig_is_set:
130
+ # form_3dgs_orig = gr.Model3D(value=self.gs_orig, clear_color=[self.bg_id, self.bg_id, self.bg_id, 0])
131
+ # else:
132
+ # form_3dgs_orig = gr.Model3D(value=None)
133
+
134
+ # if self.form_3dgs_pred_is_set:
135
+ # form_3dgs_pred = gr.Model3D(value=self.gs_pred, clear_color=[self.bg_id, self.bg_id, self.bg_id, 0])
136
+ # else:
137
+ # form_3dgs_pred = gr.Model3D(value=None)
138
+
139
+ # return form_3dgs_orig, form_3dgs_pred
140
+
141
+ def launch(self, share=False):
142
+ with gr.Blocks() as app:
143
+
144
+ # with gr.Row():
145
+ # with gr.Column(scale=2):
146
+ # run_reset = gr.Button('Clear All')
147
+
148
+ # with gr.Column(scale=2):
149
+ # run_set_example = gr.Button('Set Example')
150
+
151
+ # with gr.Column(scale=2):
152
+ # run_set_action = gr.Button('Set Action')
153
+
154
+ # with gr.Column(scale=2):
155
+ # run_run = gr.Button('Run')
156
+
157
+ # with gr.Row():
158
+ # with gr.Column(scale=1, min_width=20):
159
+ # with gr.Row():
160
+ # run_view_0 = gr.Button('View 0')
161
+
162
+ # with gr.Row():
163
+ # run_view_1 = gr.Button('View 1')
164
+
165
+ # with gr.Row():
166
+ # run_view_2 = gr.Button('View 2')
167
+
168
+ # with gr.Row():
169
+ # run_view_3 = gr.Button('View 3')
170
+
171
+ with gr.Row():
172
+ gr.Markdown("# Dynamic 3D Gaussian Tracking for Graph-Based Neural Dynamics Modeling")
173
+
174
+ with gr.Row():
175
+ gr.Markdown('Project page: [https://gs-dynamics.github.io/](https://gs-dynamics.github.io/)')
176
+
177
+ with gr.Row():
178
+ gr.Markdown()
179
+
180
+ with gr.Row():
181
+ gr.Markdown()
182
+
183
+ with gr.Row():
184
+ with gr.Column(scale=1):
185
+ gr.Markdown("**Step 0**: click **Clear All** to clear all window and reset the visualizer.")
186
+
187
+ with gr.Column(scale=1):
188
+ run_reset = gr.Button('Clear All')
189
+
190
+
191
+ with gr.Row():
192
+ with gr.Column(scale=1):
193
+ gr.Markdown("**Step 1**: select the object.")
194
+
195
+ with gr.Column(scale=1):
196
+ run_set_example_0 = gr.Button('Rope')
197
+
198
+ with gr.Column(scale=1):
199
+ run_set_example_1 = gr.Button('Rope - Long')
200
+
201
+ with gr.Column(scale=1):
202
+ run_set_example_2 = gr.Button('Toy Animal')
203
+
204
+ with gr.Row():
205
+ with gr.Column(scale=1):
206
+ gr.Markdown("**Step 2**: select the action.")
207
+
208
+ with gr.Column(scale=1):
209
+ run_set_action_0 = gr.Button('Action 1')
210
+
211
+ with gr.Column(scale=1):
212
+ run_set_action_1 = gr.Button('Action 2')
213
+
214
+ with gr.Column(scale=1):
215
+ run_set_action_2 = gr.Button('Action 3')
216
+
217
+ with gr.Row():
218
+ with gr.Column(scale=1):
219
+ gr.Markdown("**Step 3**: click **Run** to visualize the predicted video and Splats.")
220
+
221
+ with gr.Column(scale=1):
222
+ run_run = gr.Button('Run')
223
+
224
+ with gr.Row():
225
+ with gr.Column(scale=1, min_width=20):
226
+ with gr.Row():
227
+ gr.Markdown()
228
+
229
+ with gr.Row():
230
+ gr.Markdown()
231
+
232
+ with gr.Row():
233
+ gr.Markdown()
234
+
235
+ with gr.Row():
236
+ gr.Markdown()
237
+
238
+ # with gr.Row():
239
+ # gr.Markdown()
240
+
241
+ # with gr.Row():
242
+ # gr.Markdown()
243
+
244
+ with gr.Row():
245
+ gr.Markdown("Our model uses only 4 cameras for reconstructing the Gaussian Splats. Click the buttons below to change the view.")
246
+
247
+ with gr.Row():
248
+ run_view_0 = gr.Button('View 0')
249
+
250
+ with gr.Row():
251
+ run_view_1 = gr.Button('View 1')
252
+
253
+ with gr.Row():
254
+ run_view_2 = gr.Button('View 2')
255
+
256
+ with gr.Row():
257
+ run_view_3 = gr.Button('View 3')
258
+
259
+ with gr.Column(scale=4):
260
+ with gr.Row():
261
+ with gr.Column(scale=2):
262
+ form_image = gr.Image(
263
+ label='Initial state and actions',
264
+ value=None,
265
+ width=self.width,
266
+ height=self.height,
267
+ )
268
+
269
+ with gr.Column(scale=2):
270
+ form_video = gr.Video(
271
+ label='Predicted video',
272
+ value=None,
273
+ width=self.width,
274
+ height=self.height,
275
+ )
276
+
277
+ with gr.Row():
278
+ # with gr.Column(scale=1, min_width=20):
279
+ # pass
280
+ # with gr.Row():
281
+ # change_bg = gr.Button('Black/White Background')
282
+
283
+ with gr.Column(scale=2):
284
+ form_3dgs_orig = gr.Model3D(
285
+ label='Original Gaussian Splats',
286
+ value=None,
287
+ )
288
+
289
+ with gr.Column(scale=2):
290
+ form_3dgs_pred = gr.Model3D(
291
+ label='Predicted Gaussian Splats',
292
+ value=None,
293
+ )
294
+
295
+ with gr.Row():
296
+ gr.Markdown("## Notes:")
297
+
298
+ with gr.Row():
299
+ gr.Markdown("- Due to the computation constraints of Hugging Face Space, all results are precomputed. ")
300
+
301
+ with gr.Row():
302
+ gr.Markdown("- Training a GS for an object takes around 30 seconds. Prediction typically takes only 1-2 seconds for each push!")
303
+
304
+ with gr.Row():
305
+ gr.Markdown("- More examples may be added in the future. Stay tuned!")
306
+
307
+ # with gr.Row():
308
+ # with gr.Column(scale=1):
309
+ # gr.Markdown("You can change the view to any of the 4 cameras.")
310
+
311
+ # with gr.Column(scale=1):
312
+ # run_view_0 = gr.Button('View 1')
313
+
314
+ # with gr.Column(scale=1):
315
+ # run_view_1 = gr.Button('View 2')
316
+
317
+ # with gr.Column(scale=1):
318
+ # run_view_2 = gr.Button('View 3')
319
+
320
+ # with gr.Column(scale=1):
321
+ # run_view_3 = gr.Button('View 4')
322
+
323
+ # Set up callbacks
324
+
325
+ run_reset.click(self.reset,
326
+ inputs=[],
327
+ outputs=[form_image, form_video, form_3dgs_orig, form_3dgs_pred])
328
+
329
+ run_set_example_0.click(self.on_click_set_example,
330
+ inputs=[gr.State({'example_id': 0})],
331
+ outputs=[form_image, form_video, form_3dgs_orig, form_3dgs_pred])
332
+
333
+ run_set_example_1.click(self.on_click_set_example,
334
+ inputs=[gr.State({'example_id': 1})],
335
+ outputs=[form_image, form_video, form_3dgs_orig, form_3dgs_pred])
336
+
337
+ run_set_example_2.click(self.on_click_set_example,
338
+ inputs=[gr.State({'example_id': 2})],
339
+ outputs=[form_image, form_video, form_3dgs_orig, form_3dgs_pred])
340
+
341
+ run_set_action_0.click(self.on_click_set_action,
342
+ inputs=[gr.State({'action_id': 0})],
343
+ outputs=[form_image])
344
+
345
+ run_set_action_1.click(self.on_click_set_action,
346
+ inputs=[gr.State({'action_id': 1})],
347
+ outputs=[form_image])
348
+
349
+ run_set_action_2.click(self.on_click_set_action,
350
+ inputs=[gr.State({'action_id': 2})],
351
+ outputs=[form_image])
352
+
353
+ run_run.click(self.on_click_run,
354
+ inputs=[],
355
+ outputs=[form_video, form_3dgs_pred])
356
+
357
+ run_view_0.click(self.on_click_change_view,
358
+ inputs=[gr.State({'view_id': 1})],
359
+ outputs=[form_image, form_video])
360
+
361
+ run_view_1.click(self.on_click_change_view,
362
+ inputs=[gr.State({'view_id': 2})],
363
+ outputs=[form_image, form_video])
364
+
365
+ run_view_2.click(self.on_click_change_view,
366
+ inputs=[gr.State({'view_id': 3})],
367
+ outputs=[form_image, form_video])
368
+
369
+ run_view_3.click(self.on_click_change_view,
370
+ inputs=[gr.State({'view_id': 0})],
371
+ outputs=[form_image, form_video])
372
+
373
+ # change_bg.click(self.on_click_change_bg,
374
+ # inputs=[],
375
+ # outputs=[form_3dgs_orig, form_3dgs_pred])
376
+
377
+ app.launch(share=share)
378
+
379
+
380
+ if __name__ == '__main__':
381
+ visualizer = DynamicsVisualizer()
382
+ visualizer.launch(share=True)
data/0/action-0/gs_pred.splat ADDED
Binary file (170 kB). View file
 
data/0/action-0/img_0.png ADDED
data/0/action-0/img_1.png ADDED
data/0/action-0/img_2.png ADDED
data/0/action-0/img_3.png ADDED
data/0/action-0/video_0.mp4 ADDED
Binary file (51 kB). View file
 
data/0/action-0/video_1.mp4 ADDED
Binary file (63.4 kB). View file
 
data/0/action-0/video_2.mp4 ADDED
Binary file (75.3 kB). View file
 
data/0/action-0/video_3.mp4 ADDED
Binary file (56 kB). View file
 
data/0/action-1/gs_pred.splat ADDED
Binary file (160 kB). View file
 
data/0/action-1/img_0.png ADDED
data/0/action-1/img_1.png ADDED
data/0/action-1/img_2.png ADDED
data/0/action-1/img_3.png ADDED
data/0/action-1/video_0.mp4 ADDED
Binary file (59.8 kB). View file
 
data/0/action-1/video_1.mp4 ADDED
Binary file (73.1 kB). View file
 
data/0/action-1/video_2.mp4 ADDED
Binary file (86.2 kB). View file
 
data/0/action-1/video_3.mp4 ADDED
Binary file (63.9 kB). View file
 
data/0/action-2/gs_pred.splat ADDED
Binary file (164 kB). View file
 
data/0/action-2/img_0.png ADDED
data/0/action-2/img_1.png ADDED
data/0/action-2/img_2.png ADDED
data/0/action-2/img_3.png ADDED
data/0/action-2/video_0.mp4 ADDED
Binary file (56.6 kB). View file
 
data/0/action-2/video_1.mp4 ADDED
Binary file (71.8 kB). View file
 
data/0/action-2/video_2.mp4 ADDED
Binary file (83.6 kB). View file
 
data/0/action-2/video_3.mp4 ADDED
Binary file (61.6 kB). View file
 
data/0/gs_orig.splat ADDED
Binary file (166 kB). View file
 
data/0/img_0.png ADDED
data/0/img_1.png ADDED
data/0/img_2.png ADDED
data/0/img_3.png ADDED
data/1/action-0/gs_pred.splat ADDED
Binary file (325 kB). View file
 
data/1/action-0/img_0.png ADDED
data/1/action-0/img_1.png ADDED
data/1/action-0/img_2.png ADDED
data/1/action-0/img_3.png ADDED
data/1/action-0/video_0.mp4 ADDED
Binary file (83.2 kB). View file
 
data/1/action-0/video_1.mp4 ADDED
Binary file (97.2 kB). View file
 
data/1/action-0/video_2.mp4 ADDED
Binary file (106 kB). View file
 
data/1/action-0/video_3.mp4 ADDED
Binary file (84.5 kB). View file
 
data/1/action-1/gs_pred.splat ADDED
Binary file (323 kB). View file
 
data/1/action-1/img_0.png ADDED
data/1/action-1/img_1.png ADDED
data/1/action-1/img_2.png ADDED
data/1/action-1/img_3.png ADDED
data/1/action-1/video_0.mp4 ADDED
Binary file (101 kB). View file
 
data/1/action-1/video_1.mp4 ADDED
Binary file (124 kB). View file