记录CenterNet代码编译成功运行
一开始没有安装anaconda,直接用的python,安包也是各种pip,遇到了非常多的bug,改到怀疑人生,强烈建议先安装anaconda,建立python3.6的虚拟环境,再进行网络的安装编译运行。
首先要检查自己的环境,环境不对的话,后期会出现奇奇怪怪的问题。程序所需环境为:cuda9.0 , torch0.4.1,cudnn7.0,我是在Ubuntu16.04中运行的。
1.创建python3.6的环境,并激活环境,可以在终端输入python,查看自己的版本。
2.安装torch,或者输入python,import torch,print(torch__version__)可以查看torch的版本,没有的话用conda进行安装。
运行nvcc -V命令,查看自己的cuda版本是否为9.0.
cuda9.0linux安装可以参考https://blog.csdn.net/qq_25241325/article/details/90753830
如果官网安装太慢的话,可以加清华源的镜像,去掉-c pytorch 进行安装。
3.把官网上的代码git下来,按照CenterNet官网里的INSTALL,进行requirements.txt的安装和COCOAPI的安装(注意:先安装requirements.txt,因为COCOAPI需要里面的CPython)。
API需要make,按照官网操作即可
4.编译DCNv2,这一步如果出现一大串的问题,基本都是cuda路径没设置对的原因。
5.编译成功后,即可运行demo.py,会出现以下报错:
解决方法:
还会出现错误:
解决方法:(要提前mkdir output)
最后就可以成功运行demo.py啦!!!放个效果图,识别的还是可以的
新手一枚,之前因为环境的原因,改了许多奇怪的bug,这里记录一下,希望能够帮到小伙伴们。
————————————————————————————————————————————————————————————————————————————————————————————————————————————————
CenterNet官网里的INSTALL文档:
# Installation
The code was tested on Ubuntu 16.04, with [Anaconda](https://www.anaconda.com/download) Python 3.6 and [PyTorch]((http://pytorch.org/)) v0.4.1. NVIDIA GPUs are needed for both training and testing.
After install Anaconda:
0. [Optional but recommended] create a new conda environment.
~~~
conda create --name CenterNet python=3.6
~~~
And activate the environment.
~~~
conda activate CenterNet
~~~
1. Install pytorch0.4.1:
~~~
conda install pytorch=0.4.1 torchvision -c pytorch
~~~
And disable cudnn batch normalization(Due to [this issue](https://github.com/xingyizhou/pytorch-pose-hg-3d/issues/16)).
~~~
# PYTORCH=/path/to/pytorch # usually ~/anaconda3/envs/CenterNet/lib/python3.6/site-packages/
# for pytorch v0.4.0
sed -i "1194s/torch\.backends\.cudnn\.enabled/False/g" ${PYTORCH}/torch/nn/functional.py
# for pytorch v0.4.1
sed -i "1254s/torch\.backends\.cudnn\.enabled/False/g" ${PYTORCH}/torch/nn/functional.py
~~~
For other pytorch version, you can manually open `torch/nn/functional.py` and find the line with `torch.batch_norm` and replace the `torch.backends.cudnn.enabled` with `False`. We observed slight worse training results without doing so.
2. Install [COCOAPI](https://github.com/cocodataset/cocoapi):
~~~
# COCOAPI=/path/to/clone/cocoapi
git clone https://github.com/cocodataset/cocoapi.git $COCOAPI
cd $COCOAPI/PythonAPI
make
python setup.py install --user
~~~
3. Clone this repo:
~~~
CenterNet_ROOT=/path/to/clone/CenterNet
git clone https://github.com/xingyizhou/CenterNet $CenterNet_ROOT
~~~
4. Install the requirements
~~~
pip install -r requirements.txt
~~~
5. Compile deformable convolutional (from [DCNv2](https://github.com/CharlesShang/DCNv2/tree/pytorch_0.4)).
~~~
cd $CenterNet_ROOT/src/lib/models/networks/DCNv2
./make.sh
~~~
6. [Optional, only required if you are using extremenet or multi-scale testing] Compile NMS if your want to use multi-scale testing or test ExtremeNet.
~~~
cd $CenterNet_ROOT/src/lib/external
make
~~~
7. Download pertained models for [detection]() or [pose estimation]() and move them to `$CenterNet_ROOT/models/`. More models can be found in [Model zoo](MODEL_ZOO.md).
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
参考博客:https://blog.csdn.net/m0_37798080/article/details/101196884#demopy_52
https://blog.csdn.net/mary_0830/article/details/103333639#comments_12208483
https://blog.csdn.net/weixin_38715903/article/details/98039181