ReverseSequence¶
Reverses batch of sequences having different lengths specified by sequence_lens
.
Attributes¶
batch_axis
Specify which axis is the batch axis. Default is 1.
sequence_axis
Specify which axis is the sequence axis. Default is 0.
Outputs¶
Y: tensor of type T
.
Data Types¶
T: float16
, float32
, int32
, int64
, int8
, bool
, bfloat16
Shape Information¶
input is a tensor with a shape of \([a_0,...,a_n]\)
sequence_lens is a tensor of shape \([a_{batch_axis}]\)
Y is a tensor of shape \([a_0,...,a_n]\)
Examples¶
ReverseSequence
in1 = network.add_input("input", dtype=trt.float32, shape=(4, 4))
in2 = network.add_input("sequence_lens", dtype=trt.int32, shape=(4,))
layer = network.add_reverse_sequence(in1, in2)
network.mark_output(layer.get_output(0))
inputs[in1.name] = np.array(
[
[0.0, 4.0, 8.0, 12.0],
[1.0, 5.0, 9.0, 13.0],
[2.0, 6.0, 10.0, 14.0],
[3.0, 7.0, 11.0, 15.0]
],
dtype=np.float32,
)
inputs[in2.name] = np.array([4, 3, 2, 1], dtype=np.int32)
outputs[layer.get_output(0).name] = layer.get_output(0).shape
expected[layer.get_output(0).name] = np.array(
[
[3.0, 6.0, 9.0, 12.0],
[2.0, 5.0, 8.0, 13.0],
[1.0, 4.0, 10.0, 14.0],
[0.0, 7.0, 11.0, 15.0]
],
dtype=np.float32,
)
C++ API¶
For more information about the C++ IReverseSequenceLayer operator, refer to the C++ IReverseSequenceLayer documentation.
Python API¶
For more information about the Python IReverseSequenceLayer operator, refer to the Python IReverseSequenceLayer documentation.