|
|
|
@ -128,6 +128,7 @@ __all__ = [
|
|
|
|
|
'prelu_layer',
|
|
|
|
|
'gated_unit_layer',
|
|
|
|
|
'crop_layer',
|
|
|
|
|
'slice_projection',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -536,6 +537,45 @@ def identity_projection(input, offset=None, size=None):
|
|
|
|
|
return proj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def slice_projection(input, slices):
|
|
|
|
|
"""
|
|
|
|
|
slice_projection can get multiple outputs, and each output is a slice
|
|
|
|
|
of the input.
|
|
|
|
|
|
|
|
|
|
.. math::
|
|
|
|
|
output[i] = input.slice(slices[i])
|
|
|
|
|
|
|
|
|
|
The example usage is:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
proj = slice_projection(input=layer, slices=[(0, 10), (20, 30)])
|
|
|
|
|
|
|
|
|
|
Note that slice_projection should not have any parameter.
|
|
|
|
|
|
|
|
|
|
:param input: Input Layer.
|
|
|
|
|
:type input: LayerOutput
|
|
|
|
|
:param slices: An array of slice parameters.
|
|
|
|
|
Each slice contains the start and end offsets based
|
|
|
|
|
on the input.
|
|
|
|
|
:type offset: pair of int
|
|
|
|
|
:return: A SliceProjection object
|
|
|
|
|
:rtype: SliceProjection
|
|
|
|
|
"""
|
|
|
|
|
assert len(slices) >= 1
|
|
|
|
|
start = 0
|
|
|
|
|
for i in xrange(len(slices)):
|
|
|
|
|
assert len(slices[i]) == 2
|
|
|
|
|
# The start position of the next slice needs to be greater than
|
|
|
|
|
# or equal to the end position of the previous slice.
|
|
|
|
|
assert slices[i][0] >= start
|
|
|
|
|
assert slices[i][1] >= slices[i][0]
|
|
|
|
|
start = slices[i][1]
|
|
|
|
|
proj = SliceProjection(input_layer_name=input.name, slices=slices)
|
|
|
|
|
proj.origin = input
|
|
|
|
|
return proj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@wrap_param_attr_default()
|
|
|
|
|
def scaling_projection(input, param_attr=None):
|
|
|
|
|
"""
|
|
|
|
|