本教程不讲DBNet原理,只讲如何部署,在Linux系统中,并实现训练icdar2015数据集
我使用的ssh工具是final shell,其实教程Readme里都有,但是初学者不一定会用,我教大家一个好用的顺序。当然我也是按照GitHub上的方式,只是优化了一下顺序。
第一步点开链接
DBNet有作者的第一个版本,和之后重构的,我这个是重构的版本
第二步 创建文件夹,在ssh命令行里输入
需要注意的是,torch的版本可以比cuda小,但是如果是编译的化,必须版本一致,不然上面倒数两行内容是编译不通过的,我这里安装的是cu113,我的cuda版本也应该是11.3才行
git clone https://github.com/MhLiao/DB.git
cd 到你DBNet到文件夹下
conda create --name DB -y python=3.8
conda activate DB
conda install ipython pip
pip install torch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 -f https://mirrors.aliyun.com/pytorch-wheels/cu113
pip install -r requirement.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
echo $CUDA_HOME
cd assets/ops/dcn/
python setup.py build_ext --inplace
跟DBNet作者不同的是,这里先安装torch和cuda,后安装requirement里的库
三、数据集准备
icdar2015,进入链接,注册之后下载红框里的内容
Downloads - Incidental Scene Text - Robust Reading Competition

在DBNet的根目录下新建一个名为datases的文件夹,之后在里面创建一个名为icdar2015的文件夹,之后访问
https://drive.google.com/drive/folders/12ozVTiBIqK8rUFWLUrlquNfoQxL2kAl7
这是作者提供的谷歌网盘链接,如果访问不了,就访问百度网盘 请输入提取码
提取码:0drc
下载icdar2015.zip,之后解压的内容是

把内容放到刚刚创建的icdar2015的文件中,在把在数据集官网下载的训练图片和测试图片的文件夹改名成train_images和test_images放到icdar2015文件夹中,最后是这样的。(DBNet提供训练集的标签文件和官网有点不同,一个命名是xx.txt,一个是xx.jpg.txt,这不重要,按我说的做就行)

四、训练与评估
训练:
CUDA_VISIBLE_DEVICES=0,1 python train.py experiments/seg_detector/ic15_resnet18_deform_thre.yaml --num_gpus 2举例,我有两种卡,那UDA_VISIBLE_DEVICES就是0,1,末尾使用的--num_gpus 就是2,如果你有四张,那前面是0,1,2,3,后面是 4
评估:
CUDA_VISIBLE_DEVICES=0 python eval.py experiments/seg_detector/ic15_resnet18_deform_thre.yaml --resume outputs/workspace/DB/SegDetectorModel-seg_detector/deformable_resnet18/L1BalanceCELoss/model/final --box_thresh 0.55
五、可能的错误
1:
echo $CUDA_HOME没有输出内容的话,可能是你的cuda没安装好,随便找个地方创建一个test.py文件,里面写
import torch
print(torch.__version__)
之后在命令行执行
python test.py
可以看到torch是否安装成功
2:
OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.
表示在环境变量里没有设置好,去home/你的用户的用户们下,找到.bashrc 文件,如果你会vim或者nano可以执行nano ~/.bashrc,之后把
export CUDA_HOME=/usr/local/cuda
添加到最后一行,不过要先确认你的cuda文件夹是否叫这个名,我的改成了cuda-11.3,自己去usr/local中确认一下
3:
‘AT_CHECK’ was not declared in this scope; did you mean ‘DCHECK’
参考下面的链接
错误:‘AT_CHECK’ was not declared in this scope; did you mean ‘DCHECK’?-CSDN博客
4:
AttributeError: module ‘numpy’ has no attribute ‘int’.
np.int was a deprecated alias for the builtin int. To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe.
简单来说,就是numpy的1.20以上的版本没有np.int了,换成了int,但是如果降级,牵一发而动全身,所有找到源码,不过要先备份哦,以防万一。
DB/structure/representers/seg_detector_representer.py的195行开始,把四个np.int改成int,
2141

被折叠的 条评论
为什么被折叠?



