cyun9286 commited on
Commit
487d9ae
1 Parent(s): 71692ae
.gitignore CHANGED
@@ -1,4 +1,6 @@
1
  *.pth
2
  *.pt
3
  .gitignore
4
- *.glb
 
 
 
1
  *.pth
2
  *.pt
3
  .gitignore
4
+ *.glb
5
+ output/*
6
+ app_test.py
app.py CHANGED
@@ -17,6 +17,8 @@ import copy
17
  from tqdm import tqdm
18
  import cv2
19
  from PIL import Image
 
 
20
 
21
  from dust3r.inference import inference
22
  from dust3r.model import AsymmetricCroCo3DStereo
@@ -32,16 +34,19 @@ import spaces
32
  from huggingface_hub import hf_hub_download
33
  pl.ion()
34
 
 
 
 
35
  # for gpu >= Ampere and pytorch >= 1.12
36
  torch.backends.cuda.matmul.allow_tf32 = True
37
  batch_size = 1
38
 
39
  tmpdirname = tempfile.mkdtemp(suffix='_align3r_gradio_demo')
40
  image_size = 512
41
- silent = True
42
  gradio_delete_cache = 7200
43
-
44
- hf_hub_download(repo_id="apple/DepthPro", filename='depth_pro.pt', local_dir='third_party/ml-depth-pro/checkpoints/')
45
 
46
  class FileState:
47
  def __init__(self, outfile_name=None):
@@ -141,24 +146,16 @@ def local_get_reconstructed_scene(filelist, min_conf_thr, as_pointcloud, mask_sk
141
  loss = scene.compute_global_alignment(init='mst', niter=300, schedule='linear', lr=lr)
142
  # mode = GlobalAlignerMode.PairViewer
143
  # scene = global_aligner(output, device=device, mode=mode, verbose=not silent)
144
- save_folder = './output'
 
145
  os.makedirs(save_folder, exist_ok=True)
146
  outfile = get_3D_model_from_scene(save_folder, silent, scene, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size)
147
 
148
  return outfile
149
 
150
 
151
- def run_example(snapshot, matching_conf_thr, min_conf_thr, cam_size, as_pointcloud, shared_intrinsics, filelist, **kw):
152
- return local_get_reconstructed_scene(filelist, cam_size, **kw)
153
- # filelist = ['/home/lipeng/ljh_code/Video_Depth_CVPR2025-main/Align3R/data/davis/DAVIS/JPEGImages/480p/bear/00000.jpg', '/home/lipeng/ljh_code/Video_Depth_CVPR2025-main/Align3R/data/davis/DAVIS/JPEGImages/480p/bear/00008.jpg','/home/lipeng/ljh_code/Video_Depth_CVPR2025-main/Align3R/data/davis/DAVIS/JPEGImages/480p/bear/00004.jpg', '/home/lipeng/ljh_code/Video_Depth_CVPR2025-main/Align3R/data/davis/DAVIS/JPEGImages/480p/bear/00010.jpg']
154
- # min_conf_thr = 1.1
155
- # as_pointcloud = True
156
- # mask_sky = False
157
- # clean_depth = True
158
- # transparent_cams = False
159
- # cam_size = 0.2
160
- # depth_prior_name = 'Depth Anything V2'
161
- # local_get_reconstructed_scene(filelist, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size, depth_prior_name)
162
 
163
  css = """.gradio-container {margin: 0 !important; min-width: 100%};"""
164
  title = "Align3R Demo"
@@ -174,14 +171,14 @@ with gradio.Blocks(css=css, title=title, delete_cache=(gradio_delete_cache, grad
174
  snapshot = gradio.Image(None, visible=False)
175
  with gradio.Row():
176
  # adjust the camera size in the output pointcloud
177
- cam_size = gradio.Slider(label="cam_size", value=0.2, minimum=0.001, maximum=1.0, step=0.001)
178
 
179
  depth_prior_name = gradio.Dropdown(
180
  ["Depth Pro", "Depth Anything V2"], label="monocular depth estimation model", info="Select the monocular depth estimation model.")
181
- min_conf_thr = gradio.Slider(label="min_conf_thr", value=1.1, minimum=0.0, maximum=20, step=0.01)
182
  with gradio.Row():
183
  as_pointcloud = gradio.Checkbox(value=True, label="As pointcloud")
184
- mask_sky = gradio.Checkbox(value=False, label="Mask sky")
185
  clean_depth = gradio.Checkbox(value=True, label="Clean-up depthmaps")
186
  transparent_cams = gradio.Checkbox(value=False, label="Transparent cameras")
187
  # not to show camera
@@ -189,17 +186,74 @@ with gradio.Blocks(css=css, title=title, delete_cache=(gradio_delete_cache, grad
189
  run_btn = gradio.Button("Run")
190
  outmodel = gradio.Model3D()
191
 
192
- # examples = gradio.Examples(
193
- # examples=[
194
- # ['./example/yellowman/frame_0003.png',
195
- # 0.0, 1.5, 0.2, True, False,
196
- # ]
197
- # ],
198
- # inputs=[snapshot, matching_conf_thr, min_conf_thr, cam_size, as_pointcloud, shared_intrinsics, inputfiles],
199
- # outputs=[filestate, outmodel],
200
- # fn=run_example,
201
- # cache_examples="lazy",
202
- # )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
  # events
205
  run_btn.click(fn=local_get_reconstructed_scene,
 
17
  from tqdm import tqdm
18
  import cv2
19
  from PIL import Image
20
+ import os.path as path
21
+ import sys
22
 
23
  from dust3r.inference import inference
24
  from dust3r.model import AsymmetricCroCo3DStereo
 
34
  from huggingface_hub import hf_hub_download
35
  pl.ion()
36
 
37
+ HERE_PATH = path.normpath(path.dirname(__file__)) # noqa
38
+ sys.path.insert(0, HERE_PATH) # noqa
39
+
40
  # for gpu >= Ampere and pytorch >= 1.12
41
  torch.backends.cuda.matmul.allow_tf32 = True
42
  batch_size = 1
43
 
44
  tmpdirname = tempfile.mkdtemp(suffix='_align3r_gradio_demo')
45
  image_size = 512
46
+ silent = False
47
  gradio_delete_cache = 7200
48
+ print(f'{HERE_PATH}/third_party/ml-depth-pro/checkpoints/')
49
+ hf_hub_download(repo_id="apple/DepthPro", filename='depth_pro.pt', local_dir=f'{HERE_PATH}/third_party/ml-depth-pro/checkpoints/')
50
 
51
  class FileState:
52
  def __init__(self, outfile_name=None):
 
146
  loss = scene.compute_global_alignment(init='mst', niter=300, schedule='linear', lr=lr)
147
  # mode = GlobalAlignerMode.PairViewer
148
  # scene = global_aligner(output, device=device, mode=mode, verbose=not silent)
149
+
150
+ save_folder = './output/bear'
151
  os.makedirs(save_folder, exist_ok=True)
152
  outfile = get_3D_model_from_scene(save_folder, silent, scene, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size)
153
 
154
  return outfile
155
 
156
 
157
+ def run_example(snapshot, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size, depth_prior_name, inputfiles, **kw):
158
+ return local_get_reconstructed_scene(inputfiles, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size, depth_prior_name, **kw)
 
 
 
 
 
 
 
 
 
159
 
160
  css = """.gradio-container {margin: 0 !important; min-width: 100%};"""
161
  title = "Align3R Demo"
 
171
  snapshot = gradio.Image(None, visible=False)
172
  with gradio.Row():
173
  # adjust the camera size in the output pointcloud
174
+ cam_size = gradio.Slider(label="cam_size", value=0.02, minimum=0.001, maximum=1.0, step=0.001)
175
 
176
  depth_prior_name = gradio.Dropdown(
177
  ["Depth Pro", "Depth Anything V2"], label="monocular depth estimation model", info="Select the monocular depth estimation model.")
178
+ min_conf_thr = gradio.Slider(label="min_conf_thr", value=2, minimum=0.0, maximum=20, step=0.01)
179
  with gradio.Row():
180
  as_pointcloud = gradio.Checkbox(value=True, label="As pointcloud")
181
+ mask_sky = gradio.Checkbox(value=True, label="Mask sky")
182
  clean_depth = gradio.Checkbox(value=True, label="Clean-up depthmaps")
183
  transparent_cams = gradio.Checkbox(value=False, label="Transparent cameras")
184
  # not to show camera
 
186
  run_btn = gradio.Button("Run")
187
  outmodel = gradio.Model3D()
188
 
189
+ examples = gradio.Examples(
190
+ examples=[
191
+ [
192
+ os.path.join(HERE_PATH, 'example/bear/00000.jpg'),
193
+ 2, True, True, True, False, 0.02, "Depth Anything V2",
194
+ [os.path.join(HERE_PATH, 'example/bear/00000.jpg'),
195
+ os.path.join(HERE_PATH, 'example/bear/00001.jpg'),
196
+ os.path.join(HERE_PATH, 'example/bear/00002.jpg'),
197
+ os.path.join(HERE_PATH, 'example/bear/00003.jpg'),
198
+ os.path.join(HERE_PATH, 'example/bear/00004.jpg'),
199
+ os.path.join(HERE_PATH, 'example/bear/00005.jpg'),
200
+ os.path.join(HERE_PATH, 'example/bear/00006.jpg'),
201
+ os.path.join(HERE_PATH, 'example/bear/00007.jpg'),
202
+ os.path.join(HERE_PATH, 'example/bear/00008.jpg'),
203
+ os.path.join(HERE_PATH, 'example/bear/00009.jpg'),
204
+ ]
205
+ ],
206
+ [
207
+ os.path.join(HERE_PATH, 'example/breakdance/00000.jpg'),
208
+ 2, True, True, True, False, 0.02, "Depth Anything V2",
209
+ [os.path.join(HERE_PATH, 'example/breakdance/00000.jpg'),
210
+ os.path.join(HERE_PATH, 'example/breakdance/00001.jpg'),
211
+ os.path.join(HERE_PATH, 'example/breakdance/00002.jpg'),
212
+ os.path.join(HERE_PATH, 'example/breakdance/00003.jpg'),
213
+ os.path.join(HERE_PATH, 'example/breakdance/00004.jpg'),
214
+ os.path.join(HERE_PATH, 'example/breakdance/00005.jpg'),
215
+ os.path.join(HERE_PATH, 'example/breakdance/00006.jpg'),
216
+ os.path.join(HERE_PATH, 'example/breakdance/00007.jpg'),
217
+ os.path.join(HERE_PATH, 'example/breakdance/00008.jpg'),
218
+ os.path.join(HERE_PATH, 'example/breakdance/00009.jpg'),
219
+ ]
220
+ ],
221
+ [
222
+ os.path.join(HERE_PATH, 'example/tennis/00000.jpg'),
223
+ 2, True, True, True, False, 0.02, "Depth Anything V2",
224
+ [os.path.join(HERE_PATH, 'example/tennis/00000.jpg'),
225
+ os.path.join(HERE_PATH, 'example/tennis/00001.jpg'),
226
+ os.path.join(HERE_PATH, 'example/tennis/00002.jpg'),
227
+ os.path.join(HERE_PATH, 'example/tennis/00003.jpg'),
228
+ os.path.join(HERE_PATH, 'example/tennis/00004.jpg'),
229
+ os.path.join(HERE_PATH, 'example/tennis/00005.jpg'),
230
+ os.path.join(HERE_PATH, 'example/tennis/00006.jpg'),
231
+ os.path.join(HERE_PATH, 'example/tennis/00007.jpg'),
232
+ os.path.join(HERE_PATH, 'example/tennis/00008.jpg'),
233
+ os.path.join(HERE_PATH, 'example/tennis/00009.jpg'),
234
+ ]
235
+ ],
236
+ [
237
+ os.path.join(HERE_PATH, 'example/camel/00000.jpg'),
238
+ 2, True, True, True, False, 0.02, "Depth Anything V2",
239
+ [os.path.join(HERE_PATH, 'example/camel/00000.jpg'),
240
+ os.path.join(HERE_PATH, 'example/camel/00001.jpg'),
241
+ os.path.join(HERE_PATH, 'example/camel/00002.jpg'),
242
+ os.path.join(HERE_PATH, 'example/camel/00003.jpg'),
243
+ os.path.join(HERE_PATH, 'example/camel/00004.jpg'),
244
+ os.path.join(HERE_PATH, 'example/camel/00005.jpg'),
245
+ os.path.join(HERE_PATH, 'example/camel/00006.jpg'),
246
+ os.path.join(HERE_PATH, 'example/camel/00007.jpg'),
247
+ os.path.join(HERE_PATH, 'example/camel/00008.jpg'),
248
+ os.path.join(HERE_PATH, 'example/camel/00009.jpg'),
249
+ ]
250
+ ],
251
+ ],
252
+ inputs=[snapshot, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size, depth_prior_name, inputfiles],
253
+ outputs=[outmodel],
254
+ fn=run_example,
255
+ cache_examples="lazy",
256
+ )
257
 
258
  # events
259
  run_btn.click(fn=local_get_reconstructed_scene,
example/bear/00000.jpg ADDED
example/bear/00001.jpg ADDED
example/bear/00002.jpg ADDED
example/bear/00003.jpg ADDED
example/bear/00004.jpg ADDED
example/bear/00005.jpg ADDED
example/bear/00006.jpg ADDED
example/bear/00007.jpg ADDED
example/bear/00008.jpg ADDED
example/bear/00009.jpg ADDED
example/breakdance/00000.jpg ADDED
example/breakdance/00001.jpg ADDED
example/breakdance/00002.jpg ADDED
example/breakdance/00003.jpg ADDED
example/breakdance/00004.jpg ADDED
example/breakdance/00005.jpg ADDED
example/breakdance/00006.jpg ADDED
example/breakdance/00007.jpg ADDED
example/breakdance/00008.jpg ADDED
example/breakdance/00009.jpg ADDED
example/camel/00000.jpg ADDED
example/camel/00001.jpg ADDED
example/camel/00002.jpg ADDED
example/camel/00003.jpg ADDED
example/camel/00004.jpg ADDED
example/camel/00005.jpg ADDED
example/camel/00006.jpg ADDED
example/camel/00007.jpg ADDED
example/camel/00008.jpg ADDED
example/camel/00009.jpg ADDED
example/tennis/00000.jpg ADDED
example/tennis/00001.jpg ADDED
example/tennis/00002.jpg ADDED
example/tennis/00003.jpg ADDED
example/tennis/00004.jpg ADDED
example/tennis/00005.jpg ADDED
example/tennis/00006.jpg ADDED
example/tennis/00007.jpg ADDED
example/tennis/00008.jpg ADDED
example/tennis/00009.jpg ADDED
example/yellowman/frame_0003.png DELETED
Binary file (778 kB)
 
example/yellowman/frame_0014.png DELETED
Binary file (826 kB)