基于pytorch的faster-rcnn目标检测框架

paper:Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
pytorch-faster-rcnn github-----pytorch-faster-rcnn

1. 简介

faster rcnn是何凯明等大神在2015年提出目标检测算法, 一直作为经典的两阶段检测算法。该算法在2015年的ILSVRV和COCO竞赛中获得多项第一。本检测框架是基于pytorch实现的faster rcnn源码。详细的论文细节请参考Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks

本检测框架有如下特点:

  • 纯python代码, 完全是基于pytorch,不需要额外build
  • 个性化配置,超参数只需要在配置文件中进行配置即可进行配置
  • 有多个backbone训练网络. 包括vgg, resnet-fpn, mobilenet, high resolution net(HRNet)等
  • 只需修改配置参数即可进行不同模型的训练,对比不同超参数
  • 内存占用少,vgg16只需3G左右

2. 安装

2.1 Prerequisites

  • Python 2.7 or 3.5
  • Pytorch 1.5.1
  • torchvision 0.6.1
  • numpy 1.15.4
  • Pillow 6.1.0
  • pycocotools 2.0
  • matplotlib 3.0.2
  • tensorboardX 2.0
pip install -r requirements.txt

2.2 Code-Preparing

 git clone https://github.com/AlphaJia/pytorch-faster-rcnn.git

3. Data Preparation

COCO

3.1 下载 training, validation, test data and annotations
 wget http://images.cocodataset.org/zips/train2017.zip  
 wget http://images.cocodataset.org/zips/val2017.zip
 wget http://images.cocodataset.org/zips/test2017.zip
 wget http://images.cocodataset.org/annotations/annotations_trainval2017.zip
3.2 解压下载后的下载文件,放置在文件中,命名为COCODevKit
 tar xvf train2017.zip
 tar xvf val2017.zip
 tar xvf test2017.zip
 tar xvf annotations_trainval2017.zip
3.3 数据目录应该如下
   COCODevKit
       |-- train2017
               |-- [xxxxxxxxxxxx].jpg
       |-- val2017
               |-- [xxxxxxxxxxxx].jpg
       |-- test2017
               |-- [xxxxxxxxxxxx].jpg
       |-- annotations
               |-- instances_train2017.json
               |-- instances_val2017.json
               |-- image_info_test2017.json
3.4 更改config/train_config.py中的data_root_dir为/path/COCODevKit/

4. Train

更改config/train_config.py中的相关参数。model_save_dir为模型保存的路径,device_name为你自己的训练设备

  • Train with mobilenet
    更改config/train_config.py里面的backbone为 mobilenet, 下载预训练模型这里, 修改 backbone_pretrained_weights为下载路径
 python train.py
  • Train with resnet-fpn
    更改config/train_config.py里面的backbone为 resnet50_fpn, 下载预训练模型这里, 修改 backbone_pretrained_weights为下载路径
 python train.py
  • Train with vgg16
    更改config/train_config.py里面的backbone为 vgg16
 python train.py
  • Train with HRNet
    更改config/train_config.py里面的backbone为 HRNet
 python train.py

模型和tensorboard log 保存在model_save_path 路径下面
config/train_config.py 也有许多超参数可以设置.
一些主要的参数:
--backbone: 主干特征提取网络
--backbone_pretrained_weights: 主干网络预训练地址
--train_horizon_flip_prob: 水平翻转概率
--num_class: 目标检测类别数目
--data_root_dir: COCO 数据集根目录
--model_save_dir: 训练模型保存位置
--device_name: 训练设备
--num_epochs: 训练 epochs

5. Test

更改config/test_config.py里面 model_weights为模型路径,gpu_id 为cuda设备编号
config/test_config.py 里面也有可以设置的参数.
主要是设置参数如下:
--model_weights: 模型路径
--image_path: 预测图片
--gpu_id: cuda设备编号
--num_classes: 目标检测类别数目
--data_root_dir: COCO 数据集根目录

 python test.py

6. Demo

基于pytorch的faster-rcnn目标检测框架_第1张图片

7. Wiki

wiki地址

喜欢的话star一下GitHub仓库哦
pytorch-faster-rcnn github-----pytorch-faster-rcnn
如有任何问题,请联系:wanniejpf@qq.com(回复的比较及时)

你可能感兴趣的:(图像处理,图像识别,算法,pytorch)