Demo / app.py
zino36's picture
Update app.py
bce5a1f verified
raw
history blame
3.12 kB
#!/usr/bin/env python3
# Copyright (C) 2024-present Naver Corporation. All rights reserved.
# Licensed under CC BY-NC-SA 4.0 (non-commercial use only).
#
# --------------------------------------------------------
# gradio demo executable
# --------------------------------------------------------
#!/usr/bin/env python3
# Copyright (C) 2024-present Naver Corporation. All rights reserved.
# Licensed under CC BY-NC-SA 4.0 (non-commercial use only).
#
# --------------------------------------------------------
# gradio demo executable
# --------------------------------------------------------
#!/usr/bin/env python3
# Copyright (C) 2024-present Naver Corporation. All rights reserved.
# Licensed under CC BY-NC-SA 4.0 (non-commercial use only).
#
# --------------------------------------------------------
# gradio demo executable
# --------------------------------------------------------
#!/usr/bin/env python3
# Copyright (C) 2024-present Naver Corporation. All rights reserved.
# Licensed under CC BY-NC-SA 4.0 (non-commercial use only).
#
# --------------------------------------------------------
# gradio demo executable
# --------------------------------------------------------
#!/usr/bin/env python3
# Copyright (C) 2024-present Naver Corporation. All rights reserved.
# Licensed under CC BY-NC-SA 4.0 (non-commercial use only).
#
# --------------------------------------------------------
# gradio demo executable
# --------------------------------------------------------
import os
import torch
import tempfile
from contextlib import nullcontext
from mast3r.demo import get_args_parser, main_demo
from mast3r.model import AsymmetricMASt3R
from mast3r.utils.misc import hash_md5
import matplotlib.pyplot as pl
pl.ion()
torch.backends.cuda.matmul.allow_tf32 = True # for gpu >= Ampere and pytorch >= 1.12
if __name__ == '__main__':
parser = get_args_parser()
args = parser.parse_args()
# Set default value for `args.weights` if not provided
if args.weights is None:
# Set a default model_name if weights are not provided
args.model_name = 'MASt3R_ViTLarge_BaseDecoder_512_catmlpdpt_metric' # Default model_name
args.weights = "naver/" + args.model_name # Construct default weights path
if args.server_name is not None:
server_name = args.server_name
else:
server_name = '0.0.0.0' if args.local_network else '127.0.0.1'
# Use the provided or default weights_path
weights_path = args.weights
model = AsymmetricMASt3R.from_pretrained(weights_path).to(args.device)
chkpt_tag = hash_md5(weights_path)
def get_context(tmp_dir):
return tempfile.TemporaryDirectory(suffix='_mast3r_gradio_demo') if tmp_dir is None \
else nullcontext(tmp_dir)
with get_context(args.tmp_dir) as tmpdirname:
cache_path = os.path.join(tmpdirname, chkpt_tag)
os.makedirs(cache_path, exist_ok=True)
main_demo(cache_path, model, args.device, args.image_size, server_name, args.server_port, silent=args.silent,
share=args.share, gradio_delete_cache=args.gradio_delete_cache)