|
|
|
@ -29,79 +29,22 @@ from .. import unique_name
|
|
|
|
|
from functools import reduce
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
|
'fc',
|
|
|
|
|
'embedding',
|
|
|
|
|
'dynamic_lstm',
|
|
|
|
|
'dynamic_lstmp',
|
|
|
|
|
'dynamic_gru',
|
|
|
|
|
'gru_unit',
|
|
|
|
|
'linear_chain_crf',
|
|
|
|
|
'crf_decoding',
|
|
|
|
|
'cos_sim',
|
|
|
|
|
'cross_entropy',
|
|
|
|
|
'square_error_cost',
|
|
|
|
|
'chunk_eval',
|
|
|
|
|
'sequence_conv',
|
|
|
|
|
'conv2d',
|
|
|
|
|
'conv3d',
|
|
|
|
|
'sequence_pool',
|
|
|
|
|
'sequence_softmax',
|
|
|
|
|
'softmax',
|
|
|
|
|
'pool2d',
|
|
|
|
|
'pool3d',
|
|
|
|
|
'batch_norm',
|
|
|
|
|
'beam_search_decode',
|
|
|
|
|
'conv2d_transpose',
|
|
|
|
|
'conv3d_transpose',
|
|
|
|
|
'sequence_expand',
|
|
|
|
|
'lstm_unit',
|
|
|
|
|
'reduce_sum',
|
|
|
|
|
'reduce_mean',
|
|
|
|
|
'reduce_max',
|
|
|
|
|
'reduce_min',
|
|
|
|
|
'reduce_prod',
|
|
|
|
|
'sequence_first_step',
|
|
|
|
|
'sequence_last_step',
|
|
|
|
|
'dropout',
|
|
|
|
|
'split',
|
|
|
|
|
'ctc_greedy_decoder',
|
|
|
|
|
'edit_distance',
|
|
|
|
|
'l2_normalize',
|
|
|
|
|
'matmul',
|
|
|
|
|
'topk',
|
|
|
|
|
'warpctc',
|
|
|
|
|
'sequence_reshape',
|
|
|
|
|
'transpose',
|
|
|
|
|
'im2sequence',
|
|
|
|
|
'nce',
|
|
|
|
|
'hsigmoid',
|
|
|
|
|
'beam_search',
|
|
|
|
|
'row_conv',
|
|
|
|
|
'multiplex',
|
|
|
|
|
'layer_norm',
|
|
|
|
|
'softmax_with_cross_entropy',
|
|
|
|
|
'smooth_l1',
|
|
|
|
|
'one_hot',
|
|
|
|
|
'autoincreased_step_counter',
|
|
|
|
|
'reshape',
|
|
|
|
|
'lod_reset',
|
|
|
|
|
'lrn',
|
|
|
|
|
'pad',
|
|
|
|
|
'label_smooth',
|
|
|
|
|
'roi_pool',
|
|
|
|
|
'dice_loss',
|
|
|
|
|
'image_resize',
|
|
|
|
|
'image_resize_short',
|
|
|
|
|
'resize_bilinear',
|
|
|
|
|
'gather',
|
|
|
|
|
'random_crop',
|
|
|
|
|
'mean_iou',
|
|
|
|
|
'relu',
|
|
|
|
|
'log',
|
|
|
|
|
'crop',
|
|
|
|
|
'rank_loss',
|
|
|
|
|
'prelu',
|
|
|
|
|
'flatten',
|
|
|
|
|
'fc', 'embedding', 'dynamic_lstm', 'dynamic_lstmp', 'dynamic_gru',
|
|
|
|
|
'gru_unit', 'linear_chain_crf', 'crf_decoding', 'cos_sim', 'cross_entropy',
|
|
|
|
|
'square_error_cost', 'chunk_eval', 'sequence_conv', 'conv2d', 'conv3d',
|
|
|
|
|
'sequence_pool', 'sequence_softmax', 'softmax', 'pool2d', 'pool3d',
|
|
|
|
|
'batch_norm', 'beam_search_decode', 'conv2d_transpose', 'conv3d_transpose',
|
|
|
|
|
'sequence_expand', 'lstm_unit', 'reduce_sum', 'reduce_mean', 'reduce_max',
|
|
|
|
|
'reduce_min', 'reduce_prod', 'sequence_first_step', 'sequence_last_step',
|
|
|
|
|
'dropout', 'split', 'ctc_greedy_decoder', 'edit_distance', 'l2_normalize',
|
|
|
|
|
'matmul', 'topk', 'warpctc', 'sequence_reshape', 'transpose', 'im2sequence',
|
|
|
|
|
'nce', 'hsigmoid', 'beam_search', 'row_conv', 'multiplex', 'layer_norm',
|
|
|
|
|
'softmax_with_cross_entropy', 'smooth_l1', 'one_hot',
|
|
|
|
|
'autoincreased_step_counter', 'reshape', 'lod_reset', 'lrn', 'pad',
|
|
|
|
|
'label_smooth', 'roi_pool', 'dice_loss', 'image_resize',
|
|
|
|
|
'image_resize_short', 'resize_bilinear', 'gather', 'random_crop',
|
|
|
|
|
'mean_iou', 'relu', 'log', 'crop', 'rank_loss', 'prelu', 'flatten',
|
|
|
|
|
'sequence_enumerate'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -5475,3 +5418,50 @@ def flatten(x, axis=1, name=None):
|
|
|
|
|
outputs={'Out': out},
|
|
|
|
|
attrs={"axis": axis})
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sequence_enumerate(input, win_size, pad_value, name=None):
|
|
|
|
|
"""
|
|
|
|
|
Generate a new LoDTensor
|
|
|
|
|
with the same 1st dimension length as the original LoDTensor,
|
|
|
|
|
and with the 2nd dimension equal to the input window length,
|
|
|
|
|
the new sub-sequence on 2nd dimension is enumerated one by one on the original sequence.
|
|
|
|
|
The values of the last insufficient part areall filled with the input pad_value.
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
Case 1:
|
|
|
|
|
Input:
|
|
|
|
|
X.lod = [[0, 3, 5]]
|
|
|
|
|
X.data = [1, 2, 3, 4, 5]
|
|
|
|
|
X.dims = [5, 1]
|
|
|
|
|
Attrs:
|
|
|
|
|
win_size = 2
|
|
|
|
|
pad_value = 0
|
|
|
|
|
Output:
|
|
|
|
|
Out.lod = [[0, 3, 5]]
|
|
|
|
|
Out.data = [[1, 2], [2, 3], [3, 4], [4, 5], [0, 0]]
|
|
|
|
|
Out.dims = [5, 2]
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
input (Variable): The input variable which is a LoDTensor
|
|
|
|
|
win_size (int): The enumerate sequence window size.
|
|
|
|
|
pad_value (int): The enumerate sequence padding value.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Variable: The enumerate sequence variable which is a LoDTensor.
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
x = fluid.layers.data(shape[30, 1], dtype='int32', lod_level=1)
|
|
|
|
|
out = fluid.layers.sequence_enumerate(input=x, win_size=3, pad_value=0)
|
|
|
|
|
"""
|
|
|
|
|
helper = LayerHelper('sequence_enumerate', **locals())
|
|
|
|
|
out = helper.create_tmp_variable(helper.input_dtype())
|
|
|
|
|
helper.append_op(
|
|
|
|
|
type='sequence_enumerate',
|
|
|
|
|
inputs={'X': input},
|
|
|
|
|
outputs={'Out': out},
|
|
|
|
|
attrs={'win_size': win_size,
|
|
|
|
|
'pad_value': pad_value})
|
|
|
|
|
return out
|
|
|
|
|