Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
2b89f590
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2b89f590
编写于
1月 10, 2019
作者:
T
tink2123
提交者:
dengkaipeng
1月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add attr use_label_smooth test=develop
上级
8218e301
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
51 addition
and
14 deletion
+51
-14
paddle/fluid/API.spec
paddle/fluid/API.spec
+1
-1
paddle/fluid/operators/yolov3_loss_op.cc
paddle/fluid/operators/yolov3_loss_op.cc
+3
-0
paddle/fluid/operators/yolov3_loss_op.h
paddle/fluid/operators/yolov3_loss_op.h
+33
-13
python/paddle/fluid/layers/detection.py
python/paddle/fluid/layers/detection.py
+6
-0
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
+8
-0
未找到文件。
paddle/fluid/API.spec
浏览文件 @
2b89f590
...
...
@@ -324,7 +324,7 @@ paddle.fluid.layers.generate_mask_labels ArgSpec(args=['im_info', 'gt_classes',
paddle.fluid.layers.iou_similarity ArgSpec(args=['x', 'y', 'name'], varargs=None, keywords=None, defaults=(None,))
paddle.fluid.layers.box_coder ArgSpec(args=['prior_box', 'prior_box_var', 'target_box', 'code_type', 'box_normalized', 'name'], varargs=None, keywords=None, defaults=('encode_center_size', True, None))
paddle.fluid.layers.polygon_box_transform ArgSpec(args=['input', 'name'], varargs=None, keywords=None, defaults=(None,))
paddle.fluid.layers.yolov3_loss ArgSpec(args=['x', 'gtbox', 'gtlabel', 'gtscore', 'anchors', 'anchor_mask', 'class_num', 'ignore_thresh', 'downsample', 'name'], varargs=None, keywords=None, defaults=(None,))
paddle.fluid.layers.yolov3_loss ArgSpec(args=['x', 'gtbox', 'gtlabel', 'gtscore', 'anchors', 'anchor_mask', 'class_num', 'ignore_thresh', 'downsample', '
label_smooth', '
name'], varargs=None, keywords=None, defaults=(None,))
paddle.fluid.layers.multiclass_nms ArgSpec(args=['bboxes', 'scores', 'score_threshold', 'nms_top_k', 'keep_top_k', 'nms_threshold', 'normalized', 'nms_eta', 'background_label', 'name'], varargs=None, keywords=None, defaults=(0.3, True, 1.0, 0, None))
paddle.fluid.layers.accuracy ArgSpec(args=['input', 'label', 'k', 'correct', 'total'], varargs=None, keywords=None, defaults=(1, None, None))
paddle.fluid.layers.auc ArgSpec(args=['input', 'label', 'curve', 'num_thresholds', 'topk', 'slide_steps'], varargs=None, keywords=None, defaults=('ROC', 4095, 1, 1))
...
...
paddle/fluid/operators/yolov3_loss_op.cc
浏览文件 @
2b89f590
...
...
@@ -46,6 +46,7 @@ class Yolov3LossOp : public framework::OperatorWithKernel {
auto
anchor_mask
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"anchor_mask"
);
int
mask_num
=
anchor_mask
.
size
();
auto
class_num
=
ctx
->
Attrs
().
Get
<
int
>
(
"class_num"
);
PADDLE_ENFORCE_EQ
(
dim_x
.
size
(),
4
,
"Input(X) should be a 4-D tensor."
);
PADDLE_ENFORCE_EQ
(
dim_x
[
2
],
dim_x
[
3
],
"Input(X) dim[3] and dim[4] should be euqal."
);
...
...
@@ -156,6 +157,8 @@ class Yolov3LossOpMaker : public framework::OpProtoAndCheckerMaker {
AddAttr
<
float
>
(
"ignore_thresh"
,
"The ignore threshold to ignore confidence loss."
)
.
SetDefault
(
0.7
);
AddAttr
<
bool
>
(
"use_label_smooth"
,
"bool,default True"
,
"use label smooth"
)
.
SetDefault
(
true
);
AddComment
(
R"DOC(
This operator generate yolov3 loss by given predict result and ground
truth boxes.
...
...
paddle/fluid/operators/yolov3_loss_op.h
浏览文件 @
2b89f590
...
...
@@ -157,11 +157,19 @@ static void CalcBoxLocationLossGrad(T* input_grad, const T loss, const T* input,
template
<
typename
T
>
static
inline
void
CalcLabelLoss
(
T
*
loss
,
const
T
*
input
,
const
int
index
,
const
int
label
,
const
T
score
,
const
int
class_num
,
const
int
stride
)
{
for
(
int
i
=
0
;
i
<
class_num
;
i
++
)
{
T
pred
=
input
[
index
+
i
*
stride
]
<
-
0.5
?
input
[
index
+
i
*
stride
]
:
1.0
/
class_num
;
loss
[
0
]
+=
SCE
<
T
>
(
pred
,
(
i
==
label
)
?
score
:
0.0
);
const
int
class_num
,
const
int
stride
,
const
bool
use_label_smooth
)
{
if
(
use_label_smooth
)
{
for
(
int
i
=
0
;
i
<
class_num
;
i
++
)
{
T
pred
=
input
[
index
+
i
*
stride
]
<
-
0.5
?
input
[
index
+
i
*
stride
]
:
1.0
/
class_num
;
loss
[
0
]
+=
SCE
<
T
>
(
pred
,
(
i
==
label
)
?
score
:
0.0
);
}
}
else
{
for
(
int
i
=
0
;
i
<
class_num
;
i
++
)
{
T
pred
=
input
[
index
+
i
*
stride
];
loss
[
0
]
+=
SCE
<
T
>
(
pred
,
(
i
==
label
)
?
score
:
0.0
);
}
}
}
...
...
@@ -169,12 +177,21 @@ template <typename T>
static
inline
void
CalcLabelLossGrad
(
T
*
input_grad
,
const
T
loss
,
const
T
*
input
,
const
int
index
,
const
int
label
,
const
T
score
,
const
int
class_num
,
const
int
stride
)
{
for
(
int
i
=
0
;
i
<
class_num
;
i
++
)
{
T
pred
=
input
[
index
+
i
*
stride
]
<
-
0.5
?
input
[
index
+
i
*
stride
]
:
1.0
/
class_num
;
input_grad
[
index
+
i
*
stride
]
=
SCEGrad
<
T
>
(
pred
,
(
i
==
label
)
?
score
:
0.0
)
*
loss
;
const
int
class_num
,
const
int
stride
,
const
bool
use_label_smooth
)
{
if
(
use_label_smooth
)
{
for
(
int
i
=
0
;
i
<
class_num
;
i
++
)
{
T
pred
=
input
[
index
+
i
*
stride
]
<
-
0.5
?
input
[
index
+
i
*
stride
]
:
1.0
/
class_num
;
input_grad
[
index
+
i
*
stride
]
=
SCEGrad
<
T
>
(
pred
,
(
i
==
label
)
?
score
:
0.0
)
*
loss
;
}
}
else
{
for
(
int
i
=
0
;
i
<
class_num
;
i
++
)
{
T
pred
=
input
[
index
+
i
*
stride
];
input_grad
[
index
+
i
*
stride
]
=
SCEGrad
<
T
>
(
pred
,
(
i
==
label
)
?
score
:
0.0
)
*
loss
;
}
}
}
...
...
@@ -255,6 +272,7 @@ class Yolov3LossKernel : public framework::OpKernel<T> {
int
class_num
=
ctx
.
Attr
<
int
>
(
"class_num"
);
float
ignore_thresh
=
ctx
.
Attr
<
float
>
(
"ignore_thresh"
);
int
downsample
=
ctx
.
Attr
<
int
>
(
"downsample"
);
bool
use_label_smooth
=
ctx
.
Attr
<
bool
>
(
"use_label_smooth"
);
const
int
n
=
input
->
dims
()[
0
];
const
int
h
=
input
->
dims
()[
2
];
...
...
@@ -364,7 +382,7 @@ class Yolov3LossKernel : public framework::OpKernel<T> {
int
label_idx
=
GetEntryIndex
(
i
,
mask_idx
,
gj
*
w
+
gi
,
mask_num
,
an_stride
,
stride
,
5
);
CalcLabelLoss
<
T
>
(
loss_data
+
i
,
input_data
,
label_idx
,
label
,
score
,
class_num
,
stride
);
class_num
,
stride
,
use_label_smooth
);
}
}
}
...
...
@@ -390,6 +408,7 @@ class Yolov3LossGradKernel : public framework::OpKernel<T> {
auto
anchor_mask
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"anchor_mask"
);
int
class_num
=
ctx
.
Attr
<
int
>
(
"class_num"
);
int
downsample
=
ctx
.
Attr
<
int
>
(
"downsample"
);
bool
use_label_smooth
=
ctx
.
Attr
<
bool
>
(
"use_label_smooth"
);
const
int
n
=
input_grad
->
dims
()[
0
];
const
int
c
=
input_grad
->
dims
()[
1
];
...
...
@@ -432,7 +451,8 @@ class Yolov3LossGradKernel : public framework::OpKernel<T> {
int
label_idx
=
GetEntryIndex
(
i
,
mask_idx
,
gj
*
w
+
gi
,
mask_num
,
an_stride
,
stride
,
5
);
CalcLabelLossGrad
<
T
>
(
input_grad_data
,
loss_grad_data
[
i
],
input_data
,
label_idx
,
label
,
score
,
class_num
,
stride
);
label_idx
,
label
,
score
,
class_num
,
stride
,
use_label_smooth
);
}
}
}
...
...
python/paddle/fluid/layers/detection.py
浏览文件 @
2b89f590
...
...
@@ -418,6 +418,7 @@ def yolov3_loss(x,
class_num
,
ignore_thresh
,
downsample
,
use_label_smooth
=
True
,
name
=
None
):
"""
${comment}
...
...
@@ -438,6 +439,7 @@ def yolov3_loss(x,
class_num (int): ${class_num_comment}
ignore_thresh (float): ${ignore_thresh_comment}
downsample (int): ${downsample_comment}
use_label_smooth(bool): ${use_label_smooth_comment}
name (string): the name of yolov3 loss
Returns:
...
...
@@ -451,6 +453,7 @@ def yolov3_loss(x,
TypeError: Attr anchors of yolov3_loss must be list or tuple
TypeError: Attr class_num of yolov3_loss must be an integer
TypeError: Attr ignore_thresh of yolov3_loss must be a float number
TypeError: Attr use_label_smooth of yolov3_loss must be a bool value
Examples:
.. code-block:: python
...
...
@@ -479,6 +482,8 @@ def yolov3_loss(x,
raise
TypeError
(
"Attr anchor_mask of yolov3_loss must be list or tuple"
)
if
not
isinstance
(
class_num
,
int
):
raise
TypeError
(
"Attr class_num of yolov3_loss must be an integer"
)
if
not
isinstance
(
class_num
,
int
):
raise
TypeError
(
"Attr ues_label_smooth of yolov3 must be a bool value"
)
if
not
isinstance
(
ignore_thresh
,
float
):
raise
TypeError
(
"Attr ignore_thresh of yolov3_loss must be a float number"
)
...
...
@@ -498,6 +503,7 @@ def yolov3_loss(x,
"class_num"
:
class_num
,
"ignore_thresh"
:
ignore_thresh
,
"downsample"
:
downsample
,
"use_label_smooth"
:
use_label_smooth
}
helper
.
append_op
(
...
...
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
浏览文件 @
2b89f590
...
...
@@ -76,6 +76,7 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs):
class_num
=
attrs
[
"class_num"
]
ignore_thresh
=
attrs
[
'ignore_thresh'
]
downsample
=
attrs
[
'downsample'
]
#use_label_smooth = attrs['use_label_smooth']
input_size
=
downsample
*
h
x
=
x
.
reshape
((
n
,
mask_num
,
5
+
class_num
,
h
,
w
)).
transpose
((
0
,
1
,
3
,
4
,
2
))
loss
=
np
.
zeros
((
n
)).
astype
(
'float32'
)
...
...
@@ -176,6 +177,7 @@ class TestYolov3LossOp(OpTest):
"class_num"
:
self
.
class_num
,
"ignore_thresh"
:
self
.
ignore_thresh
,
"downsample"
:
self
.
downsample
,
"use_label_smooth"
:
self
.
use_label_smooth
,
}
self
.
inputs
=
{
...
...
@@ -215,6 +217,12 @@ class TestYolov3LossOp(OpTest):
self
.
downsample
=
32
self
.
x_shape
=
(
3
,
len
(
self
.
anchor_mask
)
*
(
5
+
self
.
class_num
),
5
,
5
)
self
.
gtbox_shape
=
(
3
,
10
,
4
)
self
.
use_label_smooth
=
True
class
TestYolov3LossWithLabelSmooth
(
TestYolov3LossOp
):
def
set_label_smooth
(
self
):
self
.
use_label_smooth
=
True
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录