FilesLast commitLast update
13 days ago
2 months ago
13 days ago
5 days ago
2 months ago
5 days ago
22 days ago
10 days ago
5 days ago
README

BatchToSpace

English | 简体中文

Product Support Status

Product Supported
Ascend 950PR&950DT products √
Atlas A3 products √
Atlas A2 products √
Atlas 200I/500 A2 inference products √
Atlas inference products √
Atlas training products √

Function Description

  • Operator function: rearranges data from the batch dimension into spatial dimensions and crops the spatial dimensions.

  • Function description: This operator is the inverse operation of SpaceToBatch. The input is a 4D NHWC tensor [N * bs * bs, H_in, W_in, C], and the output is a 4D NHWC tensor [N, H_out, W_out, C]. The operator restores the bs × bs spatial blocks folded in the input batch dimension to the H and W dimensions, and crops the spatial boundaries through the crops parameter.

  • Computation formula: Assume that the input x is a 4D NHWC tensor [N_in, H_in, W_in, C], block_size = bs, and crops = [[crop_top, crop_bottom], [crop_left, crop_right]].

    N_out = N_in / (bs × bs), H_out = H_in × bs - crop_top - crop_bottom, and W_out = W_in × bs - crop_left - crop_right.

    N_in must be integer-divisible by bs × bs, and the cropped H_out and W_out must be greater than 0.

    The output y has the shape [N_out, H_out, W_out, C].

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
x Input Input tensor, a 4D NHWC tensor [N*bs*bs, H_in, W_in, C], supporting multiple data types FLOAT, FLOAT16, BFLOAT16, INT8, INT16, INT32, UINT8, UINT16, INT64, DOUBLE ND
crops Input Cropping amounts of spatial dimensions, a 2D tensor with shape [2, 2] and values [[crop_top, crop_bottom], [crop_left, crop_right]] INT32, INT64 ND
block_size Attribute Size of the spatial block, which must be an integer greater than 0. N_in must be integer-divisible by block_size × block_size INT -
y Output Output tensor, with the same data type as the input x. The output shape is [N_out, H_out, W_out, C] Same as x ND

Constraint Description

  • The input tensor x must be a 4D tensor (logical layout NHWC, storage format ND), with shape [N * bs * bs, H_in, W_in, C].
  • block_size must be greater than 0.
  • The input batch dimension N_in must be integer-divisible by block_size × block_size.
  • crops has the shape [2, 2], and each element must be >= 0.
  • The spatial dimensions after cropping cannot be negative: H_in × block_size - crop_top - crop_bottom >= 0 and W_in × block_size - crop_left - crop_right >= 0 (a value of 0 indicates that the output of the spatial dimension is an empty tensor).

Invocation Description

Invocation Method Sample Code Description
Graph mode test_geir_batch_to_space Invokes the BatchToSpace operator by building a graph through the operator IR.