【从零开始复现PVnet】(下)复现PVNet

本文详细介绍了在Ubuntu18.04系统中安装CUDA10.2、配置PyTorch1.5.1和TensorFlow相关库,以及如何搭建并复现PVNet位姿估计网络的过程,包括环境配置、代码下载、编译步骤和训练测试方法。
摘要由CSDN通过智能技术生成

环境:
ubuntu18.04
GPU:GTX1060
显卡驱动版本:nvidia-driver-470
pytorch 1.5.1 + torchvision0.6.0+ cuda10.2
参考链接:
ubuntu安装cuda-10.2以及对应版本的cudnn
PVNet位姿估计网络简单复现2022-5-21
Ubuntu18.04系统搭建深度学习环境
【复现笔记】clean-pvnet复现

一. 搭建pvnet虚拟环境

1.下载代码

地址:https://github.com/zju3dv/clean-pvnet

2.配置环境

conda create -n pvnet python=3.7
conda activate pvnet
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.2 -c pytorch 
pip install Cython==0.28.2
sudo apt-get install libglfw3-dev libglfw3

在这里插入图片描述
为了防止出错,我接下来是直接根据requirement.txt中需要的包,一个一个手动pip的

yacs==0.1.4 -i https://pypi.tuna.tsinghua.edu.cn/simple/
numpy==1.21.6 -i https://pypi.tuna.tsinghua.edu.cn/simple/
opencv-python==3.4.2.17 -i https://pypi.tuna.tsinghua.edu.cn/simple/
tqdm==4.28.1 -i https://pypi.tuna.tsinghua.edu.cn/simple/
pycocotools==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/
matplotlib==2.2.2 -i https://pypi.tuna.tsinghua.edu.cn/simple/
plyfile==0.6 -i https://pypi.tuna.tsinghua.edu.cn/simple/
scikit-image==0.14.2 -i https://pypi.tuna.tsinghua.edu.cn/simple/
PyOpenGL==3.1.1a1 -i https://pypi.tuna.tsinghua.edu.cn/simple/
ipdb==0.13 -i https://pypi.tuna.tsinghua.edu.cn/simple/
cyglfw3==3.1.0.2 -i https://pypi.tuna.tsinghua.edu.cn/simple/
pyassimp==3.3 -i https://pypi.tuna.tsinghua.edu.cn/simple/
progressbar==2.5 -i https://pypi.tuna.tsinghua.edu.cn/simple/
open3d-python==0.5.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/
tensorboardX==1.2 -i https://pypi.tuna.tsinghua.edu.cn/simple/
cffi==1.11.5 -i https://pypi.tuna.tsinghua.edu.cn/simple/
transforms3d -i https://pypi.tuna.tsinghua.edu.cn/simple/
pillow==6.2.1 -i https://pypi.tuna.tsinghua.edu.cn/simple/

3.编译cuda拓展

ROOT=~/pvnet/clean-pvnet #存放项目的目录
cd $ROOT/lib/csrc
export CUDA_HOME="/usr/local/cuda-10.2" #这一步我省去了,因为之前安装完整版CUDA的时候已经配置了环境变量
cd ransac_voting
python setup.py build_ext --inplace
cd ../nn
python setup.py build_ext --inplace
cd ../fps
python setup.py build_ext --inplace
If you want to run PVNet with a detector

** 注意,后面的会开始报错了 **

# If you want to run PVNet with a detector
cd ../dcn_v2
python setup.py build_ext --inplace

dcn_v2是一个可变性卷积的包,如果在我的环境下直接编译的话,回报错,我也搜过相关的文章,去改源代码,最终还是没办法解决。
后来查询到是由于pytorch版本不匹配的原因,修改pytorch版本比较复杂,而且会影响其他包,所以我就找到了适合各torch版本dcn_v2的编译包。
然后替换掉原作者的dcn_v2文件夹

1.5版本 可变性卷积下载地址:
https://github.com/lbin/DCNv2/tree/pytorch_1.5
然后进入dcn_v2目录 执行

./make.sh         # build
python testcuda.py   # run examples and gradient check on gpu 

在这里插入图片描述
继续编译:

# If you want to use the uncertainty-driven PnP
cd ../uncertainty_pnp
sudo apt-get install libgoogle-glog-dev
sudo apt-get install libsuitesparse-dev
sudo apt-get install libatlas-base-dev
python setup.py build_ext --inplace

三.测试项目

1.设置数据集

将下载好的linemod数据集放在data文件夹下,文件夹名称是linemod
再从作者提供的链接下载名为cat_199.pth文件,保存至data/model/pvnet/cat文件夹内,== 更改文件名为199.pth ==
在这里插入图片描述
运行以下命令进行数据集的prepare

python run.py --type linemod cls_type cat

2.测试

运行以下命令进行测试

python run.py --type evaluate --cfg_file configs/linemod.yaml model cat cls_type cat
python run.py --type evaluate --cfg_file configs/linemod.yaml test.dataset LinemodOccTest model cat cls_ty

第一次运行时会从pytorch官网下载resnet的预训练文件

在这里插入图片描述

3.可视化

python run.py --type visualize --cfg_file configs/linemod.yaml model cat cls_type cat

在这里插入图片描述

四.训练网络

输入指令开始训练:

python run.py --type custom
python train_net.py --cfg_file configs/custom.yaml train.batch_size 4

遇到报错:
在这里插入图片描述
搜索解决方案发现是缺少包

pip install protobuf==3.19.0

安装之后开始训练:
这是训练了一晚上的效果,1060显卡还是太慢了
在这里插入图片描述
每5个epoch保存一个pth文件,训练得到54.pth,

python run.py --type visualize --cfg_file configs/custom.yaml

这是训练了54轮的效果
在这里插入图片描述
运行下面的命令可以看评价指标

python run.py --type evaluate --cfg_file configs/custom.yaml

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fate-Sky

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值