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/space_to_batch_nd" />
|
18 | import { Tensor } from '../tensor';
|
19 | import { TensorLike } from '../types';
|
20 | /**
|
21 | * This operation divides "spatial" dimensions `[1, ..., M]` of the input into
|
22 | * a grid of blocks of shape `blockShape`, and interleaves these blocks with
|
23 | * the "batch" dimension (0) such that in the output, the spatial
|
24 | * dimensions `[1, ..., M]` correspond to the position within the grid,
|
25 | * and the batch dimension combines both the position within a spatial block
|
26 | * and the original batch position. Prior to division into blocks,
|
27 | * the spatial dimensions of the input are optionally zero padded
|
28 | * according to `paddings`. See below for a precise description.
|
29 | *
|
30 | * ```js
|
31 | * const x = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]);
|
32 | * const blockShape = [2, 2];
|
33 | * const paddings = [[0, 0], [0, 0]];
|
34 | *
|
35 | * x.spaceToBatchND(blockShape, paddings).print();
|
36 | * ```
|
37 | *
|
38 | * @param x A `tf.Tensor`. N-D with `x.shape` = `[batch] + spatialShape +
|
39 | * remainingShape`, where spatialShape has `M` dimensions.
|
40 | * @param blockShape A 1-D array. Must have shape `[M]`, all values must
|
41 | * be >= 1.
|
42 | * @param paddings A 2-D array. Must have shape `[M, 2]`, all values must be >=
|
43 | * 0. `paddings[i] = [padStart, padEnd]` specifies the amount to zero-pad
|
44 | * from input dimension `i + 1`, which corresponds to spatial dimension `i`. It
|
45 | * is required that
|
46 | * `(inputShape[i + 1] + padStart + padEnd) % blockShape[i] === 0`
|
47 | *
|
48 | * This operation is equivalent to the following steps:
|
49 | *
|
50 | * 1. Zero-pad the start and end of dimensions `[1, ..., M]` of the input
|
51 | * according to `paddings` to produce `padded` of shape paddedShape.
|
52 | *
|
53 | * 2. Reshape `padded` to `reshapedPadded` of shape:
|
54 | * `[batch] + [paddedShape[1] / blockShape[0], blockShape[0], ...,
|
55 | * paddedShape[M] / blockShape[M-1], blockShape[M-1]] + remainingShape`
|
56 | *
|
57 | * 3. Permute dimensions of `reshapedPadded` to produce `permutedReshapedPadded`
|
58 | * of shape: `blockShape + [batch] + [paddedShape[1] / blockShape[0], ...,
|
59 | * paddedShape[M] / blockShape[M-1]] + remainingShape`
|
60 | *
|
61 | * 4. Reshape `permutedReshapedPadded` to flatten `blockShape` into the
|
62 | * batch dimension, producing an output tensor of shape:
|
63 | * `[batch * prod(blockShape)] + [paddedShape[1] / blockShape[0], ...,
|
64 | * paddedShape[M] / blockShape[M-1]] + remainingShape`
|
65 | *
|
66 | * @doc {heading: 'Tensors', subheading: 'Transformations'}
|
67 | */
|
68 | declare function spaceToBatchND_<T extends Tensor>(x: T | TensorLike, blockShape: number[], paddings: number[][]): T;
|
69 | export declare const spaceToBatchND: typeof spaceToBatchND_;
|
70 | export {};
|