init project
Browse files38 unmodified lines39404142434243444539 unmodified lines8586878988899091153 unmodified lines24524624724824925025125247 unmodified lines300301302303304305306138 unmodified lines44544644744844945045145274 unmodified lines52752852953053153253352853453553653727 unmodified lines56556656756256856957057128 unmodified lines60060160259760360460560660160760860961017 unmodified lines62862963062562662762862963063163263363463563663763863964064164264364464564664764863163263363463563663763863964064164264364464564664764864965065165265365465565665738 unmodified lines
silent = Falsedevice = 'cuda' if torch.cuda.is_available() else 'cpu'pe3r = Models(device)pe3r = Models('cpu')
def _convert_scene_output_to_glb(outdir, imgs, pts3d, mask, focals, cams2world, cam_size=0.05,39 unmodified lines scene.export(file_obj=outfile) return outfile
@spaces.GPU(duration=180)# @spaces.GPU(duration=180)def get_3D_model_from_scene(outdir, scene, min_conf_thr=3, as_pointcloud=False, mask_sky=False, clean_depth=False, transparent_cams=False, cam_size=0.05): """153 unmodified lines
@torch.no_graddef get_mask_from_img_sam1(mobilesamv2, yolov8, sam1_image, yolov8_image, original_size, input_size, transform): device = 'cuda' if torch.cuda.is_available() else 'cpu'
sam_mask=[] img_area = original_size[0] * original_size[1]
47 unmodified lines
@torch.no_graddef get_cog_feats(images): device = 'cuda' if torch.cuda.is_available() else 'cpu' cog_seg_maps = [] rev_cog_seg_maps = [] inference_state = pe3r.sam2.init_state(images=images.sam2_images, video_height=images.sam2_video_size[0], video_width=images.sam2_video_size[1])138 unmodified lines """ if len(filelist) < 2: raise gradio.Error("Please input at least 2 images.") device = 'cuda' if torch.cuda.is_available() else 'cpu'
images = Images(filelist=filelist, device=device) 74 unmodified linesdef 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('cuda') for key, value in inputs.items()} 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)27 unmodified lines
with 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) # 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:28 unmodified lines # adjust the camera size in the output pointcloud cam_size = gradio.Slider(label="cam_size", value=0.05, minimum=0.001, maximum=0.1, step=0.001, visible=False) with gradio.Row(): as_pointcloud = gradio.Checkbox(value=True, label="As pointcloud") as_pointcloud = gradio.Checkbox(value=True, label="As pointcloud", visible=False) # two post process implemented mask_sky = gradio.Checkbox(value=False, label="Mask sky", visible=False) clean_depth = gradio.Checkbox(value=True, label="Clean-up depthmaps", visible=False) transparent_cams = gradio.Checkbox(value=True, label="Transparent cameras") transparent_cams = gradio.Checkbox(value=True, label="Transparent cameras", visible=False)
with gradio.Row(): text_input = gradio.Textbox(label="Query Text")17 unmodified lines mask_sky, clean_depth, transparent_cams, cam_size, scenegraph_type, winsize, refid], outputs=[scene, outmodel]) # , outgallery min_conf_thr.release(fn=model_from_scene_fun, inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size], outputs=outmodel) cam_size.change(fn=model_from_scene_fun, inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size], outputs=outmodel) as_pointcloud.change(fn=model_from_scene_fun, inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size], outputs=outmodel) mask_sky.change(fn=model_from_scene_fun, inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size], outputs=outmodel) clean_depth.change(fn=model_from_scene_fun, inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size], outputs=outmodel) transparent_cams.change(model_from_scene_fun, inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size], outputs=outmodel) # min_conf_thr.release(fn=model_from_scene_fun, # inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, # clean_depth, transparent_cams, cam_size], # outputs=outmodel) # cam_size.change(fn=model_from_scene_fun, # inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, # clean_depth, transparent_cams, cam_size], # outputs=outmodel) # as_pointcloud.change(fn=model_from_scene_fun, # inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, # clean_depth, transparent_cams, cam_size], # outputs=outmodel) # mask_sky.change(fn=model_from_scene_fun, # inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, # clean_depth, transparent_cams, cam_size], # outputs=outmodel) # clean_depth.change(fn=model_from_scene_fun, # inputs=[scene, min_conf_thr, as_pointcloud, mask_sky, # clean_depth, transparent_cams, cam_size], # outputs=outmodel) # transparent_cams.change(model_from_scene_fun, # inputs=[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],app.py+37-31