mmdetection框架的安装、训练与测试

1、框架介绍

mmdetection is an open source object detection toolbox based on PyTorch. It is a part of the open-mmlab project developed by Multimedia Laboratory, CUHK.
Major features
1、Modular Design
We decompose the detection framework into different components and one can easily construct a customized object detection framework by combining different modules.
2、Support of multiple frameworks out of box
The toolbox directly supports popular and contemporary detection frameworks, e.g. Faster RCNN, Mask RCNN, RetinaNet, etc.
3、High efficiency
All basic bbox and mask operations run on GPUs now. The training speed is faster than or comparable to other codebases, including Detectron, maskrcnn-benchmark and SimpleDet.
4、State of the art
The toolbox stems from the codebase developed by the MMDet team, who won COCO Detection Challenge in 2018, and we keep pushing it forward.

2、环境配置

Requirements
1、Linux (Windows is not officially supported)
2、CUDA 9.0 or higher
3、GCC(G++) 4.9/5.3/5.4/7.3(Important)
4、Python 3.5+ (Python 2 is not supported)
5、PyTorch 1.1 or higher

1、Anaconda安装

#安装
bash /download_path/Anaconda3-5.3.1-Linux-x86_64.sh
.......
#修改路径
Anaconda3 will now be installed into this location:
/home/jyjiang/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/home/jyjiang/anaconda3] >>> /your_path/anaconda3 #修改
  • 添加清华源(下载速度更快)
# 添加Anaconda的TUNA镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
  • 修改~/.bashrc文件
vim ~/.bashrc
#anaconda3
export PATH=/data/jyjiang/Software/anaconda3/bin:$PATH

2、创建虚拟环境并激活

#创建
conda create -n mmlab python=3.7 
.....
#激活
conda activate mmlab

3、Pytorch下载安装
官网查询满足自身环境(cuda/python等版本匹配)的下载命令:
在这里插入图片描述

注意:如果Run this Command下载的速度较慢,则选用手动下载并安装方式
1、到官网下载pytorch的.whl文件
在这里插入图片描述
2、到官网下载torchvision的.whl文件(与pytorch在同一地址下)
在这里插入图片描述
3、用pip安装pytorch与torchvision
#pytorch与torchvision版本匹配可以直接按照官网推荐的Run this Command中的版本下载
pip install /download_path/torch-1.1.0-cp37-cp37m-linux_x86_64.whl
pip install /download_path/torchvision-0.3.0-cp37-cp37m-manylinux1_x86_64.whl
4、用conda安装cudatoolkit
# CUDA 9.0
conda install cudatoolkit=9.0

4、下载mmdetection框架

git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection

5、安装mmdetection框架

pip install mmcv
python setup.py develop

注意:已经完成了所有安装步骤,若会出现安装过程中的错误,一般是Pytorch/GCC/CUDA版本不匹配的问题,可以按照如下命令检查各自的版本:
#Pytorch/Torchvision
>>>python
>>>import torch
>>>import torchvision
>>>torch.version.cuda
‘10.0.130’
>>>torchvision.version.cuda
10000
#CUDA
>>>nvcc -V
nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130
#GCC
>>>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/data/jqlin/gcc/libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: …/configure --prefix=/data/jqlin/gcc -enable-checking=release -enable-languages=c,c++ -disable-multilib
Thread model: posix
gcc version 5.4.0 (GCC)

3、训练和测试

#训练
1、导入训练数据
coco数据组织或者

对数据建立软连接

ln -s /data/datasets/coco2017 /home/jyjiang/jyjiang/Project/MMdetection/data/coco

2、训练模型

python tools/test.py configs/mask_rcnn_r50_fpn_1x.py \
      checkpoints/mask_rcnn_r50_fpn_1x_20181010-069fa190.pth \
      --out results.pkl --eval bbox segm

训练过程
#测试
1、到Model zoo下载训练好的模型,将其放在mmdetection/checkpoints(自建)文件夹下
2、在demo文件夹下写一个image_test.py文件

from mmdet.apis import init_detector, inference_detector, show_result
import mmcv
config_file = '../configs/mask_rcnn_r50_fpn_1x.py'
checkpoint_file = '../checkpoints/mask_rcnn_r50_fpn_1x_20181010-069fa190.pth'
model = init_detector(config_file, checkpoint_file, device='cuda:0')
img = 'demo.jpg'  
result = inference_detector(model, img)
show_result(img, result, model.CLASSES, show=False, out_file='result.jpg')

3、结果展示
demo.jpg
city.jpg

发布了26 篇原创文章 · 获赞 65 · 访问量 4301

猜你喜欢

转载自blog.csdn.net/qq_40263477/article/details/103620492
今日推荐