UNPKG

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