diff --git a/fluid/faster_rcnn/README.md b/fluid/faster_rcnn/README.md
index b676cce670989e3e5f1f0b7014cebe96cd27fc42..75ff61a373dd973954a525e30893dc9553bbc865 100644
--- a/fluid/faster_rcnn/README.md
+++ b/fluid/faster_rcnn/README.md
@@ -7,7 +7,6 @@
- [Introduction](#introduction)
- [Data preparation](#data-preparation)
- [Training](#training)
-- [Finetuning](#finetuning)
- [Evaluation](#evaluation)
- [Inference and Visualization](#inference-and-visualization)
- [Appendix](#appendix)
@@ -24,10 +23,10 @@ Running sample code in this directory requires PaddelPaddle Fluid v.1.0.0 and la
Faster RCNN model
-1. Base conv layer。As a CNN objective dection, Faster RCNN extract feature maps using a basic convolutional network. The feature maps then can be shared by RPN and fc layers. This sampel uses [ResNet-50](https://arxiv.org/abs/1512.03385) as base conv layer.
-2. Region Proposal Network (RPN)。RPN generates proposals for detection。This block generates anchors by a set of size and ratio and classifies anchors into fore-ground and back-ground by softmax. Then refine anchors to obtain more precise proposals using box regression.
-3. RoI pooling。This layer takes feature maps and proposals as input. The proposals are mapped to feature maps and pooled to the same size. The output are sent to fc layers for classification and regression.
-4. Detection layer。Using the output of roi pooling to compute the class and locatoin of each proposal in two fc layers.
+1. Base conv layer. As a CNN objective dection, Faster RCNN extract feature maps using a basic convolutional network. The feature maps then can be shared by RPN and fc layers. This sampel uses [ResNet-50](https://arxiv.org/abs/1512.03385) as base conv layer.
+2. Region Proposal Network (RPN). RPN generates proposals for detection。This block generates anchors by a set of size and ratio and classifies anchors into fore-ground and back-ground by softmax. Then refine anchors to obtain more precise proposals using box regression.
+3. RoI Align. This layer takes feature maps and proposals as input. The proposals are mapped to feature maps and pooled to the same size. The output are sent to fc layers for classification and regression. RoIPool and RoIAlign are used separately to this layer and it can be set in roi\_func in config.py.
+4. Detection layer. Using the output of roi pooling to compute the class and locatoin of each proposal in two fc layers.
## Data preparation
@@ -42,10 +41,9 @@ Train the model on [MS-COCO dataset](http://cocodataset.org/#download), download
After data preparation, one can start the training step by:
python train.py \
- --max_size=1333 \
- --scales=[800] \
- --batch_size=8 \
- --model_save_dir=output/
+ --model_save_dir=output/ \
+ --pretrained_model=${path_to_pretrain_model}
+ --data_dir=${path_to_data}
- Set ```export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7``` to specifiy 8 GPU to train.
- For more help on arguments:
@@ -83,7 +81,7 @@ To train the model, [cocoapi](https://github.com/cocodataset/cocoapi) is needed.
**model configuration:**
-* Use RoIPooling.
+* Use RoIAlign and RoIPool separately.
* NMS threshold=0.7. During training, pre\_nms=12000, post\_nms=2000; during test, pre\_nms=6000, post\_nms=1000.
* In generating proposal lables, fg\_fraction=0.25, fg\_thresh=0.5, bg\_thresh_hi=0.5, bg\_thresh\_lo=0.0.
* In rpn target assignment, rpn\_fg\_fraction=0.5, rpn\_positive\_overlap=0.7, rpn\_negative\_overlap=0.3.
@@ -102,20 +100,10 @@ Training result is shown as below:
Faster RCNN train loss
-* Fluid all padding: Each image padding to 1333\*1333.
-* Fluid minibatch padding: Images in one batch padding to the same size. This method is same as detectron.
-* Fluid no padding: Images without padding.
-## Finetuning
-
-Finetuning is to finetune model weights in a specific task by loading pretrained weights. After initializing ```pretrained_model```, one can finetune a model as:
-
- python train.py
- --max_size=1333 \
- --scales=800 \
- --pretrained_model=${path_to_pretrain_model} \
- --batch_size= 8\
- --model_save_dir=output/
+* Fluid RoIPool minibatch padding: Use RoIPool. Images in one batch padding to the same size. This method is same as detectron.
+* Fluid RoIpool no padding: Use RoIPool. Images without padding.
+* Fluid RoIAlign no padding: Use RoIAlign. Images without padding.
## Evaluation
@@ -126,26 +114,28 @@ Evaluation is to evaluate the performance of a trained model. This sample provid
python eval_coco_map.py \
--dataset=coco2017 \
--pretrained_mode=${path_to_pretrain_model} \
- --batch_size=1 \
--nms_threshold=0.5 \
--score_threshold=0.05
+- Set ```export CUDA_VISIBLE_DEVICES=0``` to specifiy one GPU to eval.
+
Evalutaion result is shown as below:
Faster RCNN mAP
-| Model | Batch size | Max iteration | mAP |
-| :------------------------------ | :------------: | :-------------------:|------: |
-| Detectron | 8 | 180000 | 0.315 |
-| Fluid minibatch padding | 8 | 180000 | 0.314 |
-| Fluid all padding | 8 | 180000 | 0.308 |
-| Fluid no padding |8 | 180000 | 0.316 |
-
-* Fluid all padding: Each image padding to 1333\*1333.
-* Fluid minibatch padding: Images in one batch padding to the same size. This method is same as detectron.
-* Fluid no padding: Images without padding.
+| Model | RoI function | Batch size | Max iteration | mAP |
+| :--------------- | :--------: | :------------: | :------------------: |------: |
+| Detectron_RoIPool | RoIPool | 8 | 180000 | 0.315 |
+| Fluid RoIPool minibatch padding | RoIPool | 8 | 180000 | 0.314 |
+| Fluid RoIPool no padding | RoIPool | 8 | 180000 | 0.316 |
+| Detectron_RoIAlign | RoIAlign | 8 | 180000 | 0.346 |
+| Fluid RoIAlign no padding | RoIAlign | 8 | 180000 | 0.344 |
+
+* Fluid RoIPool minibatch padding: Use RoIPool. Images in one batch padding to the same size. This method is same as detectron.
+* Fluid RoIPool no padding: Images without padding.
+* Fluid RoIAlign no padding: Images without padding.
## Inference and Visualization
diff --git a/fluid/faster_rcnn/README_cn.md b/fluid/faster_rcnn/README_cn.md
index b17386a9e07139d0ff1bec58fe560609f7fac7bc..6cace2522826f9c276482142672e171fe7024128 100644
--- a/fluid/faster_rcnn/README_cn.md
+++ b/fluid/faster_rcnn/README_cn.md
@@ -7,7 +7,6 @@
- [简介](#简介)
- [数据准备](#数据准备)
- [模型训练](#模型训练)
-- [参数微调](#参数微调)
- [模型评估](#模型评估)
- [模型推断及可视化](#模型推断及可视化)
- [附录](#附录)
@@ -26,7 +25,7 @@ Faster RCNN 目标检测模型
1. 基础卷积层。作为一种卷积神经网络目标检测方法,Faster RCNN首先使用一组基础的卷积网络提取图像的特征图。特征图被后续RPN层和全连接层共享。本示例采用[ResNet-50](https://arxiv.org/abs/1512.03385)作为基础卷积层。
2. 区域生成网络(RPN)。RPN网络用于生成候选区域(proposals)。该层通过一组固定的尺寸和比例得到一组锚点(anchors), 通过softmax判断锚点属于前景或者背景,再利用区域回归修正锚点从而获得精确的候选区域。
-3. RoI池化。该层收集输入的特征图和候选区域,将候选区域映射到特征图中并池化为统一大小的区域特征图,送入全连接层判定目标类别。
+3. RoI Align。该层收集输入的特征图和候选区域,将候选区域映射到特征图中并池化为统一大小的区域特征图,送入全连接层判定目标类别, 该层可选用RoIPool和RoIAlign两种方式,在config.py中设置roi\_func。
4. 检测层。利用区域特征图计算候选区域的类别,同时再次通过区域回归获得检测框最终的精确位置。
## 数据准备
@@ -41,11 +40,9 @@ Faster RCNN 目标检测模型
数据准备完毕后,可以通过如下的方式启动训练:
python train.py \
- --max_size=1333 \
- --scales=[800] \
- --batch_size=8 \
--model_save_dir=output/ \
--pretrained_model=${path_to_pretrain_model}
+ --data_dir=${path_to_data}
- 通过设置export CUDA\_VISIBLE\_DEVICES=0,1,2,3,4,5,6,7指定8卡GPU训练。
- 可选参数见:
@@ -74,11 +71,11 @@ Faster RCNN 目标检测模型
# not to install the COCO API into global site-packages
python2 setup.py install --user
-**数据读取器说明:** 数据读取器定义在reader.py中。所有图像将短边等比例缩放至`scales`,若长边大于`max_size`, 则再次将长边等比例缩放至`max_iter`。在训练阶段,对图像采用水平翻转。支持将同一个batch内的图像padding为相同尺寸。
+**数据读取器说明:** 数据读取器定义在reader.py中。所有图像将短边等比例缩放至`scales`,若长边大于`max_size`, 则再次将长边等比例缩放至`max_size`。在训练阶段,对图像采用水平翻转。支持将同一个batch内的图像padding为相同尺寸。
**模型设置:**
-* 使用RoIPooling。
+* 分别使用RoIAlign和RoIPool两种方法。
* 训练过程pre\_nms=12000, post\_nms=2000,测试过程pre\_nms=6000, post\_nms=1000。nms阈值为0.7。
* RPN网络得到labels的过程中,fg\_fraction=0.25,fg\_thresh=0.5,bg\_thresh_hi=0.5,bg\_thresh\_lo=0.0
* RPN选择anchor时,rpn\_fg\_fraction=0.5,rpn\_positive\_overlap=0.7,rpn\_negative\_overlap=0.3
@@ -89,9 +86,10 @@ Faster RCNN 目标检测模型
Faster RCNN 训练loss
-* Fluid all padding: 每张图像填充为1333\*1333大小。
-* Fluid minibatch padding: 同一个batch内的图像填充为相同尺寸。该方法与detectron处理相同。
-* Fluid no padding: 不对图像做填充处理。
+
+* Fluid RoIPool minibatch padding: 使用RoIPool,同一个batch内的图像填充为相同尺寸。该方法与detectron处理相同。
+* Fluid RoIPool no padding: 使用RoIPool,不对图像做填充处理。
+* Fluid RoIAlign no padding: 使用RoIAlign,不对图像做填充处理。
**训练策略:**
@@ -110,26 +108,31 @@ Faster RCNN 训练loss
python eval_coco_map.py \
--dataset=coco2017 \
--pretrained_mode=${path_to_pretrain_model} \
- --batch_size=1 \
--nms_threshold=0.5 \
--score_threshold=0.05
+- 通过设置export CUDA\_VISIBLE\_DEVICES=0指定单卡GPU评估。
+
下图为模型评估结果:
Faster RCNN mAP
-| 模型 | 批量大小 | 迭代次数 | mAP |
-| :------------------------------ | :------------: | :------------------: |------: |
-| Detectron | 8 | 180000 | 0.315 |
-| Fluid minibatch padding | 8 | 180000 | 0.314 |
-| Fluid all padding | 8 | 180000 | 0.308 |
-| Fluid no padding |8 | 180000 | 0.316 |
+| 模型 | RoI处理方式 | 批量大小 | 迭代次数 | mAP |
+| :--------------- | :--------: | :------------: | :------------------: |------: |
+| Detectron RoIPool | RoIPool | 8 | 180000 | 0.315 |
+| Fluid RoIPool minibatch padding | RoIPool | 8 | 180000 | 0.314 |
+| Fluid RoIPool no padding | RoIPool | 8 | 180000 | 0.316 |
+| Detectron RoIAlign | RoIAlign | 8 | 180000 | 0.346 |
+| Fluid RoIAlign no padding | RoIAlign | 8 | 180000 | 0.344 |
+
+
+
-* Fluid all padding: 每张图像填充为1333\*1333大小。
-* Fluid minibatch padding: 同一个batch内的图像填充为相同尺寸。该方法与detectron处理相同。
-* Fluid no padding: 不对图像做填充处理。
+* Fluid RoIPool minibatch padding: 使用RoIPool,同一个batch内的图像填充为相同尺寸。该方法与detectron处理相同。
+* Fluid RoIPool no padding: 使用RoIPool,不对图像做填充处理。
+* Fluid RoIAlign no padding: 使用RoIAlign,不对图像做填充处理。
## 模型推断及可视化
diff --git a/fluid/faster_rcnn/image/mAP.jpg b/fluid/faster_rcnn/image/mAP.jpg
index 9c781a7caef808b716ace077b2f202267e790f76..bdac680d17233ae9a8a6390d670a05c7ab96e15d 100644
Binary files a/fluid/faster_rcnn/image/mAP.jpg and b/fluid/faster_rcnn/image/mAP.jpg differ
diff --git a/fluid/faster_rcnn/image/train_loss.jpg b/fluid/faster_rcnn/image/train_loss.jpg
index 3cc0ff84b30599597bf6a66bf0cbfd7789c485f0..5d98867525d322968bf58fe73847d3016b63fbdf 100644
Binary files a/fluid/faster_rcnn/image/train_loss.jpg and b/fluid/faster_rcnn/image/train_loss.jpg differ
diff --git a/fluid/faster_rcnn/profile.py b/fluid/faster_rcnn/profile.py
index ad5e796fc48ee209190ba21febc4d4b4c2206440..73634bd6773ecb1606a43b297f0966e2d55506b3 100644
--- a/fluid/faster_rcnn/profile.py
+++ b/fluid/faster_rcnn/profile.py
@@ -52,7 +52,7 @@ def train():
boundaries = cfg.lr_steps
gamma = cfg.lr_gamma
- step_num = len(lr_steps)
+ step_num = len(cfg.lr_steps)
values = [learning_rate * (gamma**i) for i in range(step_num + 1)]
optimizer = fluid.optimizer.Momentum(
diff --git a/fluid/faster_rcnn/reader.py b/fluid/faster_rcnn/reader.py
index c646d6757f334d18880377e7ab14ebc58ed0963f..50b3d88b3995442c49833e6f69c7d6f04ea84064 100644
--- a/fluid/faster_rcnn/reader.py
+++ b/fluid/faster_rcnn/reader.py
@@ -102,6 +102,7 @@ def coco(mode,
roidb_perm.rotate(-1)
if roidb_cur >= len(roidbs):
roidb_perm = deque(np.random.permutation(roidbs))
+ roidb_cur = 0
im, gt_boxes, gt_classes, is_crowd, im_info, im_id = roidb_reader(
roidb, mode)
if gt_boxes.shape[0] == 0: