init project
Browse files
    	
        app.py
    CHANGED
    
    | @@ -542,36 +542,39 @@ def get_reconstructed_scene(outdir, filelist, schedule, niter, min_conf_thr, | |
| 542 | 
             
                outfile = get_3D_model_from_scene(outdir, scene, min_conf_thr, as_pointcloud, mask_sky,
         | 
| 543 | 
             
                                                  clean_depth, transparent_cams, cam_size)
         | 
| 544 |  | 
|  | |
| 545 | 
             
                scene.to('cpu')
         | 
|  | |
|  | |
| 546 | 
             
                torch.cuda.empty_cache()
         | 
| 547 |  | 
| 548 | 
             
                return scene, outfile 
         | 
| 549 |  | 
| 550 | 
             
            # @spaces.GPU(duration=60)
         | 
| 551 | 
            -
            def get_3D_object_from_scene(outdir, text, threshold, scene, min_conf_thr, as_pointcloud, 
         | 
| 552 | 
            -
             | 
| 553 |  | 
| 554 | 
            -
             | 
| 555 | 
            -
             | 
| 556 | 
            -
             | 
| 557 | 
            -
             | 
| 558 | 
            -
             | 
| 559 | 
            -
             | 
| 560 | 
            -
             | 
| 561 | 
            -
             | 
| 562 | 
            -
             | 
| 563 | 
            -
             | 
| 564 | 
            -
             | 
| 565 | 
            -
             | 
| 566 | 
            -
             | 
| 567 | 
            -
             | 
| 568 | 
            -
             | 
| 569 |  | 
| 570 |  | 
| 571 | 
             
            with tempfile.TemporaryDirectory(suffix='pe3r_gradio_demo') as tmpdirname:
         | 
| 572 | 
             
                recon_fun = functools.partial(get_reconstructed_scene, tmpdirname)
         | 
| 573 | 
             
                # model_from_scene_fun = functools.partial(get_3D_model_from_scene, tmpdirname)
         | 
| 574 | 
            -
                get_3D_object_from_scene_fun = functools.partial(get_3D_object_from_scene, tmpdirname)
         | 
| 575 |  | 
| 576 | 
             
                with gradio.Blocks(css=""".gradio-container {margin: 0 !important; min-width: 100%};""", title="PE3R Demo") as demo:
         | 
| 577 | 
             
                    # scene state is save so that you can change conf_thr, cam_size... without rerunning the inference
         | 
| @@ -626,8 +629,8 @@ with tempfile.TemporaryDirectory(suffix='pe3r_gradio_demo') as tmpdirname: | |
| 626 | 
             
                                                scenegraph_type, winsize, refid],
         | 
| 627 | 
             
                                        outputs=[scene, outmodel]) # , outgallery
         | 
| 628 |  | 
| 629 | 
            -
                        find_btn.click(fn=get_3D_object_from_scene_fun,
         | 
| 630 | 
            -
             | 
| 631 | 
            -
             | 
| 632 | 
            -
             | 
| 633 | 
             
                demo.launch(show_error=True, share=None, server_name=None, server_port=None)
         | 
|  | |
| 542 | 
             
                outfile = get_3D_model_from_scene(outdir, scene, min_conf_thr, as_pointcloud, mask_sky,
         | 
| 543 | 
             
                                                  clean_depth, transparent_cams, cam_size)
         | 
| 544 |  | 
| 545 | 
            +
                print(scene)
         | 
| 546 | 
             
                scene.to('cpu')
         | 
| 547 | 
            +
                print(scene)
         | 
| 548 | 
            +
             | 
| 549 | 
             
                torch.cuda.empty_cache()
         | 
| 550 |  | 
| 551 | 
             
                return scene, outfile 
         | 
| 552 |  | 
| 553 | 
             
            # @spaces.GPU(duration=60)
         | 
| 554 | 
            +
            # def get_3D_object_from_scene(outdir, text, threshold, scene, min_conf_thr, as_pointcloud, 
         | 
| 555 | 
            +
            #                  mask_sky, clean_depth, transparent_cams, cam_size):
         | 
| 556 |  | 
| 557 | 
            +
            #     device = 'cuda' if torch.cuda.is_available() else 'cpu'
         | 
| 558 | 
            +
            #     siglip_tokenizer = AutoTokenizer.from_pretrained("google/siglip-large-patch16-256")
         | 
| 559 | 
            +
            #     siglip = AutoModel.from_pretrained("google/siglip-large-patch16-256", device_map=device)
         | 
| 560 | 
            +
             | 
| 561 | 
            +
            #     texts = [text]
         | 
| 562 | 
            +
            #     inputs = siglip_tokenizer(text=texts, padding="max_length", return_tensors="pt")
         | 
| 563 | 
            +
            #     inputs = {key: value.to(device) for key, value in inputs.items()}
         | 
| 564 | 
            +
            #     with torch.no_grad():
         | 
| 565 | 
            +
            #         text_feats =siglip.get_text_features(**inputs)
         | 
| 566 | 
            +
            #         text_feats = text_feats / text_feats.norm(dim=-1, keepdim=True)
         | 
| 567 | 
            +
            #     scene.render_image(text_feats, threshold)
         | 
| 568 | 
            +
            #     scene.ori_imgs = scene.rendered_imgs
         | 
| 569 | 
            +
            #     outfile = get_3D_model_from_scene(outdir, scene, min_conf_thr, as_pointcloud, mask_sky,
         | 
| 570 | 
            +
            #                                       clean_depth, transparent_cams, cam_size)
         | 
| 571 | 
            +
            #     return outfile
         | 
| 572 |  | 
| 573 |  | 
| 574 | 
             
            with tempfile.TemporaryDirectory(suffix='pe3r_gradio_demo') as tmpdirname:
         | 
| 575 | 
             
                recon_fun = functools.partial(get_reconstructed_scene, tmpdirname)
         | 
| 576 | 
             
                # model_from_scene_fun = functools.partial(get_3D_model_from_scene, tmpdirname)
         | 
| 577 | 
            +
                # get_3D_object_from_scene_fun = functools.partial(get_3D_object_from_scene, tmpdirname)
         | 
| 578 |  | 
| 579 | 
             
                with gradio.Blocks(css=""".gradio-container {margin: 0 !important; min-width: 100%};""", title="PE3R Demo") as demo:
         | 
| 580 | 
             
                    # scene state is save so that you can change conf_thr, cam_size... without rerunning the inference
         | 
|  | |
| 629 | 
             
                                                scenegraph_type, winsize, refid],
         | 
| 630 | 
             
                                        outputs=[scene, outmodel]) # , outgallery
         | 
| 631 |  | 
| 632 | 
            +
                        # find_btn.click(fn=get_3D_object_from_scene_fun,
         | 
| 633 | 
            +
                        #                     inputs=[text_input, threshold, scene, min_conf_thr, as_pointcloud, mask_sky,
         | 
| 634 | 
            +
                        #                             clean_depth, transparent_cams, cam_size],
         | 
| 635 | 
            +
                        #                 outputs=outmodel)
         | 
| 636 | 
             
                demo.launch(show_error=True, share=None, server_name=None, server_port=None)
         |