mindspore.ops.fold
- mindspore.ops.fold(input, output_size, kernel_size, dilation=1, padding=0, stride=1)[source]
Combines an array of sliding local blocks into a large containing tensor.
Warning
In version 2.0rc1, the input should be a 4-dimensional Tensor whose shape is \((N, C, H, W)\) .
In version 2.0, it must be a 3-dimensional Tensor with shape \((N, C \times H, W)\) .
- Parameters
input (Tensor) – 3-D Tensor, supported dtypes: float16, float32, float64, complex64 and complex128.
output_size (Tensor) – 1D tensor with 2 elements of data type int.
kernel_size (Union[int, tuple[int], list[int]]) – The size of the kernel, should be two int for height and width. If type is int, it means that height equal with width. Must be specified.
dilation (Union[int, tuple[int], list[int]], optional) – The size of the dilation, should be two int for height and width. If type is int, it means that height equal with width. Default: 1.
padding (Union[int, tuple[int], list[int]], optional) – The size of the padding, should be two int for height and width. If type is int, it means that height equal with width. Default: 0.
stride (Union[int, tuple[int], list[int]], optional) – The size of the stride, should be two int for height and width. If type is int, it means that height equal with width. Default: 1.
- Returns
A Tensor, with same type as input , format of the Tensor is (N, C, H, W).
- Raises
TypeError – If kernel_size, dilation, padding, stride data type is not int, tuple or list.
ValueError – If kernel_size, dilation, stride value is not greater than zero or elements number more than 2.
ValueError – If padding value is less than zero or elements number more than 2.
ValueError – If input.shape[2] != kernel_size[0] * kernel_size[1].
ValueError – If input.shape[3] does not match the calculated number of sliding blocks.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> x = Tensor(input_data=np.random.rand(16, 64, 25), dtype=mstype.float32) >>> output_size = Tensor(input_data=[8, 8], dtype=mstype.int32) >>> output = ops.fold(x, output_size, [2, 2], [2, 2], [2, 2], [2, 2]) >>> print(output.shape) (16, 16, 8, 8)