A Simple and Fast Implementation of Faster R-CNN翻译文档(方便看)

A Simple and Fast Implementation of Faster R-CNN翻译文档(方便看)

此文档是翻译代码中的A Simple and Fast Implementation of Faster R-CNN项目中的README.MD文档,主要是为了方便自己更直观了解项目。 有些地方翻译不对还请指教😁(侵删)

1. 介绍

[更新:] 我进一步将代码简化为Pythorch1.5、TorchVision0.6,并用torchvision中的一个替换定制的OpsRoipool和nms。如果您想要旧版本代码,请切换分支 v1.0

This project is a Simplified Faster R-CNN implementation based on chainercv and other projects . 这个项目是一个简化的 Faster R-CNN,基于chainercv和其他 projects 。我希望它能成为那些想知道Faster R-CNN细节的人的开始代码。 它的目的是:

  • 简化代码(简单比复杂好
  • 使代码更直接(平面比嵌套好)
  • 原始文件中报告的性能匹配(速度计数和地图问题)

它具有以下特点:

  • 它可以作为纯Python代码运行,不再需要构建事务。
  • 这是一个最小的实现,大约有2000行有效代码,其中包含大量注释和说明(多亏了chainercv的优秀文档)
  • 它实现了比原始实现更高的映射(0.712 VS 0.699)
  • 它的速度可与其他实现相媲美(在TITAN XP中训练和测试为6fps和14fps)
  • 它的内存效率很高(vgg16约为3GB)
    在这里插入图片描述

2. 性能

2.1 mAP

VGG16在trainval 上训练,在 test 上测试

Note:训练显示出很大的随机性,你可能需要一点运气和更多的训练时间才能到达最高地图。 但是,它应该很容易超过下限。

实施方法mAP
原论文0.699
caffe预训练模式训练0.700-0.712
torchvision预训练模式训练0.685-0.701
chainercv 转换的模型(报告0.706)(reported 0.706)0.7053

2.2 速度

实施方法GPUInferenceTrainining
原论文K405 fpsNA
This[1]TITAN Xp14-15 fps6 fps
pytorch-faster-rcnnTITAN Xp15-17fps6fps

[1]: 确保正确安装了cupy并且GPU上只有一个程序运行。训练速度对你的gpu状态很敏感。 看 troubleshooting 获取更多信息. 而且在项目开始的时候很慢——需要时间来热身。

通过去除可视化、测井、平均损失等,可以更快地实现。

3. 安装依赖项

下面是一个使用“anaconda”从头创建环境的示例

# create conda env
conda create --name simp python=3.7
conda activate simp
# install pytorch
conda install pytorch torchvision cudatoolkit=10.2 -c pytorch

# install other dependancy
pip install visdom scikit-image tqdm fire ipdb pprint matplotlib torchnet

# start visdom
nohup python -m visdom.server &

如果你不使用anaconda,那么:

  • 使用GPU安装Pythorch(代码仅限GPU),请参阅官方网站

  • 安装其他依赖项: pip install visdom scikit-image tqdm fire ipdb pprint matplotlib torchnet

  • 用visdom可视化

nohup python -m visdom.server &

4. Demo演示

Google DriveBaidu Netdisk( passwd: scxn)下载预训练模型

查看demo.ipynb 获取更多细节。

5. 训练

5.1 准备数据

Pascal VOC2007
  1. 下载训练集,验证集,测试集数据和VOCdevkit

    wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
    wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
    wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar
    
  2. 将所有这些tar解压到一个名为’VOCdevkit的目录中`

    tar xvf VOCtrainval_06-Nov-2007.tar
    tar xvf VOCtest_06-Nov-2007.tar
    tar xvf VOCdevkit_08-Jun-2007.tar
    
  3. 它应该有这样的基本结构

    $VOCdevkit/                           # development kit
    $VOCdevkit/VOCcode/                   # VOC utility code
    $VOCdevkit/VOC2007                    # image sets, annotations, etc.
    # ... and several other directories ...
    
  4. utils/config.py修改 voc_data_dir cfg项, 或者使用诸如“-voc data dir=/path/to/VOCdevkit/VOC2007/`”之类的参数将其传递给程序。

5.2 [可选]准备 caffe-pretrained vgg16

如果您想使用caffe pretrain模型作为初始权重,可以运行下面的步骤从caffe得到vgg16权重,这与原论文的使用相同。

python misc/convert_caffe_pretrain.py

This scripts would download pretrained model and converted it to the format compatible with torchvision. If you are in China and can not download the pretrain model, you may refer to
这个脚本将下载经过预训练的模型并将其转换为与torchvision兼容的格式。如果您在中国无法下载pretrain模型,您可以参考 这里

然后您可以通过在caffe_pretrain_path中设置参数来指定caffe预训练模型 vgg16_caffe.pthutils/config.py 的存储位置。默认路径就可以。

如果要使用torchvision中的预训练模型,可以跳过这一步。
NOTE,caffe预训练模型表现出稍好的性能。

NOTE:caffe模型需要BGR 0-255中的图像,而torchvision模型需要RGB和0-1中的图像。查看data/数据集.py获取更多细节。

5.3 开始训练

python train.py train --env='fasterrcnn' --plot-every=100

您可以参考utils/config.py 获取更多的arguments。

一些关键的arguments:

  • --caffe-pretrain=False: 使用caffe或torchvision的pretrain模型(默认:torchvison)
  • --plot-every=n: 将预测、损失等每一批都可视化。
  • --env: 可视化visdom env
  • --voc_data_dir: VOC数据存储在哪里
  • --use-drop: 在RoI head中使用dropout,默认为False
  • --use-Adam: 使用Adam而不是默认的SGD。(你需要给Adam设置一个非常低的’lr’)
  • --load-path:预先训练的模型路径,默认为“None”,如果指定了它,它将被加载。

您可以打开浏览器,访问http://<ip>:8097,并看到以下培训过程的可视化:

在这里插入图片描述

Troubleshooting故障排除

  • 数据加载器:收到0项ancdata

    讨论, 在 train.py中已经被修复解决了. 所以我认为你不会有这个问题。

  • 支持windows

    我没有带GPU的windows机器来调试和测试它。如果有人可以提出拉取请求并进行测试,这是受欢迎的。

Acknowledgement

This work builds on many excellent works, which include:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值