Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
16788c58
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
16788c58
编写于
9月 14, 2018
作者:
Q
qingqing01
提交者:
GitHub
9月 14, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove the fasterrcnn_model.py (#1251)
上级
1450b769
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
0 addition
and
295 deletion
+0
-295
fluid/faster_rcnn/fasterrcnn_model.py
fluid/faster_rcnn/fasterrcnn_model.py
+0
-295
未找到文件。
fluid/faster_rcnn/fasterrcnn_model.py
已删除
100644 → 0
浏览文件 @
1450b769
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.initializer
import
Constant
from
paddle.fluid.regularizer
import
L2Decay
import
paddle.fluid
as
fluid
def
conv_bn_layer
(
input
,
ch_out
,
filter_size
,
stride
,
padding
,
act
=
'relu'
,
name
=
None
):
conv1
=
fluid
.
layers
.
conv2d
(
input
=
input
,
num_filters
=
ch_out
,
filter_size
=
filter_size
,
stride
=
stride
,
padding
=
padding
,
act
=
None
,
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
bias_attr
=
ParamAttr
(
name
=
name
+
"_biases"
),
name
=
name
+
'.conv2d.output.1'
)
if
name
==
"conv1"
:
bn_name
=
"bn_"
+
name
else
:
bn_name
=
"bn"
+
name
[
3
:]
return
fluid
.
layers
.
batch_norm
(
input
=
conv1
,
act
=
act
,
name
=
bn_name
+
'.output.1'
,
param_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
),
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
),
moving_mean_name
=
bn_name
+
'_mean'
,
moving_variance_name
=
bn_name
+
'_variance'
,
is_test
=
True
)
def
conv_affine_layer
(
input
,
ch_out
,
filter_size
,
stride
,
padding
,
act
=
'relu'
,
name
=
None
):
conv
=
fluid
.
layers
.
conv2d
(
input
=
input
,
num_filters
=
ch_out
,
filter_size
=
filter_size
,
stride
=
stride
,
padding
=
padding
,
act
=
None
,
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
bias_attr
=
False
,
name
=
name
+
'.conv2d.output.1'
)
if
name
==
"conv1"
:
bn_name
=
"bn_"
+
name
else
:
bn_name
=
"bn"
+
name
[
3
:]
scale
=
fluid
.
layers
.
create_parameter
(
shape
=
[
conv
.
shape
[
1
]],
dtype
=
conv
.
dtype
,
attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
,
learning_rate
=
0.
),
default_initializer
=
Constant
(
1.
))
scale
.
stop_gradient
=
True
bias
=
fluid
.
layers
.
create_parameter
(
shape
=
[
conv
.
shape
[
1
]],
dtype
=
conv
.
dtype
,
attr
=
ParamAttr
(
bn_name
+
'_offset'
,
learning_rate
=
0.
),
default_initializer
=
Constant
(
0.
))
bias
.
stop_gradient
=
True
elt_mul
=
fluid
.
layers
.
elementwise_mul
(
x
=
conv
,
y
=
scale
,
axis
=
1
)
out
=
fluid
.
layers
.
elementwise_add
(
x
=
elt_mul
,
y
=
bias
,
axis
=
1
)
if
act
==
'relu'
:
out
=
fluid
.
layers
.
relu
(
x
=
out
)
return
out
def
shortcut
(
input
,
ch_out
,
stride
,
name
):
ch_in
=
input
.
shape
[
1
]
# if args.data_format == 'NCHW' else input.shape[-1]
if
ch_in
!=
ch_out
:
return
conv_affine_layer
(
input
,
ch_out
,
1
,
stride
,
0
,
None
,
name
=
name
)
else
:
return
input
def
basicblock
(
input
,
ch_out
,
stride
,
name
):
short
=
shortcut
(
input
,
ch_out
,
stride
,
name
=
name
)
conv1
=
conv_affine_layer
(
input
,
ch_out
,
3
,
stride
,
1
,
name
=
name
)
conv2
=
conv_affine_layer
(
conv1
,
ch_out
,
3
,
1
,
1
,
act
=
None
,
name
=
name
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
conv2
,
act
=
'relu'
,
name
=
name
)
def
bottleneck
(
input
,
ch_out
,
stride
,
name
):
short
=
shortcut
(
input
,
ch_out
*
4
,
stride
,
name
=
name
+
"_branch1"
)
conv1
=
conv_affine_layer
(
input
,
ch_out
,
1
,
stride
,
0
,
name
=
name
+
"_branch2a"
)
conv2
=
conv_affine_layer
(
conv1
,
ch_out
,
3
,
1
,
1
,
name
=
name
+
"_branch2b"
)
conv3
=
conv_affine_layer
(
conv2
,
ch_out
*
4
,
1
,
1
,
0
,
act
=
None
,
name
=
name
+
"_branch2c"
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
conv3
,
act
=
'relu'
,
name
=
name
+
".add.output.5"
)
def
layer_warp
(
block_func
,
input
,
ch_out
,
count
,
stride
,
name
):
res_out
=
block_func
(
input
,
ch_out
,
stride
,
name
=
name
+
"a"
)
for
i
in
range
(
1
,
count
):
res_out
=
block_func
(
res_out
,
ch_out
,
1
,
name
=
name
+
chr
(
ord
(
"a"
)
+
i
))
return
res_out
def
FasterRcnn
(
input
,
depth
,
anchor_sizes
,
variance
,
aspect_ratios
,
gt_box
,
is_crowd
,
gt_label
,
im_info
,
class_nums
,
use_random
):
cfg
=
{
18
:
([
2
,
2
,
2
,
1
],
basicblock
),
34
:
([
3
,
4
,
6
,
3
],
basicblock
),
50
:
([
3
,
4
,
6
,
3
],
bottleneck
),
101
:
([
3
,
4
,
23
,
3
],
bottleneck
),
152
:
([
3
,
8
,
36
,
3
],
bottleneck
)
}
stages
,
block_func
=
cfg
[
depth
]
conv1
=
conv_affine_layer
(
input
,
ch_out
=
64
,
filter_size
=
7
,
stride
=
2
,
padding
=
3
,
name
=
"conv1"
)
pool1
=
fluid
.
layers
.
pool2d
(
input
=
conv1
,
pool_type
=
'max'
,
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
1
,
name
=
"pool1.max_pool.output.1"
)
res2
=
layer_warp
(
block_func
,
pool1
,
64
,
stages
[
0
],
1
,
name
=
"res2"
)
res2
.
stop_gradient
=
True
res3
=
layer_warp
(
block_func
,
res2
,
128
,
stages
[
1
],
2
,
name
=
"res3"
)
res4
=
layer_warp
(
block_func
,
res3
,
256
,
stages
[
2
],
2
,
name
=
"res4"
)
#========= RPN ============
# rpn_conv/3*3
rpn_conv
=
fluid
.
layers
.
conv2d
(
input
=
res4
,
num_filters
=
1024
,
filter_size
=
3
,
stride
=
1
,
padding
=
1
,
act
=
'relu'
,
name
=
'conv_rpn'
,
param_attr
=
ParamAttr
(
name
=
"conv_rpn_w"
),
bias_attr
=
ParamAttr
(
name
=
"conv_rpn_b"
,
learning_rate
=
2.
,
regularizer
=
L2Decay
(
0.
)))
anchor
,
var
=
fluid
.
layers
.
anchor_generator
(
input
=
rpn_conv
,
anchor_sizes
=
anchor_sizes
,
aspect_ratios
=
aspect_ratios
,
variance
=
variance
,
stride
=
[
16.0
,
16.0
])
num_anchor
=
anchor
.
shape
[
2
]
rpn_cls_score
=
fluid
.
layers
.
conv2d
(
rpn_conv
,
num_filters
=
num_anchor
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
,
act
=
None
,
name
=
'rpn_cls_score'
,
param_attr
=
ParamAttr
(
name
=
"rpn_cls_logits_w"
),
bias_attr
=
ParamAttr
(
name
=
"rpn_cls_logits_b"
,
learning_rate
=
2.
,
regularizer
=
L2Decay
(
0.
)))
rpn_bbox_pred
=
fluid
.
layers
.
conv2d
(
rpn_conv
,
num_filters
=
4
*
num_anchor
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
,
act
=
None
,
name
=
'rpn_bbox_pred'
,
param_attr
=
ParamAttr
(
name
=
"rpn_bbox_pred_w"
),
bias_attr
=
ParamAttr
(
name
=
"rpn_bbox_pred_b"
,
learning_rate
=
2.
,
regularizer
=
L2Decay
(
0.
)))
rpn_cls_score_prob
=
fluid
.
layers
.
sigmoid
(
rpn_cls_score
,
name
=
'rpn_cls_score_prob'
)
rpn_rois
,
rpn_roi_probs
=
fluid
.
layers
.
generate_proposals
(
scores
=
rpn_cls_score_prob
,
bbox_deltas
=
rpn_bbox_pred
,
im_info
=
im_info
,
anchors
=
anchor
,
variances
=
var
,
pre_nms_top_n
=
12000
,
post_nms_top_n
=
2000
,
nms_thresh
=
0.7
,
min_size
=
0.0
,
eta
=
1.0
)
rois
,
labels_int32
,
bbox_targets
,
bbox_inside_weights
,
\
bbox_outside_weights
=
fluid
.
layers
.
generate_proposal_labels
(
rpn_rois
=
rpn_rois
,
gt_classes
=
gt_label
,
is_crowd
=
is_crowd
,
gt_boxes
=
gt_box
,
im_info
=
im_info
,
batch_size_per_im
=
512
,
fg_fraction
=
0.25
,
fg_thresh
=
0.5
,
bg_thresh_hi
=
0.5
,
bg_thresh_lo
=
0.0
,
bbox_reg_weights
=
[
0.1
,
0.1
,
0.2
,
0.2
],
class_nums
=
class_nums
,
use_random
=
use_random
)
rois
.
stop_gradient
=
True
labels_int32
.
stop_gradient
=
True
bbox_targets
.
stop_gradient
=
True
bbox_inside_weights
.
stop_gradient
=
True
bbox_outside_weights
.
stop_gradient
=
True
pool5
=
fluid
.
layers
.
roi_pool
(
input
=
res4
,
rois
=
rois
,
pooled_height
=
14
,
pooled_width
=
14
,
spatial_scale
=
0.0625
)
res5_2_sum
=
layer_warp
(
block_func
,
pool5
,
512
,
stages
[
3
],
2
,
name
=
"res5"
)
res5_pool
=
fluid
.
layers
.
pool2d
(
res5_2_sum
,
pool_type
=
'avg'
,
pool_size
=
7
,
name
=
'res5_pool'
)
cls_score
=
fluid
.
layers
.
fc
(
input
=
res5_pool
,
size
=
class_nums
,
act
=
None
,
name
=
'cls_score'
,
param_attr
=
ParamAttr
(
name
=
'cls_score_w'
),
bias_attr
=
ParamAttr
(
name
=
'cls_score_b'
,
learning_rate
=
2.
,
regularizer
=
L2Decay
(
0.
)))
bbox_pred
=
fluid
.
layers
.
fc
(
input
=
res5_pool
,
size
=
4
*
class_nums
,
act
=
None
,
name
=
'bbox_pred'
,
param_attr
=
ParamAttr
(
name
=
'bbox_pred_w'
),
bias_attr
=
ParamAttr
(
name
=
'bbox_pred_b'
,
learning_rate
=
2.
,
regularizer
=
L2Decay
(
0.
)))
return
rpn_cls_score
,
rpn_bbox_pred
,
anchor
,
var
,
cls_score
,
\
bbox_pred
,
bbox_targets
,
bbox_inside_weights
,
\
bbox_outside_weights
,
rois
,
labels_int32
def
RPNloss
(
rpn_cls_prob
,
rpn_bbox_pred
,
anchor
,
var
,
gt_box
,
is_crowd
,
im_info
,
use_random
):
rpn_cls_score_reshape
=
fluid
.
layers
.
transpose
(
rpn_cls_prob
,
perm
=
[
0
,
2
,
3
,
1
])
rpn_bbox_pred_reshape
=
fluid
.
layers
.
transpose
(
rpn_bbox_pred
,
perm
=
[
0
,
2
,
3
,
1
])
anchor_reshape
=
fluid
.
layers
.
reshape
(
anchor
,
shape
=
(
-
1
,
4
))
var_reshape
=
fluid
.
layers
.
reshape
(
var
,
shape
=
(
-
1
,
4
))
rpn_cls_score_reshape
=
fluid
.
layers
.
reshape
(
x
=
rpn_cls_score_reshape
,
shape
=
(
0
,
-
1
,
1
))
rpn_bbox_pred_reshape
=
fluid
.
layers
.
reshape
(
x
=
rpn_bbox_pred_reshape
,
shape
=
(
0
,
-
1
,
4
))
score_pred
,
loc_pred
,
score_target
,
loc_target
=
fluid
.
layers
.
rpn_target_assign
(
bbox_pred
=
rpn_bbox_pred_reshape
,
cls_logits
=
rpn_cls_score_reshape
,
anchor_box
=
anchor_reshape
,
anchor_var
=
var_reshape
,
gt_boxes
=
gt_box
,
is_crowd
=
is_crowd
,
im_info
=
im_info
,
rpn_batch_size_per_im
=
256
,
rpn_straddle_thresh
=
0.0
,
rpn_fg_fraction
=
0.5
,
rpn_positive_overlap
=
0.7
,
rpn_negative_overlap
=
0.3
,
use_random
=
use_random
)
score_target
=
fluid
.
layers
.
cast
(
x
=
score_target
,
dtype
=
'float32'
)
rpn_cls_loss
=
fluid
.
layers
.
sigmoid_cross_entropy_with_logits
(
x
=
score_pred
,
label
=
score_target
)
rpn_cls_loss
=
fluid
.
layers
.
reduce_mean
(
rpn_cls_loss
,
name
=
'loss_rpn_cls'
)
rpn_reg_loss
=
fluid
.
layers
.
smooth_l1
(
x
=
loc_pred
,
y
=
loc_target
,
sigma
=
3.0
)
rpn_reg_loss
=
fluid
.
layers
.
reduce_sum
(
rpn_reg_loss
,
name
=
'loss_rpn_bbox'
)
score_shape
=
fluid
.
layers
.
shape
(
score_target
)
score_shape
=
fluid
.
layers
.
cast
(
x
=
score_shape
,
dtype
=
'float32'
)
norm
=
fluid
.
layers
.
reduce_prod
(
score_shape
)
norm
.
stop_gradient
=
True
rpn_reg_loss
=
rpn_reg_loss
/
norm
return
rpn_cls_loss
,
rpn_reg_loss
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录