{"id":13441393,"url":"https://github.com/spacewalk01/depth-anything-tensorrt","last_synced_at":"2025-03-20T12:30:24.776Z","repository":{"id":218704692,"uuid":"747145171","full_name":"spacewalk01/depth-anything-tensorrt","owner":"spacewalk01","description":"TensorRT implementation of Depth-Anything V1, V2","archived":false,"fork":false,"pushed_at":"2025-03-03T07:01:38.000Z","size":100806,"stargazers_count":331,"open_issues_count":7,"forks_count":38,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-03T08:19:44.232Z","etag":null,"topics":["cpp","depth-anything","depth-camera","depth-estimation","depth-image","image-depth-estimation","monocular-depth-estimation","python","tensorrt","video-depth"],"latest_commit_sha":null,"homepage":"https://depth-anything.github.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spacewalk01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-23T11:02:36.000Z","updated_at":"2025-02-27T07:41:07.000Z","dependencies_parsed_at":"2024-01-23T12:26:16.415Z","dependency_job_id":"b8ca33a8-be4c-4635-a0d8-1ad8fe5d01d7","html_url":"https://github.com/spacewalk01/depth-anything-tensorrt","commit_stats":null,"previous_names":["spacewalk01/depth-anything-tensorrt"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacewalk01%2Fdepth-anything-tensorrt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacewalk01%2Fdepth-anything-tensorrt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacewalk01%2Fdepth-anything-tensorrt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacewalk01%2Fdepth-anything-tensorrt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spacewalk01","download_url":"https://codeload.github.com/spacewalk01/depth-anything-tensorrt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244611093,"owners_count":20481124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","depth-anything","depth-camera","depth-estimation","depth-image","image-depth-estimation","monocular-depth-estimation","python","tensorrt","video-depth"],"created_at":"2024-07-31T03:01:33.418Z","updated_at":"2025-03-20T12:30:24.771Z","avatar_url":"https://github.com/spacewalk01.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cdiv align=\"left\"\u003e\n\nDepth Anything TensorRT CLI\n===========================\n\n[![python](https://img.shields.io/badge/python-3.10.12-green)](https://www.python.org/downloads/release/python-31012/)\n[![cuda](https://img.shields.io/badge/cuda-11.8-green)](https://developer.nvidia.com/cuda-downloads)\n[![trt](https://img.shields.io/badge/TRT-10.0-green)](https://developer.nvidia.com/tensorrt)\n[![mit](https://img.shields.io/badge/license-MIT-blue)](https://github.com/spacewalk01/depth-anything-tensorrt/blob/main/LICENSE)\n\n\u003c/div\u003e\n\nDepth estimation is the task of measuring the distance of each pixel relative to the camera. This repo provides a TensorRT implementation of the [Depth-Anything](https://github.com/LiheYoung/Depth-Anything) depth estimation model in both C++ and Python, enabling efficient real-time inference.\n\n\u003cp align=\"center\"\u003e\n  Depth-Anything-V1\n  \u003cimg src=\"assets/davis_dolphins_result.gif\" height=\"225px\" width=\"720px\" /\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  Depth-Anything-V2\n  \u003cimg src=\"assets/ferris_wheel_result.gif\" height=\"225px\" width=\"720px\" /\u003e\n\u003c/p\u003e\n\n\n\n## News\n* **2024-08-20:** Added CLI (xa1on)\n* **2024-06-20:** Added support for TensorRT 10.\n* **2024-06-17:** [Depth Anything V2](https://github.com/DepthAnything/Depth-Anything-V2) has been integrated.\n* **2024-01-23:** The Depth Anything [TensorRT](https://github.com/spacewalk01/depth-anything-tensorrt) version has been created.\n  \n## ⏱️ Performance\n\nThe inference time includes the pre-preprocessing and post-processing stages:\n| Device          | Model | Model Input (WxH) |  Image Resolution (WxH)|Inference Time(ms)|\n|:---------------:|:------------:|:------------:|:------------:|:------------:|\n| RTX4090        | Depth-Anything-S  |518x518  |  1280x720    | 3     |\n| RTX4090        | Depth-Anything-B  |518x518  |  1280x720    | 6     |\n| RTX4090        | Depth-Anything-L  |518x518  |  1280x720    | 12    |\n\n\n\u003e [!NOTE]\n\u003e Inference was conducted using `FP16` precision, with a warm-up period of 10 frames. The reported time corresponds to the last inference.\n\n## 🚀 Quick Start\n\n#### C++\n\n- **Step 1**: Create an engine from an onnx model and save it:\n``` shell\ndepth-anything-tensorrt.exe -model \u003connx model\u003e\n```\n- **Step 2**: Deserialize an engine. Once you've built your engine, the next time you run it, simply use your engine file:\n``` shell\ndepth-anything-tensorrt.exe -model \u003cengine file\u003e -input \u003cinput image or video\u003e\n```\n- Alternatively, you can skip immediately to running the model with just an onnx file, however, it will still generate a engine file.\n``` shell\ndepth-anything-tensorrt.exe -model \u003connx model\u003e -input \u003cinput image or video\u003e\n```\n\nExample:\n``` shell\n# infer image\ndepth-anything-tensorrt.exe -model depth_anything_vitb14.engine -input test.jpg\n# infer folder(images/videos)\ndepth-anything-tensorrt.exe -model depth_anything_vitb14.engine -input data # folder containing videos/images\n# infer video\ndepth-anything-tensorrt.exe -model depth_anything_vitb14.engine -input test.mp4 # the video path\n# specify output location\ndepth-anything-tensorrt.exe -model depth_anything_vitb14.engine -input test.mp4 -output result # rendered depth maps will go into the \"results\" directory\n# display progress in one line rather than multiple\ndepth-anything-tensorrt.exe -model depth_anything_vitb14.engine -input test.mp4 -one-line\n# modify prefix of generated files (default: \"depth_\")\ndepth-anything-tensorrt.exe -model depth_anything_vitb14.engine -input test.mp4 -prefix \"depthify_\" # rendered depth map will have the name \"depthify_test.mp4\"\n# show preview including before and after (may slow down performance)\ndepth-anything-tensorrt.exe -preview -model depth_anything_vitb14.engine -input test.mp4\n# modify fps of footage (does not interpolate, will speed up or slow down footage if original video file has a different fps value)\ndepth-anything-tensorrt.exe -model depth_anything_vitb14.engine -input test.mp4 -fps 60\n# use an existing engine file if found\ndepth-anything-tensorrt.exe -model depth_anything_vitb14.onnx -input test.mp4 -find-engine\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/usage-example.png\"/\u003e\n\u003c/p\u003e\n\n#### Python\n\n```\ncd depth-anything-tensorrt/python\n\n# infer image\npython trt_infer.py --engine \u003cpath to trt engine\u003e --img \u003csingle-img\u003e --outdir \u003coutdir\u003e [--grayscale]\n```\n\n## 🛠️ Build\n\n#### C++\n\nRefer to our [docs/INSTALL.md](https://github.com/spacewalk01/depth-anything-tensorrt/blob/main/docs/INSTALL.md) for C++ environment installation.\n\n#### Python\n\n``` shell\ncd \u003ctensorrt installation path\u003e/python\npip install cuda-python\npip install tensorrt-8.6.0-cp310-none-win_amd64.whl\npip install opencv-python\n``` \n\n## 🤖 Model Preparation\n### Depth-Anything-V1\nPerform the following steps to create an onnx model:\n\n1. Download the pretrained [model](https://huggingface.co/spaces/LiheYoung/Depth-Anything/tree/main/checkpoints) and install [Depth-Anything](https://github.com/LiheYoung/Depth-Anything):\n   ``` shell\n   git clone https://github.com/LiheYoung/Depth-Anything\n   cd Depth-Anything\n   pip install -r requirements.txt\n   ```\n  \n2. Copy [dpt.py](https://github.com/spacewalk01/depth-anything-tensorrt/blob/main/depth_anything_v1/dpt.py) in depth_anything_v1 from this repo to `\u003cDepth-Anything\u003e/depth_anything` folder. And, Copy [export_v1.py](https://github.com/spacewalk01/depth-anything-tensorrt/blob/main/depth_anything_v1/export_v1.py) in depth_anything_v1 from this repo to `\u003cDepth-Anything\u003e` folder.\n3. Export the model to onnx format using [export_v1.py](https://github.com/spacewalk01/depth-anything-tensorrt/blob/main/depth_anything_v1/export_v1.py). You will get an onnx file named `depth_anything_vit{}14.onnx`, such as `depth_anything_vitb14.onnx`. Note that I used torch cpu version for exporting the onnx model as it is not necessary to deploy the model on GPU when exporting.\n\n    \n    ``` shell\n    conda create -n depth-anything python=3.8\n    conda activate depth-anything\n    pip install torch torchvision\n    pip install opencv-python\n    pip install onnx\n    cd Depth-Anything\n    python export_v1.py --encoder vitb --load_from depth_anything_vitb14.pth --image_shape 3 518 518\n    ```\n\n\n### Depth-Anything-V2\n\n1. Clone [Depth-Anything-V2](https://github.com/DepthAnything/Depth-Anything-V2.git) \n   ``` shell\n   git clone https://github.com/DepthAnything/Depth-Anything-V2.git\n   cd Depth-Anything-v2\n   pip install -r requirements.txt\n   ```\n2. Download the pretrained models from the [readme](https://github.com/DepthAnything/Depth-Anything-V2.git) and put them in checkpoints folder:\n3. Copy [dpt.py](https://github.com/spacewalk01/depth-anything-tensorrt/blob/main/depth_anything_v2/dpt.py) in depth_anything_v2 from this repo to `\u003cDepth-Anything-V2\u003e/depth_anything_v2` folder. And, Copy [export_v2.py](https://github.com/spacewalk01/depth-anything-tensorrt/blob/main/depth_anything_v2/export_v2.py) in depth_anything_v2 from this repo to `\u003cDepth-Anything-V2\u003e` folder.\n4. Run the following to export the model:\n    ``` shell\n    conda create -n depth-anything python=3.8\n    conda activate depth-anything\n    pip install torch torchvision\n    pip install opencv-python\n    pip install onnx\n    cd Depth-Anything-V2\n    python export_v2.py --encoder vitb --input-size 518\n    ```\n\n\u003e [!TIP]\n\u003e The width and height of the model input should be divisible by 14, the patch height.\n\n\n## 👏 Acknowledgement\n\nThis project is based on the following projects:\n- [Depth-Anything](https://github.com/LiheYoung/Depth-Anything) - Unleashing the Power of Large-Scale Unlabeled Data.\n- [TensorRT](https://github.com/NVIDIA/TensorRT/tree/release/8.6/samples) - TensorRT samples and api documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacewalk01%2Fdepth-anything-tensorrt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspacewalk01%2Fdepth-anything-tensorrt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacewalk01%2Fdepth-anything-tensorrt/lists"}