Transposes the batch and time dimensions of a Tensor. If the input tensor has rank < 2 it returns the original tensor. Retains as much of the static shape information as possible. Args: x: A Tensor. Returns: x transposed along the first two dimensions.
(x)
| 41 | |
| 42 | |
| 43 | def _transpose_batch_time(x): |
| 44 | """Transposes the batch and time dimensions of a Tensor. |
| 45 | |
| 46 | If the input tensor has rank < 2 it returns the original tensor. Retains as |
| 47 | much of the static shape information as possible. |
| 48 | |
| 49 | Args: |
| 50 | x: A Tensor. |
| 51 | |
| 52 | Returns: |
| 53 | x transposed along the first two dimensions. |
| 54 | """ |
| 55 | x_static_shape = x.get_shape() |
| 56 | if x_static_shape.rank is not None and x_static_shape.rank < 2: |
| 57 | return x |
| 58 | |
| 59 | x_rank = array_ops.rank(x) |
| 60 | x_t = array_ops.transpose( |
| 61 | x, array_ops.concat(([1, 0], math_ops.range(2, x_rank)), axis=0)) |
| 62 | x_t.set_shape( |
| 63 | tensor_shape.TensorShape( |
| 64 | [x_static_shape.dims[1].value, |
| 65 | x_static_shape.dims[0].value]).concatenate(x_static_shape[2:])) |
| 66 | return x_t |
| 67 | |
| 68 | |
| 69 | def _best_effort_input_batch_size(flat_input): |