一. 环境配置
1. 安装Anaconda
最新版即可,详见:配置深度学习环境(Linux服务器)
2. 创建conda环境
conda create -n MVSNet python=3.7
激活环境
conda activate MVSNet
3. 在conda中安装Pytorch
根据CUDA版本在pytorch官网中找到对应的下载(我的CUDA是11.4)
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch
Pytorch版本一定要和cuda对应,不要直接粘贴上文,否则有问题!
4. 安装各种包
安装OpenCV
pip install opencv_python==3.4.2.17
pip install opencv-contrib-python==3.4.2.17
安装tensorboard
pip install protobuf==3.19.1
pip install tensorboardX==1.8
pip install tensorboard==1.14.0
如果还缺什么,就装什么。
至此,环境就配好了!
二. 测试
1. 测试代码(自己写的)
随机生成图像和内外参,可以快速测试代码并学习网络。
python temp.py --numdepth=192
import argparse
import torch
import torch.backends.cudnn as cudnn
from models import *
from utils import *
cudnn.benchmark = True
parser = argparse.ArgumentParser(description='A PyTorch Implementation of MVSNet')
parser.add_argument('--model', default='mvsnet', help='select model')
parser.add_argument('--lr', type=float, default=0.001, help='learning rate')
# 训练中采用了动态调整学习率的策略,在第10,12,14轮训练的时候,让learning_rate除以2变为更小的学习率
parser.add_argument('--lrepochs', type=str, default="10,12,14:2", help='epoch ids to downscale lr and the downscale rate')
# weight decay策略,作为Adam优化器超参数,实现中并未使用
parser.add_argument('--wd', type=float, default=0.0, help='weight decay')
#parser.add_argument('--batch_size', type=int, default=12, help='train batch size')
# 深度假设数量,一共假设这么多种不同的深度,在里面找某个像素的最优深度
parser.add_argument('--numdepth', type=int, default=192, help='the number of depth values')
# 深度假设间隔缩放因子,每隔interval假设一个新的深度,这个interval要乘以这个scale
parser.add_argument('--interval_scale', type=float, default=1.06, help='the number of depth values')
model = MVSNet(refine=False).cuda()
with torch.no_grad():
imgs = torch.rand((4, 3, 3, 512, 640)).cuda()
proj_matrices = torch.rand((4, 3, 4, 4)).cuda()
depth_values = torch.rand((4, 192)).cuda()
model(imgs, proj_matrices, depth_values)
2. train.sh(改路径即可)
#!/usr/bin/env bash
MVS_TRAINING="/data/dtu/mvs_training/dtu/"
CUDA_VISIBLE_DEVICES=1 python train.py --dataset=dtu_yao --batch_size=2 --trainpath=$MVS_TRAINING --trainlist lists/dtu/train.txt --testlist lists/dtu/test.txt --numdepth=192 --logdir ./checkpoints/d192 $@
3. eval.sh(改路径即可)
#!/usr/bin/env bash
DTU_TESTING="/data/dtu_test/"
CKPT_FILE="./checkpoints/d192/model_000004.ckpt"
CUDA_VISIBLE_DEVICES=1 python eval.py --dataset=dtu_yao_eval --batch_size=1 --testpath=$DTU_TESTING --testlist lists/dtu/test.txt --loadckpt $CKPT_FILE $@
记得把eval.py中的save_depth()之前的#去掉,要不然跑不通!
一点心得1:网上有很多博主写了配环境的帖子,参考之后我并没有配置成功,猜测可能是因为服务器等客观因素吧。只能说,每个博主至少在自己机子上是可以运行的,包括我这篇,但不代表你就能成功!建议大家直接先在自己配好的环境里跑一下试试(有项目可以直接成功运行的环境),没准大力就出奇迹了!!!
一点心得2:阅读原码的时候,千万别手抖,删了什么或者加了空格,一旦原码报错,还找不到问题,简直怀疑人生!!!