Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
042fecef
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
042fecef
编写于
1月 21, 2019
作者:
D
dengkaipeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use L2Loss. test=develop
上级
af124dcd
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
27 addition
and
16 deletion
+27
-16
paddle/fluid/operators/yolov3_loss_op.h
paddle/fluid/operators/yolov3_loss_op.h
+14
-4
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
+13
-12
未找到文件。
paddle/fluid/operators/yolov3_loss_op.h
浏览文件 @
042fecef
...
@@ -41,6 +41,11 @@ static T L1Loss(T x, T y) {
...
@@ -41,6 +41,11 @@ static T L1Loss(T x, T y) {
return
std
::
abs
(
y
-
x
);
return
std
::
abs
(
y
-
x
);
}
}
template
<
typename
T
>
static
T
L2Loss
(
T
x
,
T
y
)
{
return
0.5
*
(
y
-
x
)
*
(
y
-
x
);
}
template
<
typename
T
>
template
<
typename
T
>
static
T
SCEGrad
(
T
x
,
T
label
)
{
static
T
SCEGrad
(
T
x
,
T
label
)
{
return
1.0
/
(
1.0
+
std
::
exp
(
-
x
))
-
label
;
return
1.0
/
(
1.0
+
std
::
exp
(
-
x
))
-
label
;
...
@@ -51,6 +56,11 @@ static T L1LossGrad(T x, T y) {
...
@@ -51,6 +56,11 @@ static T L1LossGrad(T x, T y) {
return
x
>
y
?
1.0
:
-
1.0
;
return
x
>
y
?
1.0
:
-
1.0
;
}
}
template
<
typename
T
>
static
T
L2LossGrad
(
T
x
,
T
y
)
{
return
x
-
y
;
}
static
int
GetMaskIndex
(
std
::
vector
<
int
>
mask
,
int
val
)
{
static
int
GetMaskIndex
(
std
::
vector
<
int
>
mask
,
int
val
)
{
for
(
size_t
i
=
0
;
i
<
mask
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
mask
.
size
();
i
++
)
{
if
(
mask
[
i
]
==
val
)
{
if
(
mask
[
i
]
==
val
)
{
...
@@ -130,8 +140,8 @@ static void CalcBoxLocationLoss(T* loss, const T* input, Box<T> gt,
...
@@ -130,8 +140,8 @@ static void CalcBoxLocationLoss(T* loss, const T* input, Box<T> gt,
T
scale
=
(
2.0
-
gt
.
w
*
gt
.
h
)
*
score
;
T
scale
=
(
2.0
-
gt
.
w
*
gt
.
h
)
*
score
;
loss
[
0
]
+=
SCE
<
T
>
(
input
[
box_idx
],
tx
)
*
scale
;
loss
[
0
]
+=
SCE
<
T
>
(
input
[
box_idx
],
tx
)
*
scale
;
loss
[
0
]
+=
SCE
<
T
>
(
input
[
box_idx
+
stride
],
ty
)
*
scale
;
loss
[
0
]
+=
SCE
<
T
>
(
input
[
box_idx
+
stride
],
ty
)
*
scale
;
loss
[
0
]
+=
L
1
Loss
<
T
>
(
input
[
box_idx
+
2
*
stride
],
tw
)
*
scale
;
loss
[
0
]
+=
L
2
Loss
<
T
>
(
input
[
box_idx
+
2
*
stride
],
tw
)
*
scale
;
loss
[
0
]
+=
L
1
Loss
<
T
>
(
input
[
box_idx
+
3
*
stride
],
th
)
*
scale
;
loss
[
0
]
+=
L
2
Loss
<
T
>
(
input
[
box_idx
+
3
*
stride
],
th
)
*
scale
;
}
}
template
<
typename
T
>
template
<
typename
T
>
...
@@ -150,9 +160,9 @@ static void CalcBoxLocationLossGrad(T* input_grad, const T loss, const T* input,
...
@@ -150,9 +160,9 @@ static void CalcBoxLocationLossGrad(T* input_grad, const T loss, const T* input,
input_grad
[
box_idx
+
stride
]
=
input_grad
[
box_idx
+
stride
]
=
SCEGrad
<
T
>
(
input
[
box_idx
+
stride
],
ty
)
*
scale
*
loss
;
SCEGrad
<
T
>
(
input
[
box_idx
+
stride
],
ty
)
*
scale
*
loss
;
input_grad
[
box_idx
+
2
*
stride
]
=
input_grad
[
box_idx
+
2
*
stride
]
=
L
1
LossGrad
<
T
>
(
input
[
box_idx
+
2
*
stride
],
tw
)
*
scale
*
loss
;
L
2
LossGrad
<
T
>
(
input
[
box_idx
+
2
*
stride
],
tw
)
*
scale
*
loss
;
input_grad
[
box_idx
+
3
*
stride
]
=
input_grad
[
box_idx
+
3
*
stride
]
=
L
1
LossGrad
<
T
>
(
input
[
box_idx
+
3
*
stride
],
th
)
*
scale
*
loss
;
L
2
LossGrad
<
T
>
(
input
[
box_idx
+
3
*
stride
],
th
)
*
scale
*
loss
;
}
}
template
<
typename
T
>
template
<
typename
T
>
...
...
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
浏览文件 @
042fecef
...
@@ -27,6 +27,10 @@ def l1loss(x, y):
...
@@ -27,6 +27,10 @@ def l1loss(x, y):
return
abs
(
x
-
y
)
return
abs
(
x
-
y
)
def
l2loss
(
x
,
y
):
return
0.5
*
(
y
-
x
)
*
(
y
-
x
)
def
sce
(
x
,
label
):
def
sce
(
x
,
label
):
sigmoid_x
=
expit
(
x
)
sigmoid_x
=
expit
(
x
)
term1
=
label
*
np
.
log
(
sigmoid_x
)
term1
=
label
*
np
.
log
(
sigmoid_x
)
...
@@ -145,8 +149,8 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs):
...
@@ -145,8 +149,8 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs):
scale
=
(
2.0
-
gtbox
[
i
,
j
,
2
]
*
gtbox
[
i
,
j
,
3
])
*
gtscore
[
i
,
j
]
scale
=
(
2.0
-
gtbox
[
i
,
j
,
2
]
*
gtbox
[
i
,
j
,
3
])
*
gtscore
[
i
,
j
]
loss
[
i
]
+=
sce
(
x
[
i
,
an_idx
,
gj
,
gi
,
0
],
tx
)
*
scale
loss
[
i
]
+=
sce
(
x
[
i
,
an_idx
,
gj
,
gi
,
0
],
tx
)
*
scale
loss
[
i
]
+=
sce
(
x
[
i
,
an_idx
,
gj
,
gi
,
1
],
ty
)
*
scale
loss
[
i
]
+=
sce
(
x
[
i
,
an_idx
,
gj
,
gi
,
1
],
ty
)
*
scale
loss
[
i
]
+=
l
1
loss
(
x
[
i
,
an_idx
,
gj
,
gi
,
2
],
tw
)
*
scale
loss
[
i
]
+=
l
2
loss
(
x
[
i
,
an_idx
,
gj
,
gi
,
2
],
tw
)
*
scale
loss
[
i
]
+=
l
1
loss
(
x
[
i
,
an_idx
,
gj
,
gi
,
3
],
th
)
*
scale
loss
[
i
]
+=
l
2
loss
(
x
[
i
,
an_idx
,
gj
,
gi
,
3
],
th
)
*
scale
objness
[
i
,
an_idx
*
h
*
w
+
gj
*
w
+
gi
]
=
gtscore
[
i
,
j
]
objness
[
i
,
an_idx
*
h
*
w
+
gj
*
w
+
gi
]
=
gtscore
[
i
,
j
]
...
@@ -202,7 +206,7 @@ class TestYolov3LossOp(OpTest):
...
@@ -202,7 +206,7 @@ class TestYolov3LossOp(OpTest):
def
test_check_output
(
self
):
def
test_check_output
(
self
):
place
=
core
.
CPUPlace
()
place
=
core
.
CPUPlace
()
self
.
check_output_with_place
(
place
,
atol
=
2
e-3
)
self
.
check_output_with_place
(
place
,
atol
=
1
e-3
)
def
test_check_grad_ignore_gtbox
(
self
):
def
test_check_grad_ignore_gtbox
(
self
):
place
=
core
.
CPUPlace
()
place
=
core
.
CPUPlace
()
...
@@ -210,19 +214,16 @@ class TestYolov3LossOp(OpTest):
...
@@ -210,19 +214,16 @@ class TestYolov3LossOp(OpTest):
place
,
[
'X'
],
place
,
[
'X'
],
'Loss'
,
'Loss'
,
no_grad_set
=
set
([
"GTBox"
,
"GTLabel"
,
"GTScore"
]),
no_grad_set
=
set
([
"GTBox"
,
"GTLabel"
,
"GTScore"
]),
max_relative_error
=
0.
2
)
max_relative_error
=
0.
3
)
def
initTestCase
(
self
):
def
initTestCase
(
self
):
self
.
anchors
=
[
self
.
anchors
=
[
10
,
13
,
16
,
30
,
33
,
23
]
10
,
13
,
16
,
30
,
33
,
23
,
30
,
61
,
62
,
45
,
59
,
119
,
116
,
90
,
156
,
198
,
self
.
anchor_mask
=
[
1
,
2
]
373
,
326
self
.
class_num
=
5
]
self
.
ignore_thresh
=
0.5
self
.
anchor_mask
=
[
0
,
1
,
2
]
self
.
class_num
=
10
self
.
ignore_thresh
=
0.7
self
.
downsample
=
32
self
.
downsample
=
32
self
.
x_shape
=
(
3
,
len
(
self
.
anchor_mask
)
*
(
5
+
self
.
class_num
),
5
,
5
)
self
.
x_shape
=
(
3
,
len
(
self
.
anchor_mask
)
*
(
5
+
self
.
class_num
),
5
,
5
)
self
.
gtbox_shape
=
(
3
,
10
,
4
)
self
.
gtbox_shape
=
(
3
,
5
,
4
)
self
.
use_label_smooth
=
True
self
.
use_label_smooth
=
True
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录