目前正在看ABCNet,其中的代码用到了detectron2,环境配置也是踩了一点点坑,所以整理一下整个的环境搭建和训练过程。
使用的是矩池云的服务器,pytorch、cuda等环境都已经提前选好了。
环境搭建:
提前建一个文件夹ABC,进入ABC中
进入文件夹ABC中
第一步:安装相关库
这里我先安装了这两个,后面有缺的可以再安装
pip install pythran scikit-image
pip install ninja yacs cython matplotlib tqdm opencv-python shapely scipy tensorboardX pyclipper Polygon3 editdistance
第二步:下载 detectron2
这里主要参照了这篇文章AdelaiDet安装报错,如果不提前checkout,后续会报错
git clone https://github.com/facebookresearch/detectron2.git
cd detectron2
git checkout -f 9eb4831
cd ..
python -m pip install -e detectron2/
第三步:下载 AdelaiDet并运行setup.py
在运行setup.py时如果遇到缺包少包的情况,可以安装对应包后再重新运行。
git clone https://github.com/aim-uofa/AdelaiDet.git
cd AdelaiDet
python setup.py build develop -i https://pypi.tuna.tsinghua.edu.cn/simple
注意:安装包的时候如果遇到报错,可能是对应的镜像源找不到,可以换其他镜像源
其他镜像源:
https://pypi.tuna.tsinghua.edu.cn/simple
https://mirrors.aliyun.com/pypi/simple/
https://mirrors.163.com/pypi/simple/
https://pypi.douban.com/simple/
https://pypi.mirrors.ustc.edu.cn/simple/
至此,环境已经搭建好了。
如果环境没有问题的话,根据ABCNet的readme文档,使用wget -O tt_attn_R_50.pth https://cloudstor.aarnet.edu.au/plus/s/tYsnegjTs13MwwK/download下载文件之后就可以运行demo文件,对输入图片进行文本检测并返回结果图片。
在训练部分遇到的报错包括:
1.内存不足
训练部分要求的内存很大,如果租服务器的话,要尝试租显存大的,或者租双GPU,
2.rapidfuzz包版本过高
解决方式:降低该包版本为1.1.1版本
pip install rapidfuzz==1.1.1
3.AssertionError: Checkpoint detectron2://ImageNetPretrained/MSRA/R-50.pkl not found!
这里参照了https://blog.csdn.net/chenfang0529/article/details/124290320,我是使用安装fvcore解决的
pip install fvcore==0.1.1.dev200512