Commit
Β·
ae06e9d
1
Parent(s):
7998a5d
upload dexamples
Browse files- .gitattributes +2 -0
- app.py +35 -18
- clean_app.py +0 -229
- examples/british_museum/images/336.jpg +0 -3
- examples/british_museum/images/515.jpg +0 -3
- examples/british_museum/images/599.jpg +0 -3
- examples/british_museum/images/632.jpg +0 -3
- examples/british_museum/images/767.jpg +0 -3
- examples/british_museum/images/886.jpg +0 -3
- examples/cake_single/images/frame000020.jpg +0 -3
- examples/llff_horns_single/images/017.png +0 -3
- examples/room/images/{4.png β no_overlap_1.png} +0 -0
- examples/room/images/{IMG_1506.HEIC.JPG β no_overlap_2.HEIC.JPG} +0 -0
- examples/room/images/{IMG_1507.HEIC.JPG β no_overlap_3.HEIC.JPG} +0 -0
- examples/room/images/{IMG_1508.HEIC.JPG β no_overlap_4.HEIC.JPG} +0 -0
- examples/room/images/{IMG_1509.HEIC.JPG β no_overlap_5.HEIC.JPG} +0 -0
- examples/room/images/{IMG_1510.HEIC.JPG β no_overlap_6.HEIC.JPG} +0 -0
- examples/room/images/{IMG_1511.HEIC.JPG β no_overlap_7.HEIC.JPG} +0 -0
- examples/room/images/{IMG_1512.HEIC.JPG β no_overlap_8.HEIC.JPG} +0 -0
- examples/{british_museum/images/210.jpg β single_cartoon/images/model_was_never_trained_on_single_image_or_cartoon.jpg} +2 -2
- examples/{british_museum/images/069.jpg β single_oil_painting/images/model_was_never_trained_on_single_image_or_oil_painting.png} +2 -2
- examples/statue/images/000.jpg +0 -3
- examples/statue/images/002.jpg +0 -3
- examples/statue/images/004.jpg +0 -3
- examples/statue/images/006.jpg +0 -3
- examples/statue/images/008.jpg +0 -3
- examples/statue/images/010.jpg +0 -3
- examples/statue/images/012.jpg +0 -3
- examples/statue/images/014.jpg +0 -3
- examples/statue/images/016.jpg +0 -3
- examples/{british_museum/images/134.jpg β videos/single_cartoon.mp4} +2 -2
- examples/{british_museum/images/192.jpg β videos/single_oil_painting.mp4} +2 -2
- gradio_util.py +102 -9
- requirements.txt +1 -2
- skyseg.onnx +3 -0
.gitattributes
CHANGED
@@ -36,3 +36,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
36 |
examples/** filter=lfs diff=lfs merge=lfs -text
|
37 |
examples/videos/room_video.mp4 filter=lfs diff=lfs merge=lfs -text
|
38 |
examples/room/images/IMG_1506.HEIC.JPG filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
36 |
examples/** filter=lfs diff=lfs merge=lfs -text
|
37 |
examples/videos/room_video.mp4 filter=lfs diff=lfs merge=lfs -text
|
38 |
examples/room/images/IMG_1506.HEIC.JPG filter=lfs diff=lfs merge=lfs -text
|
39 |
+
skyseg.onnx filter=lfs diff=lfs merge=lfs -text
|
40 |
+
examples/ filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
@@ -48,7 +48,8 @@ def vggt_demo(
|
|
48 |
conf_thres=3.0,
|
49 |
frame_filter="all",
|
50 |
mask_black_bg=False,
|
51 |
-
show_cam=True
|
|
|
52 |
):
|
53 |
start_time = time.time()
|
54 |
gc.collect()
|
@@ -122,10 +123,10 @@ def vggt_demo(
|
|
122 |
np.savez(prediction_save_path, **predictions)
|
123 |
|
124 |
|
125 |
-
glbfile = target_dir + f"/glbscene_{conf_thres}_{frame_filter.replace('.', '_')}_mask{mask_black_bg}_cam{show_cam}.glb"
|
126 |
|
127 |
|
128 |
-
glbscene = demo_predictions_to_glb(predictions, conf_thres=conf_thres, filter_by_frames=frame_filter, mask_black_bg=mask_black_bg, show_cam=show_cam)
|
129 |
glbscene.export(file_obj=glbfile)
|
130 |
|
131 |
del predictions
|
@@ -162,7 +163,7 @@ def update_log():
|
|
162 |
|
163 |
|
164 |
|
165 |
-
def update_visualization(target_dir, conf_thres, frame_filter, mask_black_bg, show_cam):
|
166 |
# Return early if target_dir is None, "None", empty string, or otherwise invalid
|
167 |
# Check if the predictions file exists
|
168 |
predictions_path = f"{target_dir}/predictions.npz"
|
@@ -179,10 +180,10 @@ def update_visualization(target_dir, conf_thres, frame_filter, mask_black_bg, sh
|
|
179 |
# for key in predictions.files: print(key)
|
180 |
predictions = {key: loaded[key] for key in loaded.keys()}
|
181 |
|
182 |
-
glbfile = target_dir + f"/glbscene_{conf_thres}_{frame_filter.replace('.', '_')}_mask{mask_black_bg}_cam{show_cam}.glb"
|
183 |
|
184 |
if not os.path.exists(glbfile):
|
185 |
-
glbscene = demo_predictions_to_glb(predictions, conf_thres=conf_thres, filter_by_frames=frame_filter, mask_black_bg=mask_black_bg, show_cam=show_cam)
|
186 |
glbscene.export(file_obj=glbfile)
|
187 |
return glbfile, "Updating Visualization", target_dir
|
188 |
|
@@ -214,6 +215,11 @@ drums_video = "examples/videos/drums_video.mp4"
|
|
214 |
kitchen_video = "examples/videos/kitchen_video.mp4"
|
215 |
|
216 |
room_video = "examples/videos/room_video.mp4"
|
|
|
|
|
|
|
|
|
|
|
217 |
###########################################################################################
|
218 |
apple_images = glob.glob(f'examples/apple/images/*')
|
219 |
bonsai_images = glob.glob(f'examples/bonsai/images/*')
|
@@ -233,7 +239,8 @@ statue_images = glob.glob(f'examples/statue/images/*')
|
|
233 |
drums_images = glob.glob(f'examples/drums/images/*')
|
234 |
kitchen_images = glob.glob(f'examples/kitchen/images/*')
|
235 |
room_images = glob.glob(f'examples/room/images/*')
|
236 |
-
|
|
|
237 |
###########################################################################################
|
238 |
|
239 |
|
@@ -281,6 +288,7 @@ with gr.Blocks(css="""
|
|
281 |
with gr.Column():
|
282 |
show_cam = gr.Checkbox(label="Show Camera", value=True)
|
283 |
mask_black_bg = gr.Checkbox(label="Filter Black Background", value=False)
|
|
|
284 |
|
285 |
# Add a hidden textbox for target_dir with default value "None"
|
286 |
target_dir_output = gr.Textbox(label="Target Dir", visible=False, value="None")
|
@@ -296,15 +304,18 @@ with gr.Blocks(css="""
|
|
296 |
|
297 |
|
298 |
examples = [
|
299 |
-
[
|
300 |
-
[
|
301 |
-
[
|
302 |
-
[
|
303 |
-
[
|
|
|
|
|
|
|
304 |
]
|
305 |
|
306 |
gr.Examples(examples=examples,
|
307 |
-
inputs=[input_video, input_images, conf_thres, frame_filter, mask_black_bg, show_cam],
|
308 |
outputs=[reconstruction_output, log_output, target_dir_output, frame_filter], # Added frame_filter
|
309 |
fn=vggt_demo, # Use our wrapper function
|
310 |
cache_examples=False,
|
@@ -322,7 +333,7 @@ with gr.Blocks(css="""
|
|
322 |
outputs=[log_output]
|
323 |
).then(
|
324 |
fn=vggt_demo,
|
325 |
-
inputs=[input_video, input_images, conf_thres, frame_filter, mask_black_bg, show_cam],
|
326 |
outputs=[reconstruction_output, log_output, target_dir_output, frame_filter]
|
327 |
)
|
328 |
|
@@ -330,25 +341,31 @@ with gr.Blocks(css="""
|
|
330 |
# Add event handlers for automatic updates when parameters change
|
331 |
conf_thres.change(
|
332 |
update_visualization,
|
333 |
-
[target_dir_output, conf_thres, frame_filter, mask_black_bg, show_cam],
|
334 |
[reconstruction_output, log_output, target_dir_output],
|
335 |
)
|
336 |
|
337 |
frame_filter.change(
|
338 |
update_visualization,
|
339 |
-
[target_dir_output, conf_thres, frame_filter, mask_black_bg, show_cam],
|
340 |
[reconstruction_output, log_output, target_dir_output],
|
341 |
)
|
342 |
|
343 |
mask_black_bg.change(
|
344 |
update_visualization,
|
345 |
-
[target_dir_output, conf_thres, frame_filter, mask_black_bg, show_cam],
|
346 |
[reconstruction_output, log_output, target_dir_output],
|
347 |
)
|
348 |
|
349 |
show_cam.change(
|
350 |
update_visualization,
|
351 |
-
[target_dir_output, conf_thres, frame_filter, mask_black_bg, show_cam],
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
[reconstruction_output, log_output, target_dir_output],
|
353 |
)
|
354 |
|
|
|
48 |
conf_thres=3.0,
|
49 |
frame_filter="all",
|
50 |
mask_black_bg=False,
|
51 |
+
show_cam=True,
|
52 |
+
mask_sky=False
|
53 |
):
|
54 |
start_time = time.time()
|
55 |
gc.collect()
|
|
|
123 |
np.savez(prediction_save_path, **predictions)
|
124 |
|
125 |
|
126 |
+
glbfile = target_dir + f"/glbscene_{conf_thres}_{frame_filter.replace('.', '_')}_mask{mask_black_bg}_cam{show_cam}_sky{mask_sky}.glb"
|
127 |
|
128 |
|
129 |
+
glbscene = demo_predictions_to_glb(predictions, conf_thres=conf_thres, filter_by_frames=frame_filter, mask_black_bg=mask_black_bg, show_cam=show_cam, mask_sky=mask_sky, target_dir=target_dir)
|
130 |
glbscene.export(file_obj=glbfile)
|
131 |
|
132 |
del predictions
|
|
|
163 |
|
164 |
|
165 |
|
166 |
+
def update_visualization(target_dir, conf_thres, frame_filter, mask_black_bg, show_cam, mask_sky):
|
167 |
# Return early if target_dir is None, "None", empty string, or otherwise invalid
|
168 |
# Check if the predictions file exists
|
169 |
predictions_path = f"{target_dir}/predictions.npz"
|
|
|
180 |
# for key in predictions.files: print(key)
|
181 |
predictions = {key: loaded[key] for key in loaded.keys()}
|
182 |
|
183 |
+
glbfile = target_dir + f"/glbscene_{conf_thres}_{frame_filter.replace('.', '_')}_mask{mask_black_bg}_cam{show_cam}_sky{mask_sky}.glb"
|
184 |
|
185 |
if not os.path.exists(glbfile):
|
186 |
+
glbscene = demo_predictions_to_glb(predictions, conf_thres=conf_thres, filter_by_frames=frame_filter, mask_black_bg=mask_black_bg, show_cam=show_cam, mask_sky=mask_sky, target_dir=target_dir)
|
187 |
glbscene.export(file_obj=glbfile)
|
188 |
return glbfile, "Updating Visualization", target_dir
|
189 |
|
|
|
215 |
kitchen_video = "examples/videos/kitchen_video.mp4"
|
216 |
|
217 |
room_video = "examples/videos/room_video.mp4"
|
218 |
+
|
219 |
+
# Add the new video examples
|
220 |
+
single_cartoon_video = "examples/videos/single_cartoon.mp4"
|
221 |
+
single_oil_painting_video = "examples/videos/single_oil_painting.mp4"
|
222 |
+
|
223 |
###########################################################################################
|
224 |
apple_images = glob.glob(f'examples/apple/images/*')
|
225 |
bonsai_images = glob.glob(f'examples/bonsai/images/*')
|
|
|
239 |
drums_images = glob.glob(f'examples/drums/images/*')
|
240 |
kitchen_images = glob.glob(f'examples/kitchen/images/*')
|
241 |
room_images = glob.glob(f'examples/room/images/*')
|
242 |
+
single_cartoon_images = glob.glob(f'examples/single_cartoon/images/*')
|
243 |
+
single_oil_painting_images = glob.glob(f'examples/single_oil_painting/images/*')
|
244 |
###########################################################################################
|
245 |
|
246 |
|
|
|
288 |
with gr.Column():
|
289 |
show_cam = gr.Checkbox(label="Show Camera", value=True)
|
290 |
mask_black_bg = gr.Checkbox(label="Filter Black Background", value=False)
|
291 |
+
mask_sky = gr.Checkbox(label="Filter Sky", value=False)
|
292 |
|
293 |
# Add a hidden textbox for target_dir with default value "None"
|
294 |
target_dir_output = gr.Textbox(label="Target Dir", visible=False, value="None")
|
|
|
304 |
|
305 |
|
306 |
examples = [
|
307 |
+
[single_cartoon_video, single_cartoon_images, 0.5, "All", False, True, False],
|
308 |
+
[single_oil_painting_video, single_oil_painting_images, 0.5, "All", False, True, True],
|
309 |
+
[room_video, room_images, 1.1, "All", False, True, False],
|
310 |
+
[counter_video, counter_images, 1.5, "All", False, True, False],
|
311 |
+
[flower_video, flower_images, 1.5, "All", False, True, False],
|
312 |
+
[kitchen_video, kitchen_images, 3, "All", False, True, False],
|
313 |
+
[fern_video, fern_images, 1.5, "All", False, True, False],
|
314 |
+
# Add the new examples
|
315 |
]
|
316 |
|
317 |
gr.Examples(examples=examples,
|
318 |
+
inputs=[input_video, input_images, conf_thres, frame_filter, mask_black_bg, show_cam, mask_sky],
|
319 |
outputs=[reconstruction_output, log_output, target_dir_output, frame_filter], # Added frame_filter
|
320 |
fn=vggt_demo, # Use our wrapper function
|
321 |
cache_examples=False,
|
|
|
333 |
outputs=[log_output]
|
334 |
).then(
|
335 |
fn=vggt_demo,
|
336 |
+
inputs=[input_video, input_images, conf_thres, frame_filter, mask_black_bg, show_cam, mask_sky],
|
337 |
outputs=[reconstruction_output, log_output, target_dir_output, frame_filter]
|
338 |
)
|
339 |
|
|
|
341 |
# Add event handlers for automatic updates when parameters change
|
342 |
conf_thres.change(
|
343 |
update_visualization,
|
344 |
+
[target_dir_output, conf_thres, frame_filter, mask_black_bg, show_cam, mask_sky],
|
345 |
[reconstruction_output, log_output, target_dir_output],
|
346 |
)
|
347 |
|
348 |
frame_filter.change(
|
349 |
update_visualization,
|
350 |
+
[target_dir_output, conf_thres, frame_filter, mask_black_bg, show_cam, mask_sky],
|
351 |
[reconstruction_output, log_output, target_dir_output],
|
352 |
)
|
353 |
|
354 |
mask_black_bg.change(
|
355 |
update_visualization,
|
356 |
+
[target_dir_output, conf_thres, frame_filter, mask_black_bg, show_cam, mask_sky],
|
357 |
[reconstruction_output, log_output, target_dir_output],
|
358 |
)
|
359 |
|
360 |
show_cam.change(
|
361 |
update_visualization,
|
362 |
+
[target_dir_output, conf_thres, frame_filter, mask_black_bg, show_cam, mask_sky],
|
363 |
+
[reconstruction_output, log_output, target_dir_output],
|
364 |
+
)
|
365 |
+
|
366 |
+
mask_sky.change(
|
367 |
+
update_visualization,
|
368 |
+
[target_dir_output, conf_thres, frame_filter, mask_black_bg, show_cam, mask_sky],
|
369 |
[reconstruction_output, log_output, target_dir_output],
|
370 |
)
|
371 |
|
clean_app.py
DELETED
@@ -1,229 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import cv2
|
3 |
-
import torch
|
4 |
-
import numpy as np
|
5 |
-
import gradio as gr
|
6 |
-
import sys
|
7 |
-
import os
|
8 |
-
import socket
|
9 |
-
import webbrowser
|
10 |
-
sys.path.append('vggt/')
|
11 |
-
import shutil
|
12 |
-
from datetime import datetime
|
13 |
-
from demo_hf import demo_fn
|
14 |
-
from omegaconf import DictConfig, OmegaConf
|
15 |
-
import glob
|
16 |
-
import gc
|
17 |
-
import time
|
18 |
-
from viser_fn import viser_wrapper
|
19 |
-
|
20 |
-
|
21 |
-
def get_free_port():
|
22 |
-
"""Get a free port using socket."""
|
23 |
-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
24 |
-
s.bind(('', 0))
|
25 |
-
port = s.getsockname()[1]
|
26 |
-
return port
|
27 |
-
|
28 |
-
def vggt_demo(
|
29 |
-
input_video,
|
30 |
-
input_image,
|
31 |
-
):
|
32 |
-
start_time = time.time()
|
33 |
-
gc.collect()
|
34 |
-
torch.cuda.empty_cache()
|
35 |
-
|
36 |
-
|
37 |
-
debug = False
|
38 |
-
|
39 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
40 |
-
target_dir = f"input_images_{timestamp}"
|
41 |
-
if os.path.exists(target_dir):
|
42 |
-
shutil.rmtree(target_dir)
|
43 |
-
|
44 |
-
os.makedirs(target_dir)
|
45 |
-
target_dir_images = target_dir + "/images"
|
46 |
-
os.makedirs(target_dir_images)
|
47 |
-
|
48 |
-
|
49 |
-
if input_video is not None:
|
50 |
-
if not isinstance(input_video, str):
|
51 |
-
input_video = input_video["video"]["path"]
|
52 |
-
|
53 |
-
cfg_file = "config/base.yaml"
|
54 |
-
cfg = OmegaConf.load(cfg_file)
|
55 |
-
|
56 |
-
if input_image is not None:
|
57 |
-
input_image = sorted(input_image)
|
58 |
-
# recon_num = len(input_image)
|
59 |
-
|
60 |
-
# Copy files to the new directory
|
61 |
-
for file_name in input_image:
|
62 |
-
shutil.copy(file_name, target_dir_images)
|
63 |
-
elif input_video is not None:
|
64 |
-
vs = cv2.VideoCapture(input_video)
|
65 |
-
|
66 |
-
fps = vs.get(cv2.CAP_PROP_FPS)
|
67 |
-
|
68 |
-
frame_rate = 1
|
69 |
-
frame_interval = int(fps * frame_rate)
|
70 |
-
|
71 |
-
video_frame_num = 0
|
72 |
-
count = 0
|
73 |
-
|
74 |
-
while True:
|
75 |
-
(gotit, frame) = vs.read()
|
76 |
-
count +=1
|
77 |
-
|
78 |
-
if not gotit:
|
79 |
-
break
|
80 |
-
|
81 |
-
if count % frame_interval == 0:
|
82 |
-
cv2.imwrite(target_dir_images+"/"+f"{video_frame_num:06}.png", frame)
|
83 |
-
video_frame_num+=1
|
84 |
-
else:
|
85 |
-
return None, "Uploading not finished or Incorrect input format"
|
86 |
-
|
87 |
-
|
88 |
-
print(f"Files have been copied to {target_dir_images}")
|
89 |
-
cfg.SCENE_DIR = target_dir
|
90 |
-
|
91 |
-
predictions = demo_fn(cfg)
|
92 |
-
|
93 |
-
# Get a free port for viser
|
94 |
-
viser_port = get_free_port()
|
95 |
-
|
96 |
-
# Start viser visualization in a separate thread/process
|
97 |
-
viser_wrapper(predictions, port=viser_port)
|
98 |
-
|
99 |
-
del predictions
|
100 |
-
gc.collect()
|
101 |
-
torch.cuda.empty_cache()
|
102 |
-
|
103 |
-
print(input_image)
|
104 |
-
print(input_video)
|
105 |
-
end_time = time.time()
|
106 |
-
execution_time = end_time - start_time
|
107 |
-
print(f"Execution time: {execution_time} seconds")
|
108 |
-
return None, viser_port
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
statue_video = "examples/videos/statue_video.mp4"
|
114 |
-
|
115 |
-
apple_video = "examples/videos/apple_video.mp4"
|
116 |
-
british_museum_video = "examples/videos/british_museum_video.mp4"
|
117 |
-
cake_video = "examples/videos/cake_video.mp4"
|
118 |
-
bonsai_video = "examples/videos/bonsai_video.mp4"
|
119 |
-
face_video = "examples/videos/in2n_face_video.mp4"
|
120 |
-
counter_video = "examples/videos/in2n_counter_video.mp4"
|
121 |
-
|
122 |
-
horns_video = "examples/videos/llff_horns_video.mp4"
|
123 |
-
person_video = "examples/videos/in2n_person_video.mp4"
|
124 |
-
|
125 |
-
flower_video = "examples/videos/llff_flower_video.mp4"
|
126 |
-
|
127 |
-
fern_video = "examples/videos/llff_fern_video.mp4"
|
128 |
-
|
129 |
-
drums_video = "examples/videos/drums_video.mp4"
|
130 |
-
|
131 |
-
kitchen_video = "examples/videos/kitchen_video.mp4"
|
132 |
-
|
133 |
-
###########################################################################################
|
134 |
-
apple_images = glob.glob(f'examples/apple/images/*')
|
135 |
-
bonsai_images = glob.glob(f'examples/bonsai/images/*')
|
136 |
-
cake_images = glob.glob(f'examples/cake/images/*')
|
137 |
-
british_museum_images = glob.glob(f'examples/british_museum/images/*')
|
138 |
-
face_images = glob.glob(f'examples/in2n_face/images/*')
|
139 |
-
counter_images = glob.glob(f'examples/in2n_counter/images/*')
|
140 |
-
|
141 |
-
horns_images = glob.glob(f'examples/llff_horns/images/*')
|
142 |
-
|
143 |
-
person_images = glob.glob(f'examples/in2n_person/images/*')
|
144 |
-
flower_images = glob.glob(f'examples/llff_flower/images/*')
|
145 |
-
|
146 |
-
fern_images = glob.glob(f'examples/llff_fern/images/*')
|
147 |
-
statue_images = glob.glob(f'examples/statue/images/*')
|
148 |
-
|
149 |
-
drums_images = glob.glob(f'examples/drums/images/*')
|
150 |
-
kitchen_images = glob.glob(f'examples/kitchen/images/*')
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
###########################################################################################
|
155 |
-
|
156 |
-
|
157 |
-
with gr.Blocks() as demo:
|
158 |
-
|
159 |
-
gr.Markdown("""
|
160 |
-
# ποΈ VGGT: Visual Geometry Grounded Transformer
|
161 |
-
|
162 |
-
<div style="font-size: 16px; line-height: 1.2;">
|
163 |
-
Alpha version (testing).
|
164 |
-
</div>
|
165 |
-
""")
|
166 |
-
|
167 |
-
with gr.Row():
|
168 |
-
with gr.Column(scale=1):
|
169 |
-
input_video = gr.Video(label="Upload Video", interactive=True)
|
170 |
-
input_images = gr.File(file_count="multiple", label="Upload Images", interactive=True)
|
171 |
-
|
172 |
-
|
173 |
-
with gr.Column(scale=3):
|
174 |
-
viser_output = gr.HTML(
|
175 |
-
label="Viser Visualization",
|
176 |
-
value='''<div style="height: 520px; border: 1px solid #e0e0e0;
|
177 |
-
border-radius: 4px; padding: 16px;
|
178 |
-
display: flex; align-items: center;
|
179 |
-
justify-content: center">
|
180 |
-
3D Reconstruction (Point Cloud and Camera Poses; Zoom in to see details)
|
181 |
-
</div>'''
|
182 |
-
)
|
183 |
-
|
184 |
-
log_output = gr.Textbox(label="Log")
|
185 |
-
|
186 |
-
with gr.Row():
|
187 |
-
submit_btn = gr.Button("Reconstruct", scale=1)
|
188 |
-
clear_btn = gr.ClearButton([input_video, input_images, viser_output, log_output], scale=1) #Modified viser_output
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
examples = [
|
194 |
-
[flower_video, flower_images],
|
195 |
-
[kitchen_video, kitchen_images],
|
196 |
-
[counter_video, counter_images],
|
197 |
-
[fern_video, fern_images],
|
198 |
-
[horns_video, horns_images],
|
199 |
-
]
|
200 |
-
|
201 |
-
def process_example(video, images):
|
202 |
-
"""Wrapper function to ensure outputs are properly captured"""
|
203 |
-
model_output, log = vggt_demo(video, images)
|
204 |
-
|
205 |
-
viser_url = f"http://localhost:{log}"
|
206 |
-
print(f"Viser URL: {viser_url}")
|
207 |
-
|
208 |
-
# Create the iframe HTML code. Set width and height appropriately.
|
209 |
-
iframe_code = f'<iframe src="{viser_url}" width="100%" height="520px"></iframe>'
|
210 |
-
|
211 |
-
return iframe_code, f"Visualization running at {viser_url}"
|
212 |
-
|
213 |
-
gr.Examples(examples=examples,
|
214 |
-
inputs=[input_video, input_images],
|
215 |
-
outputs=[viser_output, log_output], # Output to viser_output
|
216 |
-
fn=process_example, # Use our wrapper function
|
217 |
-
cache_examples=False,
|
218 |
-
examples_per_page=50,
|
219 |
-
)
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
submit_btn.click(
|
224 |
-
process_example, # Use the same wrapper function
|
225 |
-
[input_video, input_images],
|
226 |
-
[viser_output, log_output], # Output to viser_output
|
227 |
-
concurrency_limit=1
|
228 |
-
)
|
229 |
-
demo.queue(max_size=20).launch(show_error=True, share=True, server_port=7888, server_name="0.0.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
examples/british_museum/images/336.jpg
DELETED
Git LFS Details
|
examples/british_museum/images/515.jpg
DELETED
Git LFS Details
|
examples/british_museum/images/599.jpg
DELETED
Git LFS Details
|
examples/british_museum/images/632.jpg
DELETED
Git LFS Details
|
examples/british_museum/images/767.jpg
DELETED
Git LFS Details
|
examples/british_museum/images/886.jpg
DELETED
Git LFS Details
|
examples/cake_single/images/frame000020.jpg
DELETED
Git LFS Details
|
examples/llff_horns_single/images/017.png
DELETED
Git LFS Details
|
examples/room/images/{4.png β no_overlap_1.png}
RENAMED
File without changes
|
examples/room/images/{IMG_1506.HEIC.JPG β no_overlap_2.HEIC.JPG}
RENAMED
File without changes
|
examples/room/images/{IMG_1507.HEIC.JPG β no_overlap_3.HEIC.JPG}
RENAMED
File without changes
|
examples/room/images/{IMG_1508.HEIC.JPG β no_overlap_4.HEIC.JPG}
RENAMED
File without changes
|
examples/room/images/{IMG_1509.HEIC.JPG β no_overlap_5.HEIC.JPG}
RENAMED
File without changes
|
examples/room/images/{IMG_1510.HEIC.JPG β no_overlap_6.HEIC.JPG}
RENAMED
File without changes
|
examples/room/images/{IMG_1511.HEIC.JPG β no_overlap_7.HEIC.JPG}
RENAMED
File without changes
|
examples/room/images/{IMG_1512.HEIC.JPG β no_overlap_8.HEIC.JPG}
RENAMED
File without changes
|
examples/{british_museum/images/210.jpg β single_cartoon/images/model_was_never_trained_on_single_image_or_cartoon.jpg}
RENAMED
File without changes
|
examples/{british_museum/images/069.jpg β single_oil_painting/images/model_was_never_trained_on_single_image_or_oil_painting.png}
RENAMED
File without changes
|
examples/statue/images/000.jpg
DELETED
Git LFS Details
|
examples/statue/images/002.jpg
DELETED
Git LFS Details
|
examples/statue/images/004.jpg
DELETED
Git LFS Details
|
examples/statue/images/006.jpg
DELETED
Git LFS Details
|
examples/statue/images/008.jpg
DELETED
Git LFS Details
|
examples/statue/images/010.jpg
DELETED
Git LFS Details
|
examples/statue/images/012.jpg
DELETED
Git LFS Details
|
examples/statue/images/014.jpg
DELETED
Git LFS Details
|
examples/statue/images/016.jpg
DELETED
Git LFS Details
|
examples/{british_museum/images/134.jpg β videos/single_cartoon.mp4}
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b5418685a991dc3dba680cc1e2708214f479fc658ddb712344edc4274d373548
|
3 |
+
size 228582
|
examples/{british_museum/images/192.jpg β videos/single_oil_painting.mp4}
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:97c3ab94b7970cbe7960eb2bedf8a38343a909db035d4776aff5ba51cb3daa65
|
3 |
+
size 794368
|
gradio_util.py
CHANGED
@@ -7,16 +7,12 @@ import gradio as gr
|
|
7 |
import numpy as np
|
8 |
import matplotlib
|
9 |
from scipy.spatial.transform import Rotation
|
|
|
|
|
|
|
10 |
|
11 |
-
# except:
|
12 |
-
# print(
|
13 |
-
# f"Failed to import packages for Gradio visualization. Please disable gradio visualization"
|
14 |
-
# )
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
def demo_predictions_to_glb(predictions, conf_thres=3.0, filter_by_frames="all", mask_black_bg=False, show_cam=True) -> trimesh.Scene:
|
20 |
"""
|
21 |
Converts VGG SFM predictions to a 3D scene represented as a GLB.
|
22 |
|
@@ -29,6 +25,10 @@ def demo_predictions_to_glb(predictions, conf_thres=3.0, filter_by_frames="all",
|
|
29 |
# Convert predictions to numpy arrays
|
30 |
# pred_extrinsic_list', 'pred_world_points', 'pred_world_points_conf', 'images', 'last_pred_extrinsic
|
31 |
|
|
|
|
|
|
|
|
|
32 |
print("Building GLB scene")
|
33 |
selected_frame_idx = None
|
34 |
if filter_by_frames != "all":
|
@@ -36,7 +36,6 @@ def demo_predictions_to_glb(predictions, conf_thres=3.0, filter_by_frames="all",
|
|
36 |
# Extract the index part before the colon
|
37 |
selected_frame_idx = int(filter_by_frames.split(":")[0])
|
38 |
except (ValueError, IndexError):
|
39 |
-
# If parsing fails, default to using all frames
|
40 |
pass
|
41 |
|
42 |
pred_world_points = predictions["pred_world_points"][0] # remove batch dimension
|
@@ -45,6 +44,48 @@ def demo_predictions_to_glb(predictions, conf_thres=3.0, filter_by_frames="all",
|
|
45 |
last_pred_extrinsic = predictions["last_pred_extrinsic"][0]
|
46 |
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
if selected_frame_idx is not None:
|
49 |
pred_world_points = pred_world_points[selected_frame_idx][None]
|
50 |
pred_world_points_conf = pred_world_points_conf[selected_frame_idx][None]
|
@@ -294,3 +335,55 @@ def compute_camera_faces(cone_shape: trimesh.Trimesh) -> np.ndarray:
|
|
294 |
|
295 |
faces_list += [(v3, v2, v1) for v1, v2, v3 in faces_list]
|
296 |
return np.array(faces_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
import numpy as np
|
8 |
import matplotlib
|
9 |
from scipy.spatial.transform import Rotation
|
10 |
+
import copy
|
11 |
+
import cv2
|
12 |
+
import os
|
13 |
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
def demo_predictions_to_glb(predictions, conf_thres=3.0, filter_by_frames="all", mask_black_bg=False, show_cam=True, mask_sky=False, target_dir=None) -> trimesh.Scene:
|
|
|
|
|
|
|
16 |
"""
|
17 |
Converts VGG SFM predictions to a 3D scene represented as a GLB.
|
18 |
|
|
|
25 |
# Convert predictions to numpy arrays
|
26 |
# pred_extrinsic_list', 'pred_world_points', 'pred_world_points_conf', 'images', 'last_pred_extrinsic
|
27 |
|
28 |
+
|
29 |
+
if conf_thres is None:
|
30 |
+
conf_thres = 0.0
|
31 |
+
|
32 |
print("Building GLB scene")
|
33 |
selected_frame_idx = None
|
34 |
if filter_by_frames != "all":
|
|
|
36 |
# Extract the index part before the colon
|
37 |
selected_frame_idx = int(filter_by_frames.split(":")[0])
|
38 |
except (ValueError, IndexError):
|
|
|
39 |
pass
|
40 |
|
41 |
pred_world_points = predictions["pred_world_points"][0] # remove batch dimension
|
|
|
44 |
last_pred_extrinsic = predictions["last_pred_extrinsic"][0]
|
45 |
|
46 |
|
47 |
+
if mask_sky:
|
48 |
+
if target_dir is not None:
|
49 |
+
import onnxruntime
|
50 |
+
skyseg_session = None
|
51 |
+
target_dir_images = target_dir + "/images"
|
52 |
+
image_list = sorted(os.listdir(target_dir_images))
|
53 |
+
sky_mask_list = []
|
54 |
+
|
55 |
+
# Get the shape of pred_world_points_conf to match
|
56 |
+
S, H, W = pred_world_points_conf.shape
|
57 |
+
|
58 |
+
for i, image_name in enumerate(image_list):
|
59 |
+
image_filepath = os.path.join(target_dir_images, image_name)
|
60 |
+
mask_filepath = os.path.join(target_dir, "sky_masks", image_name)
|
61 |
+
|
62 |
+
# Check if mask already exists
|
63 |
+
if os.path.exists(mask_filepath):
|
64 |
+
# Load existing mask
|
65 |
+
sky_mask = cv2.imread(mask_filepath, cv2.IMREAD_GRAYSCALE)
|
66 |
+
else:
|
67 |
+
# Generate new mask
|
68 |
+
if skyseg_session is None:
|
69 |
+
skyseg_session = onnxruntime.InferenceSession("skyseg.onnx")
|
70 |
+
sky_mask = segment_sky(image_filepath, skyseg_session, mask_filepath)
|
71 |
+
|
72 |
+
# Resize mask to match HΓW if needed
|
73 |
+
if sky_mask.shape[0] != H or sky_mask.shape[1] != W:
|
74 |
+
sky_mask = cv2.resize(sky_mask, (W, H))
|
75 |
+
|
76 |
+
# model_was_never_trained_on_single_image_or_oil_painting
|
77 |
+
# no overlap
|
78 |
+
# single view, youhua
|
79 |
+
# single view, catoon
|
80 |
+
sky_mask_list.append(sky_mask)
|
81 |
+
|
82 |
+
# Convert list to numpy array with shape SΓHΓW
|
83 |
+
sky_mask_array = np.array(sky_mask_list)
|
84 |
+
|
85 |
+
# Apply sky mask to confidence scores
|
86 |
+
sky_mask_binary = (sky_mask_array > 0.01).astype(np.float32)
|
87 |
+
pred_world_points_conf = pred_world_points_conf * sky_mask_binary
|
88 |
+
|
89 |
if selected_frame_idx is not None:
|
90 |
pred_world_points = pred_world_points[selected_frame_idx][None]
|
91 |
pred_world_points_conf = pred_world_points_conf[selected_frame_idx][None]
|
|
|
335 |
|
336 |
faces_list += [(v3, v2, v1) for v1, v2, v3 in faces_list]
|
337 |
return np.array(faces_list)
|
338 |
+
|
339 |
+
|
340 |
+
|
341 |
+
|
342 |
+
def segment_sky(image_path, onnx_session, mask_filename=None):
|
343 |
+
assert mask_filename is not None
|
344 |
+
image = cv2.imread(image_path)
|
345 |
+
|
346 |
+
result_map = run_skyseg(onnx_session,[320,320],image)
|
347 |
+
# resize the result_map to the original image size
|
348 |
+
result_map_original = cv2.resize(result_map, (image.shape[1], image.shape[0]))
|
349 |
+
|
350 |
+
output_mask = np.zeros_like(result_map_original)
|
351 |
+
output_mask[result_map_original<1] = 1
|
352 |
+
output_mask = output_mask.astype(np.uint8) * 255
|
353 |
+
os.makedirs(os.path.dirname(mask_filename), exist_ok=True)
|
354 |
+
cv2.imwrite(mask_filename, output_mask)
|
355 |
+
return output_mask
|
356 |
+
|
357 |
+
|
358 |
+
|
359 |
+
|
360 |
+
|
361 |
+
def run_skyseg(onnx_session, input_size, image):
|
362 |
+
# Pre process:Resize, BGR->RGB, Transpose, PyTorch standardization, float32 cast
|
363 |
+
temp_image = copy.deepcopy(image)
|
364 |
+
resize_image = cv2.resize(temp_image, dsize=(input_size[0], input_size[1]))
|
365 |
+
x = cv2.cvtColor(resize_image, cv2.COLOR_BGR2RGB)
|
366 |
+
x = np.array(x, dtype=np.float32)
|
367 |
+
mean = [0.485, 0.456, 0.406]
|
368 |
+
std = [0.229, 0.224, 0.225]
|
369 |
+
x = (x / 255 - mean) / std
|
370 |
+
x = x.transpose(2, 0, 1)
|
371 |
+
x = x.reshape(-1, 3, input_size[0], input_size[1]).astype('float32')
|
372 |
+
|
373 |
+
# Inference
|
374 |
+
input_name = onnx_session.get_inputs()[0].name
|
375 |
+
output_name = onnx_session.get_outputs()[0].name
|
376 |
+
onnx_result = onnx_session.run([output_name], {input_name: x})
|
377 |
+
|
378 |
+
# Post process
|
379 |
+
onnx_result = np.array(onnx_result).squeeze()
|
380 |
+
min_value = np.min(onnx_result)
|
381 |
+
max_value = np.max(onnx_result)
|
382 |
+
onnx_result = (onnx_result - min_value) / (max_value - min_value)
|
383 |
+
onnx_result *= 255
|
384 |
+
onnx_result = onnx_result.astype('uint8')
|
385 |
+
|
386 |
+
return onnx_result
|
387 |
+
|
388 |
+
|
389 |
+
|
requirements.txt
CHANGED
@@ -9,8 +9,7 @@ numpy==1.26.3
|
|
9 |
viser
|
10 |
trimesh
|
11 |
matplotlib
|
12 |
-
|
13 |
-
|
14 |
|
15 |
|
16 |
# accelerate==0.24.0
|
|
|
9 |
viser
|
10 |
trimesh
|
11 |
matplotlib
|
12 |
+
onnxruntime
|
|
|
13 |
|
14 |
|
15 |
# accelerate==0.24.0
|
skyseg.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ab9c34c64c3d821220a2886a4a06da4642ffa14d5b30e8d5339056a089aa1d39
|
3 |
+
size 175997079
|