Home ONNX SCDepth Monocular Depth Estimation
Post
Cancel

Open In GithubOpen In Github

Python scripts for performing monocular depth estimation using the SC_Depth model in ONNX

SC_Depth monocular depth estimation ONNX Original image:https://commons.wikimedia.org/wiki/File:Cannery_District_Bozeman_Epic_Fitness_Interior_Wood_Stairs.jpg

Requirements

  • Check the requirements.txt file.
  • For ONNX, if you have a NVIDIA GPU, then install the onnxruntime-gpu, otherwise use the onnxruntime library.

Installation

1
2
3
git clone https://github.com/ibaiGorordo/ONNX-SCDepth-Monocular-Depth-Estimation.git
cd ONNX-YOLOv7-Object-Detection
pip install -r requirements.txt

ONNX Runtime

For Nvidia GPU computers: pip install onnxruntime-gpu

Otherwise: pip install onnxruntime

ONNX model

I don’t provide the model, but you can easily convert the Pytorch model by placing the following code in the line #80 of inference.py in the original repository:

1
2
3
4
5
6
model_name = "sc_depth_v3_nyu.onnx"
torch.onnx.export(model,  # model being run
                  tensor_img,  # model input (or a tuple for multiple inputs)
                  model_name,  # where to save the model (can be a file or file-like object)
                  export_params=True,  # store the trained parameter weights inside the model file
                  opset_version=16)

Then you can simplify the ONNX model using ONNX-Simplifier:

1
onnxsim sc_depth_v3_nyu.onnx sc_depth_v3_nyu_sim.onnx

Finally, copy the simplified ONNX model file to the models folder.

Original Pytorch model

The Pytorch pretrained models were taken from the original repository.

Examples

  • Image inference:
1
 python image_depth_estimation.py 
  • Video inference:
1
 python video_depth_estimation.py
  • Webcam inference:
1
 python webcam_depth_estimation.py

Inference video Example

SC_Depth monocular depth estimation ONNX

Original video: https://youtu.be/e0IjlkU-pX0

References:

This post is licensed under CC BY 4.0 by the author.