# temporal_shift¶

`paddle.fluid.layers.``temporal_shift`(x, seg_num, shift_ratio=0.25, name=None)[source]

Temporal Shift Operator

This operator calculates the temporal shifting features for Input(X).

Input(X) should be in shape of [N*T, C, H, W], while N is the batch size, T is the temporal segment number specified by `seg_num`, C is the channel number, H and W is the height and width of features.

Temporal Shifting is calculated as follows:

Step 1: Reshape Input(X) to [N, T, C, H, W].

Step 2: Pad 0 to reshaping result in the 2nd(T) dimension with padding width as 1 on each side, padding result will be in shape of [N, T+2, C, H, W].

Step 3: Assume `shift_ratio` is \(1/4\), slice padding result as follows:

\$\$ slice1 = x[:, :T, :C/4, :, :] \$\$ \$\$ slice2 = x[:, 2:T+2, C/4:C/2, :, :] \$\$ \$\$ slice3 = x[:, 1:T+1, C/2:, :, :] \$\$

Step 4: Concatenate three slices along the 3rd(C) dimension and reshape result to [N*T, C, H, W].

For details of temporal shifting, please refer to paper: Temporal Shift Module .

Parameters
• x (Variable) – The input tensor of temporal shift operator. This is a 4-D tensor with shape of [N*T, C, H, W]. While N is the batch size, T is the temporal segment number, C is the channel number, H is the height of features and W is the width of features. The data type is float32 and float64

• seg_num (int) – The temporal segment number, this should be a positive integer

• shift_ratio (float) – The shift ratio of the channels, the first `shift_ratio` part of channels will be shifted by -1 along the temporal dimension, and the second `shift_ratio` part of channels will be shifted by 1 along the temporal dimension. `shift_ratio` should be in range [0, 0.5]. Default 0.25

• name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.

Returns

The temporal shifting result is a tensor variable with the same shape and same data type as the input.

Return type

out(Variable)

Raises

`TypeError` – seg_num must be int type.

Examples

```import paddle.fluid as fluid
input = fluid.data(name='input', shape=[None,4,2,2], dtype='float32')
out = fluid.layers.temporal_shift(x=input, seg_num=2, shift_ratio=0.2)
```