batchToSpaceND function

VARP batchToSpaceND(
  1. VARP input,
  2. VARP blockShape,
  3. VARP crops
)

BatchToSpace for N-D variables

This operation reshapes the "batch" dimension 0 into M + 1 dimensions of shape block_shape + batch, interleaves these blocks back into the grid defined by the spatial dimensions 1, ..., M, to obtain a result with the same rank as the input.

The spatial dimensions of this intermediate result are then optionally cropped according to crops to produce the output. This is the reverse of SpaceToBatch. See below for a precise description.

Arguments:

  • input: must be 4-D with NC4HW4 format. N-D with shape input_shape = batch + spatial_shape + remaining_shape, where spatial_shape has M dimensions.
  • block_shape: 1-D with shape M, all values must be >= 1.
  • crops: 2-D with shape M, 2, all values must be >= 0. cropsi = crop_start, crop_end specifies the amount to crop from input dimension i + 1, which corresponds to spatial dimension i. It is required that crop_starti + crop_endi <= block_shapei * input_shapei + 1.

This operation is equivalent to the following steps:

  1. Reshape input to reshaped of shape: [block_shape0, ..., block_shapeM-1, batch / prod(block_shape), input_shape1, ..., input_shapeN-1]
  2. Permute dimensions of reshaped to produce permuted of shape [batch / prod(block_shape),input_shape1, block_shape0, ..., input_shapeM, block_shapeM-1,input_shapeM+1, ..., input_shapeN-1]
  3. Reshape permuted to produce reshaped_permuted of shape [batch / prod(block_shape),input_shape1 * block_shape0, ..., input_shapeM * block_shapeM-1,input_shapeM+1, ..., input_shapeN-1]
  4. Crop the start and end of dimensions 1, ..., M of reshaped_permuted according to crops to produce the output of shape: [batch / prod(block_shape),input_shape1 * block_shape0 - crops0,0 - crops0,1, ..., input_shapeM * block_shapeM-1 - cropsM-1,0 - cropsM-1,1,input_shapeM+1, ..., input_shapeN-1]

Some examples: for the following input of shape 4, 1, 1, 3, block_shape = 2, 2, and crops = [0, 0, 0, 0]:

[[[[1, 2, 3]]], [[[4, 5, 6]]], [[[7, 8, 9]]], [[[10, 11, 12]]]]

The output variable has shape 1, 2, 2, 3 and value:

x = [[[[1, 2, 3], [4, 5, 6]],
      [[7, 8, 9], [10, 11, 12]]]]

Returns:

  • Output: The output variable

Implementation

VARP batchToSpaceND(VARP input, VARP blockShape, VARP crops) =>
    VARP.fromPointer(C.mnn_expr_BatchToSpaceND(input.ptr, crops.ptr, blockShape.ptr));