UNPKG

3.24 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 */
17/// <amd-module name="@tensorflow/tfjs-core/dist/ops/batch_to_space_nd" />
18import { Tensor } from '../tensor';
19import { TensorLike } from '../types';
20/**
21 * This operation reshapes the "batch" dimension 0 into `M + 1` dimensions of
22 * shape `blockShape + [batch]`, interleaves these blocks back into the grid
23 * defined by the spatial dimensions `[1, ..., M]`, to obtain a result with
24 * the same rank as the input. The spatial dimensions of this intermediate
25 * result are then optionally cropped according to `crops` to produce the
26 * output. This is the reverse of `tf.spaceToBatchND`. See below for a precise
27 * description.
28 *
29 * ```js
30 * const x = tf.tensor4d([1, 2, 3, 4], [4, 1, 1, 1]);
31 * const blockShape = [2, 2];
32 * const crops = [[0, 0], [0, 0]];
33 *
34 * x.batchToSpaceND(blockShape, crops).print();
35 * ```
36 *
37 * @param x A `tf.Tensor`. N-D with `x.shape` = `[batch] + spatialShape +
38 * remainingShape`, where spatialShape has `M` dimensions.
39 * @param blockShape A 1-D array. Must have shape `[M]`, all values must
40 * be >= 1.
41 * @param crops A 2-D array. Must have shape `[M, 2]`, all values must be >= 0.
42 * `crops[i] = [cropStart, cropEnd]` specifies the amount to crop from input
43 * dimension `i + 1`, which corresponds to spatial dimension `i`. It is required
44 * that `cropStart[i] + cropEnd[i] <= blockShape[i] * inputShape[i + 1]`
45 *
46 * This operation is equivalent to the following steps:
47 *
48 * 1. Reshape `x` to `reshaped` of shape: `[blockShape[0], ...,
49 * blockShape[M-1], batch / prod(blockShape), x.shape[1], ...,
50 * x.shape[N-1]]`
51 *
52 * 2. Permute dimensions of `reshaped`to produce `permuted` of shape `[batch /
53 * prod(blockShape),x.shape[1], blockShape[0], ..., x.shape[M],
54 * blockShape[M-1],x.shape[M+1], ..., x.shape[N-1]]`
55 *
56 * 3. Reshape `permuted` to produce `reshapedPermuted` of shape `[batch /
57 * prod(blockShape),x.shape[1] * blockShape[0], ..., x.shape[M] *
58 * blockShape[M-1],x.shape[M+1], ..., x.shape[N-1]]`
59 *
60 * 4. Crop the start and end of dimensions `[1, ..., M]` of `reshapedPermuted`
61 * according to `crops` to produce the output of shape: `[batch /
62 * prod(blockShape),x.shape[1] * blockShape[0] - crops[0,0] - crops[0,1],
63 * ..., x.shape[M] * blockShape[M-1] - crops[M-1,0] -
64 * crops[M-1,1],x.shape[M+1], ..., x.shape[N-1]]`
65 *
66 * @doc {heading: 'Tensors', subheading: 'Transformations'}
67 */
68declare function batchToSpaceND_<T extends Tensor>(x: T | TensorLike, blockShape: number[], crops: number[][]): T;
69export declare const batchToSpaceND: typeof batchToSpaceND_;
70export {};