mmdetection配置

mmdetection配置

简介

商汤科技(2018 COCO 目标检测挑战赛冠军)和香港中文大学最近开源了一个基于Pytorch实现的深度学习目标检测工具箱mmdetection,支持Faster-RCNN,Mask-RCNN,Fast-RCNN,Cascade-RCNN等主流目标检测框架。可以快速部署自己的模型。

环境要求

  1. Linux (不支持windows)
  2. Python 3.5+
  3. >=PyTorch 1.1
  4. >=CUDA 9.0
  5. NCCL 2
  6. >=GCC 4.9
  7. 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

git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
pip install .
安装依赖包:
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 结果:

你可能感兴趣的:(视觉,深度学习,pytorch)