init project
Browse files
app.py
CHANGED
|
@@ -519,21 +519,21 @@ def get_reconstructed_scene(outdir, filelist, schedule, niter, min_conf_thr,
|
|
| 519 |
|
| 520 |
return scene, outfile#, imgs
|
| 521 |
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
|
| 538 |
|
| 539 |
def set_scenegraph_options(inputfiles, winsize, refid, scenegraph_type):
|
|
@@ -560,7 +560,7 @@ def set_scenegraph_options(inputfiles, winsize, refid, scenegraph_type):
|
|
| 560 |
with tempfile.TemporaryDirectory(suffix='pe3r_gradio_demo') as tmpdirname:
|
| 561 |
recon_fun = functools.partial(get_reconstructed_scene, tmpdirname)
|
| 562 |
model_from_scene_fun = functools.partial(get_3D_model_from_scene, tmpdirname)
|
| 563 |
-
|
| 564 |
|
| 565 |
with gradio.Blocks(css=""".gradio-container {margin: 0 !important; min-width: 100%};""", title="PE3R Demo") as demo:
|
| 566 |
# scene state is save so that you can change conf_thr, cam_size... without rerunning the inference
|
|
@@ -646,8 +646,8 @@ with tempfile.TemporaryDirectory(suffix='pe3r_gradio_demo') as tmpdirname:
|
|
| 646 |
inputs=[scene, min_conf_thr, as_pointcloud, mask_sky,
|
| 647 |
clean_depth, transparent_cams, cam_size],
|
| 648 |
outputs=outmodel)
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
demo.launch(show_error=True, share=None, server_name=None, server_port=None)
|
|
|
|
| 519 |
|
| 520 |
return scene, outfile#, imgs
|
| 521 |
|
| 522 |
+
@spaces.GPU(duration=180)
|
| 523 |
+
def get_3D_object_from_scene(outdir, text, threshold, scene, min_conf_thr, as_pointcloud,
|
| 524 |
+
mask_sky, clean_depth, transparent_cams, cam_size):
|
| 525 |
|
| 526 |
+
texts = [text]
|
| 527 |
+
inputs = pe3r.siglip_tokenizer(text=texts, padding="max_length", return_tensors="pt")
|
| 528 |
+
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 529 |
+
with torch.no_grad():
|
| 530 |
+
text_feats =pe3r.siglip.get_text_features(**inputs)
|
| 531 |
+
text_feats = text_feats / text_feats.norm(dim=-1, keepdim=True)
|
| 532 |
+
scene.render_image(text_feats, threshold)
|
| 533 |
+
scene.ori_imgs = scene.rendered_imgs
|
| 534 |
+
outfile = get_3D_model_from_scene(outdir, scene, min_conf_thr, as_pointcloud, mask_sky,
|
| 535 |
+
clean_depth, transparent_cams, cam_size)
|
| 536 |
+
return outfile
|
| 537 |
|
| 538 |
|
| 539 |
def set_scenegraph_options(inputfiles, winsize, refid, scenegraph_type):
|
|
|
|
| 560 |
with tempfile.TemporaryDirectory(suffix='pe3r_gradio_demo') as tmpdirname:
|
| 561 |
recon_fun = functools.partial(get_reconstructed_scene, tmpdirname)
|
| 562 |
model_from_scene_fun = functools.partial(get_3D_model_from_scene, tmpdirname)
|
| 563 |
+
get_3D_object_from_scene_fun = functools.partial(get_3D_object_from_scene, tmpdirname)
|
| 564 |
|
| 565 |
with gradio.Blocks(css=""".gradio-container {margin: 0 !important; min-width: 100%};""", title="PE3R Demo") as demo:
|
| 566 |
# scene state is save so that you can change conf_thr, cam_size... without rerunning the inference
|
|
|
|
| 646 |
inputs=[scene, min_conf_thr, as_pointcloud, mask_sky,
|
| 647 |
clean_depth, transparent_cams, cam_size],
|
| 648 |
outputs=outmodel)
|
| 649 |
+
find_btn.click(fn=get_3D_object_from_scene_fun,
|
| 650 |
+
inputs=[text_input, threshold, scene, min_conf_thr, as_pointcloud, mask_sky,
|
| 651 |
+
clean_depth, transparent_cams, cam_size],
|
| 652 |
+
outputs=outmodel)
|
| 653 |
demo.launch(show_error=True, share=None, server_name=None, server_port=None)
|