Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
c0fa8d2e
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看板
提交
c0fa8d2e
编写于
12月 10, 2018
作者:
D
dengkaipeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use L1Loss for w, h. test=develop
上级
3841983a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
6 deletion
+59
-6
paddle/fluid/operators/yolov3_loss_op.h
paddle/fluid/operators/yolov3_loss_op.h
+49
-4
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
+10
-2
未找到文件。
paddle/fluid/operators/yolov3_loss_op.h
浏览文件 @
c0fa8d2e
...
...
@@ -32,6 +32,49 @@ static inline bool isZero(T x) {
return
fabs
(
x
)
<
1e-6
;
}
template
<
typename
T
>
static
inline
void
CalcL1LossWithWeight
(
const
Tensor
&
x
,
const
Tensor
&
y
,
const
Tensor
&
weight
,
const
T
loss_weight
,
T
*
loss
)
{
int
n
=
x
.
dims
()[
0
];
int
stride
=
x
.
numel
()
/
n
;
const
T
*
x_data
=
x
.
data
<
T
>
();
const
T
*
y_data
=
y
.
data
<
T
>
();
const
T
*
weight_data
=
weight
.
data
<
T
>
();
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
0
;
j
<
stride
;
j
++
)
{
loss
[
i
]
+=
fabs
(
y_data
[
j
]
-
x_data
[
j
])
*
weight_data
[
j
]
*
loss_weight
;
}
x_data
+=
stride
;
y_data
+=
stride
;
weight_data
+=
stride
;
}
}
template
<
typename
T
>
static
void
CalcL1LossGradWithWeight
(
const
T
*
loss_grad
,
Tensor
*
grad
,
const
Tensor
&
x
,
const
Tensor
&
y
,
const
Tensor
&
weight
)
{
int
n
=
x
.
dims
()[
0
];
int
stride
=
x
.
numel
()
/
n
;
T
*
grad_data
=
grad
->
data
<
T
>
();
const
T
*
x_data
=
x
.
data
<
T
>
();
const
T
*
y_data
=
y
.
data
<
T
>
();
const
T
*
weight_data
=
weight
.
data
<
T
>
();
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
0
;
j
<
stride
;
j
++
)
{
grad_data
[
j
]
=
weight_data
[
j
]
*
loss_grad
[
i
];
if
(
x_data
[
j
]
<
y_data
[
j
])
grad_data
[
j
]
*=
-
1.0
;
}
grad_data
+=
stride
;
x_data
+=
stride
;
y_data
+=
stride
;
weight_data
+=
stride
;
}
}
template
<
typename
T
>
static
inline
void
CalcMSEWithWeight
(
const
Tensor
&
x
,
const
Tensor
&
y
,
const
Tensor
&
weight
,
const
T
loss_weight
,
...
...
@@ -374,8 +417,8 @@ class Yolov3LossKernel : public framework::OpKernel<T> {
memset
(
loss_data
,
0
,
n
*
sizeof
(
T
));
CalcSCEWithWeight
<
T
>
(
pred_x
,
tx
,
obj_weight
,
loss_weight_xy
,
loss_data
);
CalcSCEWithWeight
<
T
>
(
pred_y
,
ty
,
obj_weight
,
loss_weight_xy
,
loss_data
);
Calc
MSE
WithWeight
<
T
>
(
pred_w
,
tw
,
obj_weight
,
loss_weight_wh
,
loss_data
);
Calc
MSE
WithWeight
<
T
>
(
pred_h
,
th
,
obj_weight
,
loss_weight_wh
,
loss_data
);
Calc
L1Loss
WithWeight
<
T
>
(
pred_w
,
tw
,
obj_weight
,
loss_weight_wh
,
loss_data
);
Calc
L1Loss
WithWeight
<
T
>
(
pred_h
,
th
,
obj_weight
,
loss_weight_wh
,
loss_data
);
CalcSCEWithWeight
<
T
>
(
pred_conf
,
tconf
,
obj_mask
,
loss_weight_conf_target
,
loss_data
);
CalcSCEWithWeight
<
T
>
(
pred_conf
,
tconf
,
noobj_mask
,
...
...
@@ -471,8 +514,10 @@ class Yolov3LossGradKernel : public framework::OpKernel<T> {
grad_class
.
mutable_data
<
T
>
({
n
,
an_num
,
h
,
w
,
class_num
},
ctx
.
GetPlace
());
CalcSCEGradWithWeight
<
T
>
(
loss_grad_data
,
&
grad_x
,
pred_x
,
tx
,
obj_weight
);
CalcSCEGradWithWeight
<
T
>
(
loss_grad_data
,
&
grad_y
,
pred_y
,
ty
,
obj_weight
);
CalcMSEGradWithWeight
<
T
>
(
loss_grad_data
,
&
grad_w
,
pred_w
,
tw
,
obj_weight
);
CalcMSEGradWithWeight
<
T
>
(
loss_grad_data
,
&
grad_h
,
pred_h
,
th
,
obj_weight
);
CalcL1LossGradWithWeight
<
T
>
(
loss_grad_data
,
&
grad_w
,
pred_w
,
tw
,
obj_weight
);
CalcL1LossGradWithWeight
<
T
>
(
loss_grad_data
,
&
grad_h
,
pred_h
,
th
,
obj_weight
);
CalcSCEGradWithWeight
<
T
>
(
loss_grad_data
,
&
grad_conf_target
,
pred_conf
,
tconf
,
obj_mask
);
CalcSCEGradWithWeight
<
T
>
(
loss_grad_data
,
&
grad_conf_notarget
,
pred_conf
,
...
...
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
浏览文件 @
c0fa8d2e
...
...
@@ -23,6 +23,14 @@ from op_test import OpTest
from
paddle.fluid
import
core
def
l1loss
(
x
,
y
,
weight
):
n
=
x
.
shape
[
0
]
x
=
x
.
reshape
((
n
,
-
1
))
y
=
y
.
reshape
((
n
,
-
1
))
weight
=
weight
.
reshape
((
n
,
-
1
))
return
(
np
.
abs
(
y
-
x
)
*
weight
).
sum
(
axis
=
1
)
def
mse
(
x
,
y
,
weight
):
n
=
x
.
shape
[
0
]
x
=
x
.
reshape
((
n
,
-
1
))
...
...
@@ -146,8 +154,8 @@ def YoloV3Loss(x, gtbox, gtlabel, attrs):
np
.
expand_dims
(
obj_mask
,
4
),
(
1
,
1
,
1
,
1
,
int
(
attrs
[
'class_num'
])))
loss_x
=
sce
(
pred_x
,
tx
,
obj_weight
)
loss_y
=
sce
(
pred_y
,
ty
,
obj_weight
)
loss_w
=
mse
(
pred_w
,
tw
,
obj_weight
)
loss_h
=
mse
(
pred_h
,
th
,
obj_weight
)
loss_w
=
l1loss
(
pred_w
,
tw
,
obj_weight
)
loss_h
=
l1loss
(
pred_h
,
th
,
obj_weight
)
loss_conf_target
=
sce
(
pred_conf
,
tconf
,
obj_mask
)
loss_conf_notarget
=
sce
(
pred_conf
,
tconf
,
noobj_mask
)
loss_class
=
sce
(
pred_cls
,
tcls
,
obj_mask_expand
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录