MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / load_model

Function load_model

ldm/modules/midas/api.py:73–134  ·  view source on GitHub ↗
(model_type)

Source from the content-addressed store, hash-verified

71
72
73def load_model(model_type):
74 # https://github.com/isl-org/MiDaS/blob/master/run.py
75 # load network
76 model_path = ISL_PATHS[model_type]
77 if model_type == "dpt_large": # DPT-Large
78 model = DPTDepthModel(
79 path=model_path,
80 backbone="vitl16_384",
81 non_negative=True,
82 )
83 net_w, net_h = 384, 384
84 resize_mode = "minimal"
85 normalization = NormalizeImage(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
86
87 elif model_type == "dpt_hybrid": # DPT-Hybrid
88 model = DPTDepthModel(
89 path=model_path,
90 backbone="vitb_rn50_384",
91 non_negative=True,
92 )
93 net_w, net_h = 384, 384
94 resize_mode = "minimal"
95 normalization = NormalizeImage(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
96
97 elif model_type == "midas_v21":
98 model = MidasNet(model_path, non_negative=True)
99 net_w, net_h = 384, 384
100 resize_mode = "upper_bound"
101 normalization = NormalizeImage(
102 mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
103 )
104
105 elif model_type == "midas_v21_small":
106 model = MidasNet_small(model_path, features=64, backbone="efficientnet_lite3", exportable=True,
107 non_negative=True, blocks={'expand': True})
108 net_w, net_h = 256, 256
109 resize_mode = "upper_bound"
110 normalization = NormalizeImage(
111 mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
112 )
113
114 else:
115 print(f"model_type '{model_type}' not implemented, use: --model_type large")
116 assert False
117
118 transform = Compose(
119 [
120 Resize(
121 net_w,
122 net_h,
123 resize_target=None,
124 keep_aspect_ratio=True,
125 ensure_multiple_of=32,
126 resize_method=resize_mode,
127 image_interpolation_method=cv2.INTER_CUBIC,
128 ),
129 normalization,
130 PrepareForNet(),

Callers 1

__init__Method · 0.85

Calls 6

DPTDepthModelClass · 0.90
NormalizeImageClass · 0.90
MidasNetClass · 0.90
MidasNet_smallClass · 0.90
ResizeClass · 0.90
PrepareForNetClass · 0.90

Tested by

no test coverage detected