@@ -1974,16 +1974,13 @@ def sequence_reshape(input, new_dim):
1974
1974
1975
1975
1976
1976
def im2sequence (input ,
1977
- block_x = 1 ,
1978
- block_y = 1 ,
1979
- stride_x = 1 ,
1980
- stride_y = 1 ,
1981
- padding_x = 0 ,
1982
- padding_y = 0 ,
1977
+ filter_size = 1 ,
1978
+ stride = 1 ,
1979
+ padding = 0 ,
1983
1980
name = None ,
1984
1981
layer_attr = None ):
1985
1982
"""
1986
- This op use block to scan images and convert these images to sequences.
1983
+ This op use filter to scan images and convert these images to sequences.
1987
1984
After expanding, the number of time step are output_height * output_width
1988
1985
for an image, in which output_height and output_width are calculated
1989
1986
by below equation:
@@ -1995,23 +1992,34 @@ def im2sequence(input,
1995
1992
1996
1993
And the dimension of each time step is block_y * block_x * input.channels.
1997
1994
1998
-
1999
-
2000
1995
Args:
2001
1996
input (Variable): The input should be a tensor in NCHW format.
2002
- block_x (int): The width of sub block.
2003
- block_y (int): The width of sub block.
2004
- stride_x (int): The stride size in horizontal direction.
2005
- stride_y (int): The stride size in vertical direction.
2006
- padding_x (int): The padding size in horizontal direction.
2007
- padding_y (int): The padding size in vertical direction.
1997
+
1998
+ filter_size(int|tuple|None): The filter size. If filter_size is a tuple,
1999
+ it must contain two integers, (filter_size_H, filter_size_W).
2000
+ Otherwise, the filter will be a square.
2001
+
2002
+ stride(int|tuple): The stride size. If stride is a tuple, it must
2003
+ contain two integers, (stride_H, stride_W). Otherwise, the
2004
+ stride_H = stride_W = stride. Default: stride = 1.
2005
+
2006
+ padding(int|tuple): The padding size. If padding is a tuple, it can
2007
+ contain two integers like (padding_H, padding_W) which means
2008
+ padding_up = padding_down = padding_H and
2009
+ padding_left = padding_right = padding_W. Or it can use
2010
+ (padding_up, padding_left, padding_down, padding_right) to indicate
2011
+ paddings of four direction. Otherwise, a scalar padding means
2012
+ padding_up = padding_down = padding_left = padding_right = padding
2013
+ Default: padding = 0.
2014
+
2008
2015
name (int): The name of this layer. It is optional.
2009
2016
2010
2017
Returns:
2011
- output: The output is a LoDTensor woth shape
2012
- {input.batch_size * output_y * x,
2013
- block_y * block_x * input.channels}.
2014
- If we regard output as matrix, each row of this matrix is a step of sequence.
2018
+ output: The output is a LoDTensor with shape
2019
+ {input.batch_size * output_height * output_width,
2020
+ filter_size_H * filter_size_W * input.channels}.
2021
+ If we regard output as a matrix, each row of this matrix is
2022
+ a step of a sequence.
2015
2023
2016
2024
Examples:
2017
2025
@@ -2041,12 +2049,9 @@ def im2sequence(input,
2041
2049
2042
2050
And:
2043
2051
2044
- block_height = 2
2045
- block_width = 2
2046
- stride_height = 1
2047
- stride_width = 1
2048
- padding_height = 0
2049
- padding_width = 0
2052
+ filter = [2, 2]
2053
+ stride = [1, 1]
2054
+ padding = [0, 0]
2050
2055
2051
2056
Then:
2052
2057
@@ -2063,27 +2068,33 @@ def im2sequence(input,
2063
2068
2064
2069
output.lod = [[0, 4, 8]]
2065
2070
2066
-
2067
-
2068
2071
The simple usage is:
2069
2072
2070
2073
.. code-block:: python
2071
2074
2072
- output = fluid.layers.im2sequence(input=layer, stride_x= 1, stride_y=1, block_x= 2, block_y=2 )
2075
+ output = fluid.layers.im2sequence(input=layer, stride=[ 1, 1], filter=[ 2, 2] )
2073
2076
2074
2077
"""
2078
+
2079
+ if isinstance (filter_size , int ):
2080
+ filter_size = [filter_size , filter_size ]
2081
+ if isinstance (stride , int ):
2082
+ stride = [stride , stride ]
2083
+ if isinstance (padding , int ):
2084
+ padding = [padding , padding ]
2085
+ if len (padding ) == 2 :
2086
+ padding .append (padding [0 ])
2087
+ padding .append (padding [1 ])
2088
+
2075
2089
helper = LayerHelper ('im2sequence' , ** locals ())
2076
2090
out = helper .create_tmp_variable (dtype = helper .input_dtype ())
2077
2091
helper .append_op (
2078
2092
type = 'im2sequence' ,
2079
2093
inputs = {'X' : input },
2080
2094
outputs = {'Out' : out },
2081
2095
attrs = {
2082
- 'block_height' : block_y ,
2083
- 'block_width' : block_x ,
2084
- 'stride_height' : stride_y ,
2085
- 'stride_width' : stride_x ,
2086
- 'padding_height' : padding_y ,
2087
- 'padding_width' : padding_x
2096
+ 'kernels' : filter_size ,
2097
+ 'strides' : stride ,
2098
+ 'paddings' : padding ,
2088
2099
})
2089
2100
return out
0 commit comments