Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
3cdb419b
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3cdb419b
编写于
2月 09, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add doc for prior box
上级
19749d52
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
137 addition
and
21 deletion
+137
-21
python/paddle/v2/fluid/layers/nn.py
python/paddle/v2/fluid/layers/nn.py
+137
-21
未找到文件。
python/paddle/v2/fluid/layers/nn.py
浏览文件 @
3cdb419b
...
@@ -22,7 +22,6 @@ from ..param_attr import ParamAttr
...
@@ -22,7 +22,6 @@ from ..param_attr import ParamAttr
from
layer_function_generator
import
autodoc
from
layer_function_generator
import
autodoc
from
tensor
import
concat
from
tensor
import
concat
import
math
import
math
import
numpy
as
np
from
operator
import
mul
from
operator
import
mul
__all__
=
[
__all__
=
[
...
@@ -3006,10 +3005,43 @@ def reshape_with_axis(input, axis):
...
@@ -3006,10 +3005,43 @@ def reshape_with_axis(input, axis):
"""
"""
**ReshapeWithAxis Layer**
**ReshapeWithAxis Layer**
"""
According to the axis to merge the adjacent dim of input. Currently, the axis of
assert
len
(
input
.
shape
)
>
axis
and
axis
>=
0
,
' '
reshape_with_axis must be a scalar.
Args:
input(variable): The input tensor.
axis(list): According to the axis to merge the adjacent dim.
Returns:
Variable: A tensor variable.
Examples:
.. code-block:: python
x = fluid.layers.data(name="data", shape=[3, 32, 32], dtype="float32")
reshaped = fluid.layers.reshape_with_axis(input=x, axis=2)
reshaped.shape
>> [-1, 1024]
reshaped = fluid.layers.reshape_with_axis(input=x, axis=[1,3])
reshaped.shape
>> [-1, 96, 32]
"""
assert
isinstance
(
axis
,
list
),
"axis should be list."
assert
len
(
input
.
shape
)
>
len
(
axis
),
"the length of axis should be litter than input.shape's."
input_shape
=
input
.
shape
input_shape
=
input
.
shape
new_dim
=
[
-
1
,
reduce
(
mul
,
input_shape
[
axis
:
len
(
input_shape
)],
1
)]
temp
=
0
for
ax
in
axis
:
assert
ax
<
len
(
input
.
shape
)
and
ax
>
0
,
\
'The data of Axis should be between 1 and len(input.shape)'
assert
ax
>
temp
,
'Axis should be incremented sequence'
temp
=
ax
axis
+=
[
len
(
input
.
shape
)]
new_shape
=
[]
for
i
in
range
(
len
(
axis
)
-
1
):
new_shape
+=
[
reduce
(
mul
,
input_shape
[
axis
[
i
]:
axis
[
i
+
1
]],
1
)]
new_shape
=
[
-
1
]
+
new_shape
helper
=
LayerHelper
(
'reshape'
,
**
locals
())
helper
=
LayerHelper
(
'reshape'
,
**
locals
())
out
=
helper
.
create_tmp_variable
(
helper
.
input_dtype
())
out
=
helper
.
create_tmp_variable
(
helper
.
input_dtype
())
...
@@ -3017,14 +3049,28 @@ def reshape_with_axis(input, axis):
...
@@ -3017,14 +3049,28 @@ def reshape_with_axis(input, axis):
type
=
'reshape'
,
type
=
'reshape'
,
inputs
=
{
'X'
:
[
input
]},
inputs
=
{
'X'
:
[
input
]},
outputs
=
{
'Out'
:
[
out
]},
outputs
=
{
'Out'
:
[
out
]},
attrs
=
{
'shape'
:
new_
dim
})
attrs
=
{
'shape'
:
new_
shape
})
return
out
return
out
def
reshape
(
input
,
new_
dim
):
def
reshape
(
input
,
new_
shape
):
"""
"""
**Reshape Layer**
**Reshape Layer**
Reshape the shape of input according to new_dim.
Args:
input(variable): The input tensor.
new_shape(list): The new shape of input.
Returns:
Variable: A tensor variable.
Examples:
.. code-block:: python
x = fluid.layers.data(name="data", shape=[3, 32, 32], dtype="float32")
reshaped = fluid.layers.reshape(input=x, new_shape=[-1, 1024])
"""
"""
helper
=
LayerHelper
(
'reshape'
,
**
locals
())
helper
=
LayerHelper
(
'reshape'
,
**
locals
())
out
=
helper
.
create_tmp_variable
(
helper
.
input_dtype
())
out
=
helper
.
create_tmp_variable
(
helper
.
input_dtype
())
...
@@ -3051,6 +3097,44 @@ def prior_box(input,
...
@@ -3051,6 +3097,44 @@ def prior_box(input,
"""
"""
**Prior_box**
**Prior_box**
Generate prior boxes for SSD(Single Shot MultiBox Detector) algorithm.
Each position of the input produce N prior boxes, N is determined by
the count of min_sizes, max_sizes and aspect_ratios, The size of the
box is in range(min_size, max_size) interval, which is generated in
sequence according to the aspect_ratios.
Args:
input(variable): The input feature data of PriorBox, the layout is NCHW.
image(variable): The input image data of PriorBoxOp, the layout is NCHW.
min_sizes(list): the min sizes of generated prior boxes.
max_sizes(list): the max sizes of generated prior boxes.
aspect_ratios(list): the aspect ratios of generated prior boxes.
variance(list): the variances to be encoded in prior boxes.
flip(bool): Whether to flip aspect ratios.
clip(bool): Whether to clip out-of-boundary boxes.
step_w(list): Prior boxes step across width, 0 for auto calculation.
step_h(list): Prior boxes step across height, 0 for auto calculation.
offset(float): Prior boxes center offset.
name(str): Name of the prior box layer.
Returns:
boxes(variable): the output prior boxes of PriorBoxOp. The layout is
[H, W, num_priors, 4]. H is the height of input, W is the width
of input, num_priors is the box count of each position.
Variances(variable): the expanded variances of PriorBoxOp. The layout
is [H, W, num_priors, 4]. H is the height of input, W is the width
of input, num_priors is the box count of each position.
Examples:
.. code-block:: python
data = fluid.layers.data(name="data", shape=[3, 32, 32], dtype="float32")
conv2d = fluid.layers.conv2d(
input=data, num_filters=2, filter_size=3)
box, var = fluid.layers.prior_box(conv2d, data,
min_size, max_size, aspect_ratio,
variance, flip, clip,
step_w, step_h, offset)
"""
"""
helper
=
LayerHelper
(
"prior_box"
,
**
locals
())
helper
=
LayerHelper
(
"prior_box"
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
...
@@ -3093,7 +3177,39 @@ def prior_boxes(input_layers,
...
@@ -3093,7 +3177,39 @@ def prior_boxes(input_layers,
name
=
None
):
name
=
None
):
"""
"""
**Prior_boxes**
**Prior_boxes**
e.g.
Generate prior boxes for SSD(Single Shot MultiBox Detector) algorithm.
Each position of the input produce N prior boxes, N is determined by
the count of min_sizes, max_sizes and aspect_ratios, The size of the
box is in range(min_size, max_size) interval, which is generated in
sequence according to the aspect_ratios.
Args:
input(list): The list of input variables, the format of all variables is NCHW.
image(variable): The input image data of PriorBoxOp, the layout is NCHW.
min_ratio(list): the min sizes of generated prior boxes.
max_ratio(list): the max sizes of generated prior boxes.
aspect_ratios(list): the aspect ratios of generated prior boxes.
min_dim(int):
step_w(list): Prior boxes step across width, 0 for auto calculation.
step_h(list): Prior boxes step across height, 0 for auto calculation.
offset(float): Prior boxes center offset.
variance(list): the variances to be encoded in prior boxes.
flip(bool): Whether to flip aspect ratios.
clip(bool): Whether to clip out-of-boundary boxes.
name(str): Name of the prior box layer.
Returns:
boxes(variable): the output prior boxes of PriorBoxOp. The layout is
[num_priors, 4]. num_priors is the total box count of each
position of input_layers.
Variances(variable): the expanded variances of PriorBoxOp. The layout
is [num_priors, 4]. num_priors is the total box count of each
position of input_layers
Examples:
.. code-block:: python
prior_boxes(
prior_boxes(
input_layers = [conv1, conv2, conv3, conv4, conv5, conv6],
input_layers = [conv1, conv2, conv3, conv4, conv5, conv6],
image = data,
image = data,
...
@@ -3103,7 +3219,7 @@ def prior_boxes(input_layers,
...
@@ -3103,7 +3219,7 @@ def prior_boxes(input_layers,
aspect_ratios = [[2.], [2., 3.], [2., 3.], [2., 3.], [2.], [2.]],
aspect_ratios = [[2.], [2., 3.], [2., 3.], [2., 3.], [2.], [2.]],
min_dim = 300,
min_dim = 300,
offset = 0.5,
offset = 0.5,
variance = [
0.1],
variance = [0.1,0.1,0.1,
0.1],
flip=True,
flip=True,
clip=True)
clip=True)
"""
"""
...
@@ -3168,8 +3284,8 @@ def prior_boxes(input_layers,
...
@@ -3168,8 +3284,8 @@ def prior_boxes(input_layers,
reshaped_boxes
=
[]
reshaped_boxes
=
[]
reshaped_vars
=
[]
reshaped_vars
=
[]
for
i
in
range
(
len
(
box_results
)):
for
i
in
range
(
len
(
box_results
)):
reshaped_boxes
+=
[
reshape_with_axis
(
box_results
[
i
],
axis
=
axis
)]
reshaped_boxes
+=
[
reshape_with_axis
(
box_results
[
i
],
axis
=
[
axis
]
)]
reshaped_vars
+=
[
reshape_with_axis
(
var_results
[
i
],
axis
=
axis
)]
reshaped_vars
+=
[
reshape_with_axis
(
var_results
[
i
],
axis
=
[
axis
]
)]
helper
=
LayerHelper
(
"concat"
,
**
locals
())
helper
=
LayerHelper
(
"concat"
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录