UNPKG

2.44 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2020 Google LLC. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * =============================================================================
16 */
17import { Tensor4D } from '../tensor';
18import { TensorLike4D } from '../types';
19/**
20 * Rearranges data from depth into blocks of spatial data. More specifically,
21 * this op outputs a copy of the input tensor where values from the `depth`
22 * dimension are moved in spatial blocks to the `height` and `width` dimensions.
23 * The attr `blockSize` indicates the input block size and how the data is
24 * moved.
25 *
26 * - Chunks of data of size `blockSize * blockSize` from depth are rearranged
27 * into non-overlapping blocks of size `blockSize x blockSize`
28 *
29 * - The width the output tensor is `inputWidth * blockSize`, whereas the
30 * height is `inputHeight * blockSize`
31 *
32 * - The Y, X coordinates within each block of the output image are determined
33 * by the high order component of the input channel index
34 *
35 * - The depth of the input tensor must be divisible by `blockSize *
36 * blockSize`
37 *
38 * The `dataFormat` attr specifies the layout of the input and output tensors
39 * with the following options: "NHWC": [ `batch, height, width, channels` ]
40 * "NCHW": [ `batch, channels, height, width` ]
41 *
42 * ```js
43 * const x = tf.tensor4d([1, 2, 3, 4], [1, 1, 1, 4]);
44 * const blockSize = 2;
45 * const dataFormat = "NHWC";
46 *
47 * tf.depthToSpace(x, blockSize, dataFormat).print();
48 * ```
49 *
50 * @param x The input tensor of rank 4
51 * @param blockSIze An `int` that is `>= 2`. The size of the spatial block
52 * @param dataFormat An optional string from: "NHWC", "NCHW". Defaults to "NHWC"
53 *
54 * @doc {heading: 'Tensors', subheading: 'Transformations'}
55 */
56declare function depthToSpace_(x: Tensor4D | TensorLike4D, blockSize: number, dataFormat?: 'NHWC' | 'NCHW'): Tensor4D;
57export declare const depthToSpace: typeof depthToSpace_;
58export {};