Files
openvino/docs/ops/movement/BatchToSpace_2.md
Maciej Smyk 49b5d039db DOCS shift to rst - Opsets B (#17169)
* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_1.md

* Update BatchNormInference_5.md

* Update BatchToSpace_2.md

* Update BinaryConvolution_1.md

* Update Broadcast_1.md

* Update Broadcast_3.md

* Update Bucketize_3.md

* fix

* fix-2
2023-04-25 16:06:17 +02:00

6.6 KiB

BatchToSpace

@sphinxdirective

Versioned name: BatchToSpace-2

Category: Data movement

Short description: BatchToSpace operation permutes the batch dimension on a given input data into blocks in the spatial dimensions specified by block_shape input. The spatial dimensions are then optionally cropped according to crops_begin and crops_end inputs to produce the output.

Detailed description

BatchToSpace operation is equivalent to the following operation steps on the input data with shape [batch, D_1, D_2, ..., D_{N-1}] and block_shape, crops_begin, crops_end inputs with shape [N] to produce the output tensor :math:y.

  1. Reshape data input to produce a tensor of shape :math:[B_1, \dots, B_{N - 1}, \frac{batch}{\left(B_1 \times \dots \times B_{N - 1}\right)}, D_1, D_2, \dots, D_{N - 1}]

.. math::

x^{\prime} = reshape(data, [B_1, \dots, B_{N - 1}, \frac{batch}{\left(B_1 \times \dots \times B_{N - 1}\right)}, D_1, D_2, \dots, D_{N - 1}])

  1. Permute dimensions of :math:x^{\prime} to produce a tensor of shape :math:[\frac{batch}{\left(B_1 \times \dots \times B_{N - 1}\right)}, D_1, B_1, D_2, B_2, \dots, D_{N-1}, B_{N - 1}]

.. math::

x^{\prime\prime} = transpose(x', [N, N + 1, 0, N + 2, 1, \dots, N + N - 1, N - 1])

  1. Reshape :math:x^{\prime\prime} to produce a tensor of shape :math:[\frac{batch}{\left(B_1 \times \dots \times B_{N - 1}\right)}, D_1 \times B_1, D_2 \times B_2, \dots, D_{N - 1} \times B_{N - 1}]

.. math::

x^{\prime\prime\prime} = reshape(x^{\prime\prime}, [\frac{batch}{\left(B_1 \times \dots \times B_{N - 1}\right)}, D_1 \times B_1, D_2 \times B_2, \dots, D_{N - 1} \times B_{N - 1}])

  1. Crop the start and end of spatial dimensions of :math:x^{\prime\prime\prime} according to crops_begin and crops_end inputs to produce the output :math:y of shape:

.. math::

\left[\frac{batch}{\left(B_1 \times \dots \times B_{N - 1}\right)}, crop(D_1 \times B_1, CB_1, CE_1), crop(D_2 \times B_2, CB_2, CE_2), \dots , crop(D_{N - 1} \times B_{N - 1}, CB_{N - 1}, CE_{N - 1})\right]

Where

  • :math:B_i = block_shape[i]
  • :math:B_0 is expected to be 1
  • :math:CB_i = crops_begin[i]
  • :math:CE_i = crops_end[i]
  • :math:CB_0 and :math:CE_0 are expected to be 0
  • :math:CB_i + CE_i \leq D_i \times B_i

BatchToSpace operation is the reverse of SpaceToBatch operation.

Attributes: BatchToSpace operation has no attributes.

Inputs

  • 1: data - A tensor of type T and rank greater than or equal to 2. Layout is [batch, D_1, D_2 ... D_{N-1}] (number of batches, spatial axes). Required.
  • 2: block_shape - Specifies the block sizes of batch axis of data input which are moved to the corresponding spatial axes. A 1D tensor of type T_INT and shape [N]. All element values must be greater than or equal to 1. block_shape[0] is expected to be 1. Required.
  • 3: crops_begin - Specifies the amount to crop from the beginning along each axis of data input. A 1D tensor of type T_INT and shape [N]. All element values must be greater than or equal to 0. crops_begin[0] is expected to be 0. Required.
  • 4: crops_end - Specifies the amount to crop from the ending along each axis of data input. A 1D tensor of type T_INT and shape [N]. All element values must be greater than or equal to 0. crops_end[0] is expected to be 0. Required.
  • Note: N corresponds to the rank of data input.
  • Note: batch axis of data input must be evenly divisible by the cumulative product of block_shape elements.
  • Note: It is required that crops_begin[i] + crops_end[i] <= block_shape[i] \* input_shape[i].

Outputs

  • 1: Permuted tensor of type T with the same rank as data input tensor, and shape [batch / (block_shape[0] \* block_shape[1] \* ... \* block_shape[N - 1]), D_1 \* block_shape[1] - crops_begin[1] - crops_end[1], D_2 \* block_shape[2] - crops_begin[2] - crops_end[2], ..., D_{N - 1} \* block_shape[N - 1] - crops_begin[N - 1] - crops_end[N - 1].

Types

  • T: any supported type.
  • T_INT: any supported integer type.

Examples

Example: 2D input tensor data

.. code-block:: cpp

<layer type="BatchToSpace" ...> < !-- data --> 10 < !-- batch --> 2 < !-- spatial dimension 1 --> < !-- block_shape value: [1, 5] --> 2 < !-- crops_begin value: [0, 2] --> 2 < !-- crops_end value: [0, 0] --> 2 2 < !-- data.shape[0] / (block_shape.shape[0] * block_shape.shape[1]) --> 8 < !-- data.shape[1] * block_shape.shape[1] - crops_begin[1] - crops_end[1]-->

Example: 5D input tensor data

.. code-block:: cpp

<layer type="BatchToSpace" ...> < !-- data --> 48 < !-- batch --> 3 < !-- spatial dimension 1 --> 3 < !-- spatial dimension 2 --> 1 < !-- spatial dimension 3 --> 3 < !-- spatial dimension 4 --> < !-- block_shape value: [1, 2, 4, 3, 1] --> 5 < !-- crops_begin value: [0, 0, 1, 0, 0] --> 5 < !-- crops_end value: [0, 0, 1, 0, 0] --> 5 2 < !-- data.shape[0] / (block_shape.shape[0] * block_shape.shape[1] * ... * block_shape.shape[4]) --> 6 < !-- data.shape[1] * block_shape.shape[1] - crops_begin[1] - crops_end[1]--> 10 < !-- data.shape[2] * block_shape.shape[2] - crops_begin[2] - crops_end[2] --> 3 < !-- data.shape[3] * block_shape.shape[3] - crops_begin[3] - crops_end[3] --> 3 < !-- data.shape[4] * block_shape.shape[4] - crops_begin[4] - crops_end[4] -->

@endsphinxdirective