import os, subprocess, shlex, sys, gc import time import torch import numpy as np import shutil import argparse import gradio as gr import uuid import spaces from huggingface_hub import snapshot_download # subprocess.run(shlex.split("pip install wheel/torch_scatter-2.1.2+pt21cu121-cp310-cp310-linux_x86_64.whl")) subprocess.run(shlex.split("pip install wheel/flash_attn-2.6.3+cu123torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whl")) subprocess.run(shlex.split("pip install wheel/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl")) subprocess.run(shlex.split("pip install wheel/simple_knn-0.0.0-cp310-cp310-linux_x86_64.whl")) subprocess.run(shlex.split("pip install wheel/curope-0.0.0-cp310-cp310-linux_x86_64.whl")) subprocess.run(shlex.split("pip install wheel/pointops-1.0-cp310-cp310-linux_x86_64.whl")) from src.utils.visualization_utils import render_video_from_file from src.model import LSM_MASt3R # Download the model checkpoint from Hugging Face Hub repo_id = "Journey9ni/LSM" remote_dir = "checkpoints/pretrained_models" local_dir = "checkpoints/pretrained_model" model_path_map = { "MASt3R_ViTLarge_BaseDecoder_512_catmlpdpt_metric.pth": "MASt3R_ViTLarge_BaseDecoder_512_catmlpdpt_metric.pth", "checkpoint-40.pth":"checkpoint-40.pth", "demo_e200.ckpt":"lang_seg.ckpt" } os.makedirs(local_dir, exist_ok=True) # download remote repo snapshot_download(repo_id=repo_id, local_dir='./') # rename the files for remote_name, local_name in model_path_map.items(): os.rename(os.path.join(remote_dir, remote_name), os.path.join(local_dir, local_name)) # load the model model_path = "checkpoints/pretrained_model/checkpoint-40.pth" model = LSM_MASt3R.from_pretrained(model_path, device='cuda') model = model.eval() @spaces.GPU(duration=80) def process(inputfiles, input_path=None): # Create a unique cache directory cache_dir = os.path.join('outputs', str(uuid.uuid4())) os.makedirs(cache_dir, exist_ok=True) if input_path is not None: imgs_path = './assets/examples/' + input_path imgs_names = sorted(os.listdir(imgs_path)) inputfiles = [] for imgs_name in imgs_names: file_path = os.path.join(imgs_path, imgs_name) print(file_path) inputfiles.append(file_path) print(inputfiles) filelist = inputfiles if len(filelist) != 2: gr.Warning("Please select 2 images") shutil.rmtree(cache_dir) # Clean up cache directory return None, None, None, None, None, None ply_path = os.path.join(cache_dir, 'gaussians.ply') # render_video_from_file(filelist, model, output_path=cache_dir, resolution=224) render_video_from_file(filelist, model, output_path=cache_dir, resolution=512) rgb_video_path = os.path.join(cache_dir, 'moved', 'output_images_video.mp4') depth_video_path = os.path.join(cache_dir, 'moved', 'output_depth_video.mp4') feature_video_path = os.path.join(cache_dir, 'moved', 'output_fmap_video.mp4') return filelist, rgb_video_path, depth_video_path, feature_video_path, ply_path, ply_path _TITLE = 'LargeSpatialModel' _DESCRIPTION = '''