hujiecpp commited on
Commit
89fb9c8
·
1 Parent(s): 6cbef76

init project

Browse files
Files changed (1) hide show
  1. app.py +25 -22
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
- mask_sky, clean_depth, transparent_cams, cam_size):
553
 
554
- device = 'cuda' if torch.cuda.is_available() else 'cpu'
555
- siglip_tokenizer = AutoTokenizer.from_pretrained("google/siglip-large-patch16-256")
556
- siglip = AutoModel.from_pretrained("google/siglip-large-patch16-256", device_map=device)
557
-
558
- texts = [text]
559
- inputs = siglip_tokenizer(text=texts, padding="max_length", return_tensors="pt")
560
- inputs = {key: value.to(device) for key, value in inputs.items()}
561
- with torch.no_grad():
562
- text_feats =siglip.get_text_features(**inputs)
563
- text_feats = text_feats / text_feats.norm(dim=-1, keepdim=True)
564
- scene.render_image(text_feats, threshold)
565
- scene.ori_imgs = scene.rendered_imgs
566
- outfile = get_3D_model_from_scene(outdir, scene, min_conf_thr, as_pointcloud, mask_sky,
567
- clean_depth, transparent_cams, cam_size)
568
- return outfile
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
- inputs=[text_input, threshold, scene, min_conf_thr, as_pointcloud, mask_sky,
631
- clean_depth, transparent_cams, cam_size],
632
- outputs=outmodel)
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)