Skip to content

Commit bf9061d

Browse files
committed
Expose default transform in hubconf
1 parent 4deed7b commit bf9061d

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

hubconf.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from midas.midas_net import MidasNet
66

77

8-
98
def MiDaS(pretrained=True, **kwargs):
109
""" # This docstring shows up in hub.help()
1110
MiDaS model for monocular depth estimation
@@ -24,3 +23,29 @@ def MiDaS(pretrained=True, **kwargs):
2423
model.load_state_dict(state_dict)
2524

2625
return model
26+
27+
28+
def transforms():
29+
import cv2
30+
from torchvision.transforms import Compose
31+
from midas.transforms import Resize, NormalizeImage, PrepareForNet
32+
from midas import transforms
33+
34+
transforms.default_transform = Compose(
35+
[
36+
lambda img: {"image": img / 255.0},
37+
Resize(
38+
384,
39+
384,
40+
resize_target=None,
41+
keep_aspect_ratio=True,
42+
ensure_multiple_of=32,
43+
resize_method="upper_bound",
44+
image_interpolation_method=cv2.INTER_CUBIC,
45+
),
46+
NormalizeImage(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
47+
PrepareForNet(),
48+
lambda sample: torch.from_numpy(sample["image"]).unsqueeze(0),
49+
]
50+
)
51+
return transforms

0 commit comments

Comments
 (0)