(深度估计学习)Depth Anything V2 复现

Depth Anything V2 复现

代码:https://github.com/DepthAnything/Depth-Anything-V2

一、配置环境

在本机电脑win跑之后依旧爆显存,放到服务器跑:Ubuntu22.04,CUDA17

bash 复制代码
conda create -n DAv2 python=3.10
conda activate DAv2

conda下安装cuda。由于服务器上面我不能安装CUDA,只能在conda上安装cuda。我安装的cuda11.7。

跟着下面的教程做:

conda虚拟环境中安装cuda和cudnn,再也不用头疼版本号的问题了

bash 复制代码
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64/cudatoolkit-11.7.1-h4bc3d14_13.conda
conda install --use-local cudatoolkit-11.7.1-h4bc3d14_13.conda
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64/cudnn-8.9.7.29-hcdd5f01_2.conda
conda install --use-local cudnn-8.9.7.29-hcdd5f01_2.conda

安装其他依赖

记得在requirements.txt中增加tensorboard、h5py

bash 复制代码
pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2 -f https://download.pytorch.org/whl/torch_stable.html
pip install -r requirements.txt

检查torch是否安装正确以及cuda版本

bash 复制代码
python
import torch
torch.cuda.is_available()
torch.version.cuda

二、准备数据

1. 权重文件

pre-trained-models放在 DepthAnythingV2/checkpoints 文件夹

2. 训练数据

训练的时候需要,我这里之前就准备了vkitti。我先用vkitti数据跑一下试一下。

三、Test

Running script on images:

bash 复制代码
python run.py \
  --encoder <vits | vitb | vitl | vitg> \
  --img-path <path> --outdir <outdir> \
  [--input-size <size>] [--pred-only] [--grayscale]

Options:

  • --img-path: You can either 1) point it to an image directory storing all interested images, 2) point it to a single image, or 3)
    point it a text file storing all image paths.
  • --input-size (optional): By default, we use input size 518 for model inference. You can increase the size for even more fine-grained
    results.
  • --pred-only (optional): Only save the predicted depth map, without raw image.
  • --grayscale (optional): Save the grayscale depth map, without applying color palette.

For example:

bash 复制代码
python run.py --encoder vitl --img-path assets/examples --outdir depth_vis

Running script on videos

bash 复制代码
python run_video.py \
  --encoder <vits | vitb | vitl | vitg> \
  --video-path assets/examples_video --outdir video_depth_vis \
  [--input-size <size>] [--pred-only] [--grayscale]

Our larger model has better temporal consistency on videos.

四、Train

根据自己的数据修改DepthAnythingV2/metric_depth/dataset/splits和train.py中的路径数据

bash 复制代码
sh dist_train.sh

但我运行不了这个sh文件,所以我选择直接配置.vscode/launch.json。并且我将我的train代码改为了非分布式的。

bash 复制代码
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python 调试程序: train.py",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/metric_depth/train.py",
            "console": "integratedTerminal",
            "args": [
                "--epoch", "120",
                "--encoder", "vitl",
                "--bs", "2",
                "--lr", "0.000005",
                "--save-path", "./exp/vkitti",
                "--dataset", "vkitti",
                "--img-size", "518",
                "--min-depth", "0.001",
                "--max-depth", "20",
                "--pretrained-from", "./checkpoints/depth_anything_v2_vitl.pth", 
            ],
            "env": {
                "MASTER_ADDR": "localhost",
                "MASTER_PORT": "20596"
            }
        },
        {
            "name":"Python 调试程序: run.py",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/run.py",
            "console": "integratedTerminal",
            "args": [
                "--encoder", "vitl",
                "--img-path", "assets/examples",
                "--outdir", "output/depth_anything_v2_vitl_test",
                "--checkpoints","checkpoints/depth_anything_v2_vitl_test.pth"
            ],
        }
    ]
}
相关推荐
Brookty9 小时前
【算法】位运算| & ^ ~ -n n-1
学习·算法·leetcode·位运算
shenghaide_jiahu9 小时前
数学分析简明教程——1.4(未完)
学习
tritone10 小时前
在优豆云的免费云服务器上开启MongoDB学习之旅
服务器·学习·mongodb
俊俊谢11 小时前
【第一章】金融数据的获取——金融量化学习入门笔记
笔记·python·学习·金融·量化·akshare
Yupureki11 小时前
从零开始的C++学习生活 20:数据结构与STL复习课(4.4w字全解析)
c语言·数据结构·c++·学习·visual studio·1024程序员节
大白的编程日记.11 小时前
计算机网络学习笔记】初始网络之网络发展和OSI七层模型
笔记·学习·计算机网络
~kiss~13 小时前
spark-SQL学习
sql·学习·spark
cpq3713 小时前
AI学习研究——KIMI对佛教四圣谛深度研究
人工智能·学习
DSP 电源笔记君14 小时前
电子电力技术的准谐振电路和LLC电路相关习题学习记录分享
学习·dsp开发·电源开发·电力电子技术
_dindong15 小时前
【递归、回溯、搜索】专题六:记忆化搜索
数据结构·c++·笔记·学习·算法·深度优先·哈希算法