1- from pathlib import Path
21import torchvision .transforms as tfm
3- import py3_wget
42import numpy as np
5- import torch
6- from huggingface_hub import snapshot_download
7-
8- # Monkey patch torch.load to use weights_only=False by default for compatibility with PyTorch 2.6+
9- _original_torch_load = torch .load
10-
11-
12- def _patched_torch_load (* args , ** kwargs ):
13- if "weights_only" not in kwargs :
14- kwargs ["weights_only" ] = False
15- return _original_torch_load (* args , ** kwargs )
16-
17-
18- torch .load = _patched_torch_load
193
204from vismatch import BaseMatcher , THIRD_PARTY_DIR
215from vismatch .utils import resize_to_divisible , add_to_path
@@ -29,8 +13,6 @@ def _patched_torch_load(*args, **kwargs):
2913
3014
3115class Mast3rMatcher (BaseMatcher ):
32- hf_model_id = "vismatch/master"
33- weight_filename = "MASt3R_ViTLarge_BaseDecoder_512_catmlpdpt_metric.pth"
3416 vit_patch_size = 16
3517
3618 def __init__ (self , device = "cpu" , * args , ** kwargs ):
@@ -39,18 +21,9 @@ def __init__(self, device="cpu", *args, **kwargs):
3921
4022 self .verbose = False
4123
42- model_path = self .download_weights ()
43- self .model = AsymmetricMASt3R .from_pretrained (model_path ).to (device )
44-
45- @classmethod
46- def download_weights (cls ):
47- url = "https://download.europe.naverlabs.com/ComputerVision/MASt3R/MASt3R_ViTLarge_BaseDecoder_512_catmlpdpt_metric.pth"
48- cache_dir = Path (snapshot_download (cls .hf_model_id ))
49- model_path = cache_dir / cls .weight_filename
50- if not model_path .is_file ():
51- print ("Downloading Master(ViT large)... (takes a while)" )
52- py3_wget .download_file (url , model_path )
53- return model_path
24+ self .model = AsymmetricMASt3R .from_pretrained ("naver/MASt3R_ViTLarge_BaseDecoder_512_catmlpdpt_metric" ).to (
25+ device
26+ )
5427
5528 def preprocess (self , img ):
5629 _ , h , w = img .shape
0 commit comments