Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
db8ff57a
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看板
提交
db8ff57a
编写于
12月 17, 2018
作者:
D
dengkaipeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove useless code and update doc. test=develop
上级
577a92d9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
69 deletion
+45
-69
paddle/fluid/operators/yolov3_loss_op.cc
paddle/fluid/operators/yolov3_loss_op.cc
+17
-15
paddle/fluid/operators/yolov3_loss_op.h
paddle/fluid/operators/yolov3_loss_op.h
+28
-36
python/paddle/fluid/layers/detection.py
python/paddle/fluid/layers/detection.py
+0
-13
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
+0
-5
未找到文件。
paddle/fluid/operators/yolov3_loss_op.cc
浏览文件 @
db8ff57a
...
...
@@ -138,17 +138,23 @@ class Yolov3LossOpMaker : public framework::OpProtoAndCheckerMaker {
thresh, the confidence score loss of this anchor box will be ignored.
Therefore, the yolov3 loss consist of three major parts, box location loss,
confidence score loss, and classification loss. The MSE loss is used for
box location, and binary cross entropy loss is used for confidence score
loss and classification loss.
confidence score loss, and classification loss. The L1 loss is used for
box coordinates (w, h), and sigmoid cross entropy loss is used for box
coordinates (x, y), confidence score loss and classification loss.
In order to trade off box coordinate losses between big boxes and small
boxes, box coordinate losses will be mutiplied by scale weight, which is
calculated as follow.
$$
weight_{box} = 2.0 - t_w * t_h
$$
Final loss will be represented as follow.
$$
loss = \loss_weight_{xy} * loss_{xy} + \loss_weight_{wh} * loss_{wh}
+ \loss_weight_{conf_target} * loss_{conf_target}
+ \loss_weight_{conf_notarget} * loss_{conf_notarget}
+ \loss_weight_{class} * loss_{class}
loss = (loss_{xy} + loss_{wh}) * weight_{box}
+ loss_{conf} + loss_{class}
$$
)DOC"
);
}
...
...
@@ -204,11 +210,7 @@ namespace ops = paddle::operators;
REGISTER_OPERATOR
(
yolov3_loss
,
ops
::
Yolov3LossOp
,
ops
::
Yolov3LossOpMaker
,
ops
::
Yolov3LossGradMaker
);
REGISTER_OPERATOR
(
yolov3_loss_grad
,
ops
::
Yolov3LossOpGrad
);
REGISTER_OP_CPU_KERNEL
(
yolov3_loss
,
ops
::
Yolov3LossKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
Yolov3LossKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
yolov3_loss_grad
,
ops
::
Yolov3LossGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
Yolov3LossGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
yolov3_loss
,
ops
::
Yolov3LossKernel
<
float
>
,
ops
::
Yolov3LossKernel
<
double
>
);
REGISTER_OP_CPU_KERNEL
(
yolov3_loss_grad
,
ops
::
Yolov3LossGradKernel
<
float
>
,
ops
::
Yolov3LossGradKernel
<
double
>
);
paddle/fluid/operators/yolov3_loss_op.h
浏览文件 @
db8ff57a
...
...
@@ -260,26 +260,18 @@ static void CalcYolov3Loss(T* loss_data, const Tensor& input, const Tensor& tx,
const
int
class_num
=
tclass
.
dims
()[
4
];
const
int
grid_num
=
h
*
w
;
// T l = 0.0;
CalcSCE
<
T
>
(
loss_data
,
input_data
,
tx_data
,
tweight_data
,
obj_mask_data
,
n
,
an_num
,
grid_num
,
class_num
,
1
);
CalcSCE
<
T
>
(
loss_data
,
input_data
+
grid_num
,
ty_data
,
tweight_data
,
obj_mask_data
,
n
,
an_num
,
grid_num
,
class_num
,
1
);
// LOG(ERROR) << "C++ xy: " << loss_data[0] - l;
// l = loss_data[0];
CalcL1Loss
<
T
>
(
loss_data
,
input_data
+
2
*
grid_num
,
tw_data
,
tweight_data
,
obj_mask_data
,
n
,
an_num
,
grid_num
,
class_num
);
CalcL1Loss
<
T
>
(
loss_data
,
input_data
+
3
*
grid_num
,
th_data
,
tweight_data
,
obj_mask_data
,
n
,
an_num
,
grid_num
,
class_num
);
// LOG(ERROR) << "C++ wh: " << loss_data[0] - l;
// l = loss_data[0];
CalcSCE
<
T
>
(
loss_data
,
input_data
+
4
*
grid_num
,
tconf_data
,
conf_mask_data
,
conf_mask_data
,
n
,
an_num
,
grid_num
,
class_num
,
1
);
// LOG(ERROR) << "C++ conf: " << loss_data[0] - l;
// l = loss_data[0];
CalcSCE
<
T
>
(
loss_data
,
input_data
+
5
*
grid_num
,
tclass_data
,
obj_mask_data
,
obj_mask_data
,
n
,
an_num
,
grid_num
,
class_num
,
class_num
);
// LOG(ERROR) << "C++ class: " << loss_data[0] - l;
}
template
<
typename
T
>
...
...
@@ -329,7 +321,7 @@ static void CalcYolov3LossGrad(T* input_grad_data, const Tensor& loss_grad,
obj_mask_data
,
n
,
an_num
,
grid_num
,
class_num
,
class_num
);
}
template
<
typename
DeviceContext
,
typename
T
>
template
<
typename
T
>
class
Yolov3LossKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
...
...
@@ -359,24 +351,24 @@ class Yolov3LossKernel : public framework::OpKernel<T> {
tconf
.
mutable_data
<
T
>
({
n
,
an_num
,
h
,
w
},
ctx
.
GetPlace
());
tclass
.
mutable_data
<
T
>
({
n
,
an_num
,
h
,
w
,
class_num
},
ctx
.
GetPlace
());
math
::
SetConstant
<
DeviceContext
,
T
>
constant
;
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
conf_mask
,
static_cast
<
T
>
(
1.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
obj_mask
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tx
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
ty
,
math
::
SetConstant
<
platform
::
CPUDeviceContext
,
T
>
constant
;
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
conf_mask
,
static_cast
<
T
>
(
1.0
));
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
obj_mask
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
tx
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tw
,
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
ty
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
th
,
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
tw
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tweight
,
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
th
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tconf
,
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
tweight
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
tconf
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tclass
,
constant
(
ctx
.
template
device_context
<
platform
::
CPU
DeviceContext
>(),
&
tclass
,
static_cast
<
T
>
(
0.0
));
PreProcessGTBox
<
T
>
(
*
gt_box
,
*
gt_label
,
ignore_thresh
,
anchors
,
input_size
,
...
...
@@ -390,7 +382,7 @@ class Yolov3LossKernel : public framework::OpKernel<T> {
}
};
template
<
typename
DeviceContext
,
typename
T
>
template
<
typename
T
>
class
Yolov3LossGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
...
...
@@ -422,24 +414,24 @@ class Yolov3LossGradKernel : public framework::OpKernel<T> {
tconf
.
mutable_data
<
T
>
({
n
,
an_num
,
h
,
w
},
ctx
.
GetPlace
());
tclass
.
mutable_data
<
T
>
({
n
,
an_num
,
h
,
w
,
class_num
},
ctx
.
GetPlace
());
math
::
SetConstant
<
DeviceContext
,
T
>
constant
;
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
conf_mask
,
static_cast
<
T
>
(
1.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
obj_mask
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tx
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
ty
,
math
::
SetConstant
<
platform
::
CPUDeviceContext
,
T
>
constant
;
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
conf_mask
,
static_cast
<
T
>
(
1.0
));
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
obj_mask
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
tx
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tw
,
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
ty
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
th
,
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
tw
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tweight
,
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
th
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tconf
,
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
tweight
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
platform
::
CPUDeviceContext
>(),
&
tconf
,
static_cast
<
T
>
(
0.0
));
constant
(
ctx
.
template
device_context
<
DeviceContext
>(),
&
tclass
,
constant
(
ctx
.
template
device_context
<
platform
::
CPU
DeviceContext
>(),
&
tclass
,
static_cast
<
T
>
(
0.0
));
PreProcessGTBox
<
T
>
(
*
gt_box
,
*
gt_label
,
ignore_thresh
,
anchors
,
input_size
,
...
...
python/paddle/fluid/layers/detection.py
浏览文件 @
db8ff57a
...
...
@@ -485,19 +485,6 @@ def yolov3_loss(x,
"input_size"
:
input_size
,
}
# if loss_weight_xy is not None and isinstance(loss_weight_xy, float):
# self.attrs['loss_weight_xy'] = loss_weight_xy
# if loss_weight_wh is not None and isinstance(loss_weight_wh, float):
# self.attrs['loss_weight_wh'] = loss_weight_wh
# if loss_weight_conf_target is not None and isinstance(
# loss_weight_conf_target, float):
# self.attrs['loss_weight_conf_target'] = loss_weight_conf_target
# if loss_weight_conf_notarget is not None and isinstance(
# loss_weight_conf_notarget, float):
# self.attrs['loss_weight_conf_notarget'] = loss_weight_conf_notarget
# if loss_weight_class is not None and isinstance(loss_weight_class, float):
# self.attrs['loss_weight_class'] = loss_weight_class
helper
.
append_op
(
type
=
'yolov3_loss'
,
inputs
=
{
"X"
:
x
,
...
...
python/paddle/fluid/tests/unittests/test_yolov3_loss_op.py
浏览文件 @
db8ff57a
...
...
@@ -157,11 +157,6 @@ def YoloV3Loss(x, gtbox, gtlabel, attrs):
loss_obj
=
sce
(
pred_conf
,
tconf
,
conf_mask
)
loss_class
=
sce
(
pred_cls
,
tcls
,
obj_mask_expand
)
# print("python loss_xy: ", loss_x + loss_y)
# print("python loss_wh: ", loss_w + loss_h)
# print("python loss_obj: ", loss_obj)
# print("python loss_class: ", loss_class)
return
loss_x
+
loss_y
+
loss_w
+
loss_h
+
loss_obj
+
loss_class
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录