未验证 提交 d815b77b 编写于 作者: F FlyingQianMM 提交者: GitHub

change fluid.layers.data to fluid.data in api_cn for retinanet_target_assign,...

change fluid.layers.data to fluid.data in api_cn for retinanet_target_assign, sigmoid_focal_loss, retinanet_detection_output. (#1473)

* test=document_preview
change  to  in api_cn for retinanet_target_assign, sigmoid_focal_loss, retinanet_detection_output.

* test=document_preview
remove Notice: this OP supports CPU mode only in api_cn for retinanet_target_assign and retinanet_detection_output
上级 945c3b99
......@@ -5,8 +5,6 @@ retinanet_detection_output
.. py:function:: paddle.fluid.layers.retinanet_detection_output(bboxes, scores, anchors, im_info, score_threshold=0.05, nms_top_k=1000, keep_top_k=100, nms_threshold=0.3, nms_eta=1.0)
**注意:该OP目前仅支持CPU** 。
在 `RetinaNet <https://arxiv.org/abs/1708.02002>`_ 中,有多个 `FPN <https://arxiv.org/abs/1612.03144>`_ 层会输出用于分类的预测值和位置回归的预测值,该OP通过执行以下步骤将这些预测值转换成最终的检测结果:
1. 在每个FPN层上,先剔除分类预测值小于score_threshold的anchor,然后按分类预测值从大到小排序,选出排名前nms_top_k的anchor,并将这些anchor与其位置回归的预测值做解码操作得到检测框。
......@@ -36,19 +34,20 @@ retinanet_detection_output
import paddle.fluid as fluid
bboxes_low = fluid.layers.data(name='bboxes_low', shape=[1, 44, 4],
append_batch_size=False, dtype='float32')
bboxes_high = fluid.layers.data(name='bboxes_high', shape=[1, 11, 4],
scores_low = fluid.layers.data(name='scores_low', shape=[1, 44, 10],
append_batch_size=False, dtype='float32')
scores_high = fluid.layers.data(name='scores_high', shape=[1, 11, 10],
append_batch_size=False, dtype='float32')
anchors_low = fluid.layers.data(name='anchors_low', shape=[44, 4],
append_batch_size=False, dtype='float32')
anchors_high = fluid.layers.data(name='anchors_high', shape=[11, 4],
append_batch_size=False, dtype='float32')
im_info = fluid.layers.data(name="im_info", shape=[1, 3],
append_batch_size=False, dtype='float32')
bboxes_low = fluid.data(name='bboxes_low', shape=[1, 44, 4],
dtype='float32')
bboxes_high = fluid.data(name='bboxes_high', shape=[1, 11, 4],
dtype='float32')
scores_low = fluid.data(name='scores_low', shape=[1, 44, 10],
dtype='float32')
scores_high = fluid.data(name='scores_high', shape=[1, 11, 10],
dtype='float32')
anchors_low = fluid.data(name='anchors_low', shape=[44, 4],
dtype='float32')
anchors_high = fluid.data(name='anchors_high', shape=[11, 4],
dtype='float32')
im_info = fluid.data(name="im_info", shape=[1, 3],
dtype='float32')
nmsed_outs = fluid.layers.retinanet_detection_output(
bboxes=[bboxes_low, bboxes_high],
scores=[scores_low, scores_high],
......
......@@ -5,8 +5,6 @@ retinanet_target_assign
.. py:function:: paddle.fluid.layers.retinanet_target_assign(bbox_pred, cls_logits, anchor_box, anchor_var, gt_boxes, gt_labels, is_crowd, im_info, num_classes=1, positive_overlap=0.5, negative_overlap=0.4)
**注意:该OP目前仅支持CPU** 。
该OP是从输入anchor中找出训练检测模型 `RetinaNet <https://arxiv.org/abs/1708.02002>`_ 所需的正负样本,并为每个正负样本分配用于分类的目标值和位置回归的目标值,同时从全部anchor的类别预测值cls_logits、位置预测值bbox_pred中取出属于各正负样本的部分。
正负样本的查找准则如下:
......@@ -24,8 +22,8 @@ retinanet_target_assign
- **bbox_pred** (Variable) – 维度为 :math:`[N, M, 4]` 的3-D Tensor,表示全部anchor的位置回归预测值。其中,第一维N表示批量训练时批量内的图片数量,第二维M表示每张图片的全部anchor的数量,第三维4表示每个anchor有四个坐标值。数据类型为float32或float64。
- **cls_logits** (Variable) – 维度为 :math:`[N, M, C]` 的3-D Tensor,表示全部anchor的分类预测值。 其中,第一维N表示批量训练时批量内的图片数量,第二维M表示每张图片的全部anchor的数量,第三维C表示每个anchor需预测的类别数量( **注意:不包括背景** )。数据类型为float32或float64。
- **anchor_box** (Variable) – 维度为 :math:`[M, 4]` 的2-D Tensor,表示全部anchor的坐标值。其中,第一维M表示每张图片的全部anchor的数量,第二维4表示每个anchor有四个坐标值 :math:`[xmin, ymin, xmax, ymax]` ,:math:`[xmin, ymin]` 是anchor的左上顶部坐标,:math:`[xmax, ymax]` 是anchor的右下坐标。数据类型为float32或float64。anchor_box的生成请参考OP `anchor_generate <https://www.paddlepaddle.org.cn/documentation/docs/en/1.5/api/layers/detection.html#anchor-generator>`_
- **anchor_var** (Variable) – 维度为 :math:`[M, 4]` 的2-D Tensor,表示在后续计算损失函数时anchor坐标值的缩放比例。其中,第一维M表示每张图片的全部anchor的数量,第二维4表示每个anchor有四个坐标缩放因子。数据类型为float32或float64。anchor_var的生成请参考OP `anchor_generate <https://www.paddlepaddle.org.cn/documentation/docs/en/1.5/api/layers/detection.html#anchor-generator>`_
- **anchor_box** (Variable) – 维度为 :math:`[M, 4]` 的2-D Tensor,表示全部anchor的坐标值。其中,第一维M表示每张图片的全部anchor的数量,第二维4表示每个anchor有四个坐标值 :math:`[xmin, ymin, xmax, ymax]` ,:math:`[xmin, ymin]` 是anchor的左上顶部坐标,:math:`[xmax, ymax]` 是anchor的右下坐标。数据类型为float32或float64。anchor_box的生成请参考OP :ref:`cn_api_fluid_layers_anchor_generator`
- **anchor_var** (Variable) – 维度为 :math:`[M, 4]` 的2-D Tensor,表示在后续计算损失函数时anchor坐标值的缩放比例。其中,第一维M表示每张图片的全部anchor的数量,第二维4表示每个anchor有四个坐标缩放因子。数据类型为float32或float64。anchor_var的生成请参考OP :ref:`cn_api_fluid_layers_anchor_generator`
- **gt_boxes** (Variable) – 维度为 :math:`[G, 4]` 且LoD level必须为1的2-D LoDTensor,表示批量训练时批量内的真值框位置。其中,第一维G表示批量内真值框的总数,第二维表示每个真值框有四个坐标值。数据类型为float32或float64。
- **gt_labels** (variable) – 维度为 :math:`[G, 1]` 且LoD level必须为1的2-D LoDTensor,表示批量训练时批量内的真值框类别,数值范围为 :math:`[1, C]` 。其中,第一维G表示批量内真值框的总数,第二维表示每个真值框只有1个类别。数据类型为int32。
- **is_crowd** (Variable) – 维度为 :math:`[G]` 且LoD level必须为1的1-D LoDTensor,表示各真值框是否位于重叠区域,值为1表示重叠,则不参与训练。第一维G表示批量内真值框的总数。数据类型为int32。
......@@ -40,7 +38,7 @@ retinanet_target_assign
- **predict_location** (Variable) — 维度为 :math:`[F, 4]` 的2-D Tensor,表示正样本的位置回归预测值。其中,第一维F为批量内正样本的数量,第二维4表示每个样本有4个坐标值。数据类型为float32或float64。
- **target_label** (Variable) — 维度为 :math:`[F + B, 1]` 的2-D Tensor,表示正负样本的分类目标值。其中,第一维F为正样本的数量,B为负样本的数量,第二维1表示每个样本的真值类别只有1类。数据类型为int32。
- **target_bbox** (Variable) — 维度为 :math:`[F, 4]` 的2-D Tensor,表示正样本的位置回归目标值。其中,第一维F为正样本的数量,第二维4表示每个样本有4个坐标值。数据类型为float32或float64。
- **bbox_inside_weight** (Variable) — 维度为 :math:`[F, 4]` 的2-D LoDTensor,表示位置回归预测值中是否属于假正样本,若某个正样本为假,则bbox_inside_weight中对应维度的值为0,否则为1。第一维F为正样本的数量,第二维4表示每个样本有4个坐标值。数据类型为float32或float64。
- **bbox_inside_weight** (Variable) — 维度为 :math:`[F, 4]` 的2-D Tensor,表示位置回归预测值中是否属于假正样本,若某个正样本为假,则bbox_inside_weight中对应维度的值为0,否则为1。第一维F为正样本的数量,第二维4表示每个样本有4个坐标值。数据类型为float32或float64。
- **fg_num** (Variable) — 维度为 :math:`[N, 1]` 的2-D Tensor,表示正样本的数量。其中,第一维N表示批量内的图片数量。 **注意:由于正样本数量会用作后续损失函数的分母,为避免出现除以0的情况,该OP已将每张图片的正样本数量做加1操作** 。数据类型为int32。
......@@ -54,22 +52,22 @@ retinanet_target_assign
import paddle.fluid as fluid
import numpy as np
bbox_pred = fluid.layers.data(name='bbox_pred', shape=[1, 100, 4],
append_batch_size=False, dtype='float32')
cls_logits = fluid.layers.data(name='cls_logits', shape=[1, 100, 10],
append_batch_size=False, dtype='float32')
anchor_box = fluid.layers.data(name='anchor_box', shape=[100, 4],
append_batch_size=False, dtype='float32')
anchor_var = fluid.layers.data(name='anchor_var', shape=[100, 4],
append_batch_size=False, dtype='float32')
gt_boxes = fluid.layers.data(name='gt_boxes', shape=[10, 4],
append_batch_size=False, dtype='float32')
gt_labels = fluid.layers.data(name='gt_labels', shape=[10, 1],
append_batch_size=False, dtype='float32')
is_crowd = fluid.layers.data(name='is_crowd', shape=[1],
append_batch_size=False, dtype='float32')
im_info = fluid.layers.data(name='im_info', shape=[1, 3],
append_batch_size=False, dtype='float32')
bbox_pred = fluid.data(name='bbox_pred', shape=[1, 100, 4],
dtype='float32')
cls_logits = fluid.data(name='cls_logits', shape=[1, 100, 10],
dtype='float32')
anchor_box = fluid.data(name='anchor_box', shape=[100, 4],
dtype='float32')
anchor_var = fluid.data(name='anchor_var', shape=[100, 4],
dtype='float32')
gt_boxes = fluid.data(name='gt_boxes', shape=[10, 4],
dtype='float32')
gt_labels = fluid.data(name='gt_labels', shape=[10, 1],
dtype='float32')
is_crowd = fluid.data(name='is_crowd', shape=[1],
dtype='float32')
im_info = fluid.data(name='im_info', shape=[1, 3],
dtype='float32')
loc_pred, score_pred, loc_target, score_target, bbox_inside_weight, fg_num =
fluid.layers.retinanet_target_assign(bbox_pred, cls_logits, anchor_box,
anchor_var, gt_boxes, gt_labels, is_crowd, im_info, 10)
......@@ -25,14 +25,14 @@ Focal Loss的计算过程如下:
参数:
- **x** (Variable) – 维度为 :math:`[N, D]` 的2-D Tensor,表示全部样本的分类预测值。其中,第一维N是批量内参与训练的样本数量,例如在目标检测中,样本为框级别,N为批量内所有图像的正负样本的数量总和;在图像分类中,样本为图像级别,N为批量内的图像数量总和。第二维D是类别数量( **不包括背景类** )。数据类型为float32或float64。
- **label** (Variable) – 维度为 :math:`[N, 1]` 的2-D Tensor,表示全部样本的分类目标值。其中,第一维N是批量内参与训练的样本数量,第二维1表示每个样本只有一个类别目标值。正样本的目标类别值的取值范围是 :math:`[1, D]` , 负样本的目标类别值是0。数据类型为int32。
- **x** (Variable) – 维度为 :math:`[N, C]` 的2-D Tensor,表示全部样本的分类预测值。其中,第一维N是批量内参与训练的样本数量,例如在目标检测中,样本为框级别,N为批量内所有图像的正负样本的数量总和;在图像分类中,样本为图像级别,N为批量内的图像数量总和。第二维:math:`C` 是类别数量( **不包括背景类** )。数据类型为float32或float64。
- **label** (Variable) – 维度为 :math:`[N, 1]` 的2-D Tensor,表示全部样本的分类目标值。其中,第一维N是批量内参与训练的样本数量,第二维1表示每个样本只有一个类别目标值。正样本的目标类别值的取值范围是 :math:`[1, C]` , 负样本的目标类别值是0。数据类型为int32。
- **fg_num** (Variable) – 维度为 :math:`[1]` 的1-D Tensor,表示批量内正样本的数量,需在进入此OP前获取正样本的数量。数据类型为int32。
- **gamma** (float) – 用于平衡易分样本和难分样本的超参数, 默认值设置为2.0。
- **alpha** (float) – 用于平衡正样本和负样本的超参数,默认值设置为0.25。
返回: 输入x中每个元素的Focal loss,即维度为 :math:`[N, D]` 的2-D Tensor。
返回: 输入x中每个元素的Focal loss,即维度为 :math:`[N, C]` 的2-D Tensor。
返回类型: 变量(Variable),数据类型为float32或float64。
......@@ -43,12 +43,9 @@ Focal Loss的计算过程如下:
import paddle.fluid as fluid
input = fluid.layers.data(
name='data', shape=[10,80], append_batch_size=False, dtype='float32')
label = fluid.layers.data(
name='label', shape=[10,1], append_batch_size=False, dtype='int32')
fg_num = fluid.layers.data(
name='fg_num', shape=[1], append_batch_size=False, dtype='int32')
input = fluid.data(name='data', shape=[10,80], dtype='float32')
label = fluid.data(name='label', shape=[10,1], dtype='int32')
fg_num = fluid.data(name='fg_num', shape=[1], dtype='int32')
loss = fluid.layers.sigmoid_focal_loss(x=input,
label=label,
fg_num=fg_num,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册