MiDaS Depth Estimation Guide

Published: February 6, 2023 | Last Modified: May 13, 2025

Tags: ai computer vision depth estimation midas python cuda installation

Categories: Python AI Computer Vision

GitHub Repository

During installation, I ran into an issue where the CUDA package wasn’t found. Had to modify environment.yaml to:

name: midas-py310
channels:
  - pytorch
  - defaults
dependencies:
  - nvidia::cuda-toolkit=11.7.0
  - python=3.10.8
  - pytorch::pytorch=1.13.0
  - torchvision=0.14.0
  - pip=22.3.1
  - numpy=1.23.4
  - pip:
    - opencv-python==4.6.0.66
    - imutils==0.5.4
    - timm==0.6.12
    - einops==0.6.0

Commands that were helpful for troubleshooting CUDA:

conda list env
conda env remove -n midas-py310
python -m torch.utils.collect_env
nvidia-smi
conda install cudatoolkit
conda install -c "nvidia/label/cuda-11.7.0" cuda-toolkit

Activate the Conda environment

conda activate midas-py310

Run MiDaS

From the Conda Shell, cd to the MiDaS directory
cd C:\Users\trima\MiDaS

Place the image frames you would like to process in the “input” directory and run one of the following commands:

# dpt_beit_large_512
python run.py --model_type dpt_beit_large_512 --input_path input --output_path output --grayscale --optimize
# dpt_swin2_large_384
python run.py --model_type dpt_swin2_large_384 --input_path input --output_path output --grayscale --optimize
# dpt_swin2_tiny_256
python run.py --model_type dpt_swin2_tiny_256 --input_path input --output_path output --grayscale --optimize

For “inferno” color mapping, omit the –grayscale flag.