記錄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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM