mmdetection配置
簡介
商湯科技(2018 COCO 目標檢測挑戰賽冠軍)和香港中文大學最近開源了一個基於Pytorch實現的深度學習目標檢測工具箱mmdetection,支持Faster-RCNN,Mask-RCNN,Fast-RCNN,Cascade-RCNN等主流目標檢測框架。可以快速部署自己的模型。
環境要求
- Linux (不支持windows)
- Python 3.5+
- >=PyTorch 1.1
- >=CUDA 9.0
- NCCL 2
- >=GCC 4.9
- mmcv
安裝過程簡介:
1.Ubuntu18.04
2.安裝NVIDIA顯卡驅動與CUDA
3.安裝NCCL
4.安裝anaconda
5.安裝Pytorch和Torchvision
6.安裝mmcv
7.安裝mmdetection
8.測試
參考:https://blog.csdn.net/No__names/article/details/90708566
步驟
2、安裝驅動
https://www.cnblogs.com/aclearn/p/9463958.html
https://www.cnblogs.com/zmbreathing/p/Nvidia-driver_ubuntu.html
https://www.jianshu.com/p/e2a15336f174
驅動ok
CUDA配置:(>=9.0
cuda10.0
https://blog.csdn.net/EliminatedAcmer/article/details/80528980
result=pass 安裝成功
ok
3、NCCL 2 配置:
參考:https://blog.csdn.net/No__names/article/details/90708566
nccl2.5.6
sudo dpkg -i nccl-repo-ubuntu1804-2.5.6-ga-cuda10.0_1-1_amd64.deb
sudo apt update
//網絡安裝需要下一個命令 本地安裝不需要
sudo apt install libnccl2 = 2.5.6-1 + cuda10.0 libnccl-dev = 2.5.6-1 + cuda10.0
4、anaconda 配置
anaconda
Anaconda(官方網站)就是可以便捷獲取包且對包能夠進行管理,同時對環境可以統一管理的發行版本。Anaconda包含了conda、Python在內的超過180個科學包及其依賴項。
Anaconda是一個包含180+的科學包及其依賴項的發行版本。其包含的科學包包括:conda, numpy, scipy, ipython notebook等。
參考官方文檔:https://docs.anaconda.com/anaconda/install/linux/
1.前往官方下載頁面下載 Python3.7
2.啓動終端 輸入 sha256sum /path/filename
3.bash ~/Downloads/Anaconda3-2019.10-Linux-x86_64.sh
4.source ~/.bashrc //啓動
驗證安裝:
https://docs.anaconda.com/anaconda/install/verify-install/
打開Anaconda Prompt或終端後,選擇以下任何一種方法進行驗證:
- 輸入。如果Anaconda已安裝且正在運行,它將顯示已安裝軟件包及其版本的列表。
conda list
- 輸入命令
python
。此命令運行Python Shell。如果Anaconda已安裝且正在運行,則其啓動時顯示的版本信息將包含“ Anaconda”。要退出Python Shell,請輸入命令quit()
。 - 使用命令打開Anaconda Navigator
anaconda-navigator
。如果正確安裝了Anaconda,Anaconda Navigator將打開。
conda
conda是包及其依賴項和環境的管理工具。
適用語言:Python, R, Ruby, Lua, Scala, Java, JavaScript, C/C++, FORTRAN。
適用平臺:Windows, macOS, Linux
用途:
快速安裝、運行和升級包及其依賴項。
在計算機中便捷地創建、保存、加載和切換環境
conda爲Python項目而創造,但可適用於上述的多種語言。
conda包和環境管理器包含於Anaconda的所有版本當中。
pip
pip是用於安裝和管理軟件包的包管理器。
pip編寫語言:Python。
Python中默認安裝的版本:
Python 2.7.9及後續版本:默認安裝,命令爲pip
Python 3.4及後續版本:默認安裝,命令爲pip3
virtualenv
virtualenv:用於創建一個獨立的Python環境的工具。
解決問題:
當一個程序需要使用Python 2.7版本,而另一個程序需要使用Python 3.6版本,如何同時使用這兩個程序?
如果將所有程序都安裝在系統下的默認路徑,如:/usr/lib/python2.7/site-packages,當不小心升級了本不該升級的程序時,將會對其他的程序造成影響。
如果想要安裝程序並在程序運行時對其庫或庫的版本進行修改,都會導致程序的中斷。
在共享主機時,無法在全局site-packages目錄中安裝包。
virtualenv將會爲它自己的安裝目錄創建一個環境,這並不與其他virtualenv環境共享庫;同時也可以選擇性地不連接已安裝的全局庫。
5、Pytorch 配置(>=1.1
conda創建一個虛擬環境
conda create -n open-mmlab python=3.7 -y #創建名爲open-mmlab,python版本爲3.7的虛擬環境
conda activate open-mmlab #進入虛擬環境
安裝pytorch及torchvision
https://pytorch.org/get-started/previous-versions/#linux-and-windows
# CUDA 10.0
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch //可去掉-c pytorch
conda 連接超時和獲取超時時間設置
conda config --show
conda config --set remote_connect_timeout_secs 60
conda config --set remote_read_timeout_secs 360
6.安裝mmcv
安裝依賴包:
pip install mmcv
pip install matplotlib
pip install seaborn
pip安裝時如果速度很慢,後面加 -i https://pypi.tuna.tsinghua.edu.cn/simple,使用國內源,例如使用清華源安裝mmcv:
pip install mmcv -i https://pypi.tuna.tsinghua.edu.cn/simple
必須先安裝mmcv,再運行setup.py編譯,不然會報錯。
7、安裝mmdetection
官方文檔https://github.com/jmu201521121021/mmdetection/blob/master/docs/INSTALL.md
下載mmdetection
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
安裝mmdetection
安裝構建要求,然後安裝mmdetection。(我們通過github repo而不是pypi安裝pycocotools,因爲pypi版本較舊並且與最新的numpy不兼容。)
pip install -r requirements/build.txt
pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
pip install -v -e . # or "python setup.py develop
8、test.py
驗證,下載Faster R-CNN 的pth或者Cascade R-CNN 的pth;
代碼在mmdetection目錄下,在conda創建一個虛擬環境open-mmlab中運行test.py
from mmdet.apis import init_detector, inference_detector, show_result
import mmcv
config_file = 'configs/faster_rcnn_r50_fpn_1x.py'
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth'
# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# test a single image and show the results
img = 'demo/test.jpg' # or img = mmcv.imread(img), which will only load it once
result = inference_detector(model, img)
# visualize the results in a new window
show_result(img, result, model.CLASSES)
# or save the visualization results to image files
show_result(img, result, model.CLASSES, out_file='demo/result.jpg')
Cascade R-CNN 結果: