init project
Browse files518 unmodified lines51952052152252352452552652752852953053153253353453553653753853954054120 unmodified lines56256356456556656756879 unmodified lines648649650651652653654655518 unmodified linesreturn scene, outfile#, imgs@spaces.GPU(duration=180)def get_3D_object_from_scene(outdir, text, threshold, scene, min_conf_thr, as_pointcloud,mask_sky, clean_depth, transparent_cams, cam_size):device = 'cuda' if torch.cuda.is_available() else 'cpu'texts = [text]inputs = pe3r.siglip_tokenizer(text=texts, padding="max_length", return_tensors="pt")inputs = {key: value.to(device) for key, value in inputs.items()}with torch.no_grad():text_feats =pe3r.siglip.get_text_features(**inputs)text_feats = text_feats / text_feats.norm(dim=-1, keepdim=True)scene.render_image(text_feats, threshold)scene.ori_imgs = scene.rendered_imgsoutfile = get_3D_model_from_scene(outdir, scene, min_conf_thr, as_pointcloud, mask_sky,clean_depth, transparent_cams, cam_size)return outfiledef set_scenegraph_options(inputfiles, winsize, refid, scenegraph_type):20 unmodified lineswith tempfile.TemporaryDirectory(suffix='pe3r_gradio_demo') as tmpdirname:recon_fun = functools.partial(get_reconstructed_scene, tmpdirname)model_from_scene_fun = functools.partial(get_3D_model_from_scene, tmpdirname)get_3D_object_from_scene_fun = functools.partial(get_3D_object_from_scene, tmpdirname)with gradio.Blocks(css=""".gradio-container {margin: 0 !important; min-width: 100%};""", title="PE3R Demo") as demo:# scene state is save so that you can change conf_thr, cam_size... without rerunning the inference79 unmodified linesinputs=[scene, min_conf_thr, as_pointcloud, mask_sky,clean_depth, transparent_cams, cam_size],outputs=outmodel)find_btn.click(fn=get_3D_object_from_scene_fun,inputs=[text_input, threshold, scene, min_conf_thr, as_pointcloud, mask_sky,clean_depth, transparent_cams, cam_size],outputs=outmodel)demo.launch(show_error=True, share=None, server_name=None, server_port=None)518 unmodified lines51952052152252352452552652752852953053153253353453553653753853920 unmodified lines56056156256356456556679 unmodified lines646647648649650651652653518 unmodified linesreturn scene, outfile#, imgs# @spaces.GPU(duration=180)# def get_3D_object_from_scene(outdir, text, threshold, scene, min_conf_thr, as_pointcloud,# mask_sky, clean_depth, transparent_cams, cam_size):# texts = [text]# inputs = pe3r.siglip_tokenizer(text=texts, padding="max_length", return_tensors="pt")# inputs = {key: value.to(device) for key, value in inputs.items()}# with torch.no_grad():# text_feats =pe3r.siglip.get_text_features(**inputs)# text_feats = text_feats / text_feats.norm(dim=-1, keepdim=True)# scene.render_image(text_feats, threshold)# scene.ori_imgs = scene.rendered_imgs# outfile = get_3D_model_from_scene(outdir, scene, min_conf_thr, as_pointcloud, mask_sky,# clean_depth, transparent_cams, cam_size)# return outfiledef set_scenegraph_options(inputfiles, winsize, refid, scenegraph_type):20 unmodified lineswith tempfile.TemporaryDirectory(suffix='pe3r_gradio_demo') as tmpdirname:recon_fun = functools.partial(get_reconstructed_scene, tmpdirname)model_from_scene_fun = functools.partial(get_3D_model_from_scene, tmpdirname)# get_3D_object_from_scene_fun = functools.partial(get_3D_object_from_scene, tmpdirname)with gradio.Blocks(css=""".gradio-container {margin: 0 !important; min-width: 100%};""", title="PE3R Demo") as demo:# scene state is save so that you can change conf_thr, cam_size... without rerunning the inference79 unmodified linesinputs=[scene, min_conf_thr, as_pointcloud, mask_sky,clean_depth, transparent_cams, cam_size],outputs=outmodel)# find_btn.click(fn=get_3D_object_from_scene_fun,# inputs=[text_input, threshold, scene, min_conf_thr, as_pointcloud, mask_sky,# clean_depth, transparent_cams, cam_size],# outputs=outmodel)demo.launch(show_error=True, share=None, server_name=None, server_port=None)
app.py+19-21