Skip to content

Mono Depth Prediction

Image title

Query image and prediction

BiWAKO.MiDAS

MonoDepth prediction model.

Model

This is a pretrained MiDASv1 model. Currently available models are: - mono_depth_small - mono_depth_large

Attributes:

Name Type Description
model_path str

Path to model file. If automatic download is triggered, this path is used to save the model.

session onnxruntime.InferenceSession

Inference session.

input_name str

Input node name.

output_name str

Output node name.

input_shape tuple

Input shape.

h int

Alias of input_shape[2].

w int

Alias of input_shape[3].

__init__(self, model='mono_depth_small', show_exp=False) special

Initialize model.

Parameters:

Name Type Description Default
model str

Model name or path to the downloaded onnx file. Defaults to "mono_depth_small". Onnx file is downloaded automatically.

'mono_depth_small'
show_exp bool

True to display expected input size. Defaults to False.

False

Examples:

>>> model = MiDAS("mono_depth_large")
downloading mono_depth_large.onnx to mono_depth_large.onnx
100%|██████████| 416M/416M [02:11<00:00, 3.47MB/s]
>>> model = MiDAS("weights/midas/mono_depth_small.onnx") # download to a specific directory
downloading mono_depth_small.onnx to weights/midas/mono_depth_small.onnx
100%|██████████| 66.8M/66.8M [03:26<00:00, 323kB/s]

predict(self, img)

Predict.

Parameters:

Name Type Description Default
img Union[str, np.ndarray]

image path or numpy array in cv2 format

required

Returns:

Type Description
np.ndarray

predicted depthmap

render(self, prediction, query)

Return the resized depth map in cv2 foramt.

Parameters:

Name Type Description Default
prediction np.ndarray

predicted depthmap

required
query Union[str, np.ndarray]

query image path or numpy array in cv2 format used for resizing.

required

Returns:

Type Description
np.ndarray

Resized depthmap