Skip to content

Commit da70b30

Browse files
committed
Load duster and master weights from Naver's HF repos
1 parent 5026d01 commit da70b30

2 files changed

Lines changed: 4 additions & 60 deletions

File tree

‎vismatch/im_models/duster.py‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
import numpy as np
2-
from pathlib import Path
32
import torchvision.transforms as tfm
4-
import py3_wget
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

204
from vismatch.utils import add_to_path, resize_to_divisible
215
from vismatch import THIRD_PARTY_DIR, BaseMatcher
@@ -30,8 +14,6 @@ def _patched_torch_load(*args, **kwargs):
3014

3115

3216
class Dust3rMatcher(BaseMatcher):
33-
hf_model_id = "vismatch/duster"
34-
weight_filename = "duster_vit_large.pth"
3517
vit_patch_size = 16
3618

3719
def __init__(self, device="cpu", *args, **kwargs):
@@ -40,18 +22,7 @@ def __init__(self, device="cpu", *args, **kwargs):
4022

4123
self.verbose = False
4224

43-
model_path = self.download_weights()
44-
self.model = AsymmetricCroCo3DStereo.from_pretrained(model_path).to(device)
45-
46-
@classmethod
47-
def download_weights(cls):
48-
url = "https://download.europe.naverlabs.com/ComputerVision/DUSt3R/DUSt3R_ViTLarge_BaseDecoder_512_dpt.pth"
49-
cache_dir = Path(snapshot_download(cls.hf_model_id))
50-
model_path = cache_dir / cls.weight_filename
51-
if not model_path.is_file():
52-
print("Downloading Dust3r(ViT large)... (takes a while)")
53-
py3_wget.download_file(url, model_path)
54-
return model_path
25+
self.model = AsymmetricCroCo3DStereo.from_pretrained("naver/DUSt3R_ViTLarge_BaseDecoder_512_dpt").to(device)
5526

5627
def preprocess(self, img):
5728
_, h, w = img.shape

‎vismatch/im_models/master.py‎

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
from pathlib import Path
21
import torchvision.transforms as tfm
3-
import py3_wget
42
import 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

204
from vismatch import BaseMatcher, THIRD_PARTY_DIR
215
from vismatch.utils import resize_to_divisible, add_to_path
@@ -29,8 +13,6 @@ def _patched_torch_load(*args, **kwargs):
2913

3014

3115
class 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

Comments
 (0)