UNPKG

@tensorflow-models/coco-ssd

Version:

Object detection model (coco-ssd) in TensorFlow.js

252 lines (251 loc) 14.8 kB
/** * @license * Copyright 2018 Google Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ import { Tensor2D, Tensor3D, Tensor4D, Tensor5D } from '../tensor'; import { TensorLike } from '../types'; /** * Computes a 1D convolution over the input x. * * @param x The input tensor, of rank 3 or rank 2, of shape * `[batch, width, inChannels]`. If rank 2, batch of 1 is assumed. * @param filter The filter, rank 3, of shape * `[filterWidth, inDepth, outDepth]`. * @param stride The number of entries by which the filter is moved right at * each step. * @param pad The type of padding algorithm. * - `same` and stride 1: output will be of same size as input, * regardless of filter size. * - `valid`: output will be smaller than input if filter is larger * than 1x1. * - For more info, see this guide: * [https://www.tensorflow.org/api_guides/python/nn#Convolution]( * https://www.tensorflow.org/api_guides/python/nn#Convolution) * @param dataFormat An optional string from "NWC", "NCW". Defaults to "NWC", * the data is stored in the order of [batch, in_width, in_channels]. Only * "NWC" is currently supported. * @param dilation The dilation rate in which we sample input values in * atrous convolution. Defaults to `1`. If it is greater than 1, then * stride must be `1`. * @param dimRoundingMode The rounding mode used when computing output * dimensions if pad is a number. If none is provided, it will not round * and error if the output is of fractional size. */ /** @doc {heading: 'Operations', subheading: 'Convolution'} */ declare function conv1d_<T extends Tensor2D | Tensor3D>(x: T | TensorLike, filter: Tensor3D | TensorLike, stride: number, pad: 'valid' | 'same' | number, dataFormat?: 'NWC' | 'NCW', dilation?: number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T; /** * Computes a 2D convolution over the input x. * * @param x The input tensor, of rank 4 or rank 3, of shape * `[batch, height, width, inChannels]`. If rank 3, batch of 1 is * assumed. * @param filter The filter, rank 4, of shape * `[filterHeight, filterWidth, inDepth, outDepth]`. * @param strides The strides of the convolution: `[strideHeight, * strideWidth]`. * @param pad The type of padding algorithm. * - `same` and stride 1: output will be of same size as input, * regardless of filter size. * - `valid`: output will be smaller than input if filter is larger * than 1x1. * - For more info, see this guide: * [https://www.tensorflow.org/api_guides/python/nn#Convolution]( * https://www.tensorflow.org/api_guides/python/nn#Convolution) * @param dataFormat: An optional string from: "NHWC", "NCHW". Defaults to * "NHWC". Specify the data format of the input and output data. With the * default format "NHWC", the data is stored in the order of: [batch, * height, width, channels]. Only "NHWC" is currently supported. * @param dilations The dilation rates: `[dilationHeight, dilationWidth]` * in which we sample input values across the height and width dimensions * in atrous convolution. Defaults to `[1, 1]`. If `dilations` is a single * number, then `dilationHeight == dilationWidth`. If it is greater than * 1, then all values of `strides` must be 1. * @param dimRoundingMode The rounding mode used when computing output * dimensions if pad is a number. If none is provided, it will not round * and error if the output is of fractional size. */ /** @doc {heading: 'Operations', subheading: 'Convolution'} */ declare function conv2d_<T extends Tensor3D | Tensor4D>(x: T | TensorLike, filter: Tensor4D | TensorLike, strides: [number, number] | number, pad: 'valid' | 'same' | number, dataFormat?: 'NHWC' | 'NCHW', dilations?: [number, number] | number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T; /** * Computes the derivative of the filter of a 2D convolution. * * @param x The input tensor, of rank 4 or rank 3 of shape * [batch, height, width, inChannels]. If rank 3, batch of 1 is assumed. * @param dy The dy image, of rank 4 or rank 3, of shape * [batch, height, width, outDepth]. If rank 3, batch of 1 is assumed. * @param filterShape The shape of the filter, length 4, * [filterHeight, filterWidth, inDepth, outDepth]. * @param strides The strides of the convolution: [strideHeight, * strideWidth]. * @param pad A string from: 'same', 'valid'. The type of padding algorithm * used in the forward prop of the op. * @param dimRoundingMode A string from: 'ceil', 'round', 'floor'. The * rounding mode used when computing output dimensions if pad is a * number. If none is provided, it will not round and error if the output * is of fractional size. */ declare function conv2dDerFilter_<T extends Tensor3D | Tensor4D>(x: T, dy: T, filterShape: [number, number, number, number], strides: [number, number] | number, pad: 'valid' | 'same' | number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): Tensor4D; /** * Computes the transposed 2D convolution of an image, also known as a * deconvolution. * * @param x The input image, of rank 4 or rank 3, of shape * `[batch, height, width, inDepth]`. If rank 3, batch of 1 is assumed. * @param filter The filter, rank 4, of shape * `[filterHeight, filterWidth, outDepth, inDepth]`. * `inDepth` must match `inDepth` in `x`. * @param outputShape Output shape, of rank 4 or rank 3: * `[batch, height, width, outDepth]`. If rank 3, batch of 1 is assumed. * @param strides The strides of the original convolution: * `[strideHeight, strideWidth]`. * @param pad The type of padding algorithm used in the non-transpose version * of the op. * @param dimRoundingMode The rounding mode used when computing output * dimensions if pad is a number. If none is provided, it will not round * and error if the output is of fractional size. */ /** @doc {heading: 'Operations', subheading: 'Convolution'} */ declare function conv2dTranspose_<T extends Tensor3D | Tensor4D>(x: T | TensorLike, filter: Tensor4D | TensorLike, outputShape: [number, number, number, number] | [number, number, number], strides: [number, number] | number, pad: 'valid' | 'same' | number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T; /** * Depthwise 2D convolution. * * Given a 4D `input` array and a `filter` array of shape * `[filterHeight, filterWidth, inChannels, channelMultiplier]` containing * `inChannels` convolutional filters of depth 1, this op applies a * different filter to each input channel (expanding from 1 channel to * `channelMultiplier` channels for each), then concatenates the results * together. The output has `inChannels * channelMultiplier` channels. * * See * [https://www.tensorflow.org/api_docs/python/tf/nn/depthwise_conv2d]( * https://www.tensorflow.org/api_docs/python/tf/nn/depthwise_conv2d) * for more details. * * @param x The input tensor, of rank 4 or rank 3, of shape * `[batch, height, width, inChannels]`. If rank 3, batch of 1 is * assumed. * @param filter The filter tensor, rank 4, of shape * `[filterHeight, filterWidth, inChannels, channelMultiplier]`. * @param strides The strides of the convolution: `[strideHeight, * strideWidth]`. If strides is a single number, then `strideHeight == * strideWidth`. * @param pad The type of padding algorithm. * - `same` and stride 1: output will be of same size as input, * regardless of filter size. * - `valid`: output will be smaller than input if filter is larger * than 1x1. * - For more info, see this guide: * [https://www.tensorflow.org/api_guides/python/nn#Convolution]( * https://www.tensorflow.org/api_guides/python/nn#Convolution) * @param dilations The dilation rates: `[dilationHeight, dilationWidth]` * in which we sample input values across the height and width dimensions * in atrous convolution. Defaults to `[1, 1]`. If `rate` is a single * number, then `dilationHeight == dilationWidth`. If it is greater than * 1, then all values of `strides` must be 1. * @param dataFormat: An optional string from: "NHWC", "NCHW". Defaults to * "NHWC". Specify the data format of the input and output data. With the * default format "NHWC", the data is stored in the order of: [batch, * height, width, channels]. Only "NHWC" is currently supported. * @param dimRoundingMode The rounding mode used when computing output * dimensions if pad is a number. If none is provided, it will not round * and error if the output is of fractional size. */ /** @doc {heading: 'Operations', subheading: 'Convolution'} */ declare function depthwiseConv2d_<T extends Tensor3D | Tensor4D>(x: T | TensorLike, filter: Tensor4D | TensorLike, strides: [number, number] | number, pad: 'valid' | 'same' | number, dataFormat?: 'NHWC' | 'NCHW', dilations?: [number, number] | number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T; /** * 2-D convolution with separable filters. * * Performs a depthwise convolution that acts separately on channels followed * by a pointwise convolution that mixes channels. Note that this is * separability between dimensions [1, 2] and 3, not spatial separability * between dimensions 1 and 2. * * See * [https://www.tensorflow.org/api_docs/python/tf/nn/separable_conv2d]( * https://www.tensorflow.org/api_docs/python/tf/nn/separable_conv2d) * for more details. * * @param x The input tensor, of rank 4 or rank 3, of shape * `[batch, height, width, inChannels]`. If rank 3, batch of 1 is * assumed. * @param depthwiseFilter The depthwise filter tensor, rank 4, of shape * `[filterHeight, filterWidth, inChannels, channelMultiplier]`. This is * the filter used in the first step. * @param pointwiseFilter The pointwise filter tensor, rank 4, of shape * `[1, 1, inChannels * channelMultiplier, outChannels]`. This is * the filter used in the second step. * @param strides The strides of the convolution: `[strideHeight, * strideWidth]`. If strides is a single number, then `strideHeight == * strideWidth`. * @param pad The type of padding algorithm. * - `same` and stride 1: output will be of same size as input, * regardless of filter size. * - `valid`: output will be smaller than input if filter is larger * than 1x1. * - For more info, see this guide: * [https://www.tensorflow.org/api_guides/python/nn#Convolution]( * https://www.tensorflow.org/api_guides/python/nn#Convolution) * @param dilations The dilation rates: `[dilationHeight, dilationWidth]` * in which we sample input values across the height and width dimensions * in atrous convolution. Defaults to `[1, 1]`. If `rate` is a single * number, then `dilationHeight == dilationWidth`. If it is greater than * 1, then all values of `strides` must be 1. * @param dataFormat: An optional string from: "NHWC", "NCHW". Defaults to * "NHWC". Specify the data format of the input and output data. With the * default format "NHWC", the data is stored in the order of: [batch, * height, width, channels]. Only "NHWC" is currently supported. */ /** @doc {heading: 'Operations', subheading: 'Convolution'} */ declare function separableConv2d_<T extends Tensor3D | Tensor4D>(x: T | TensorLike, depthwiseFilter: Tensor4D | TensorLike, pointwiseFilter: Tensor4D | TensorLike, strides: [number, number] | number, pad: 'valid' | 'same', dilation?: [number, number] | number, dataFormat?: 'NHWC' | 'NCHW'): T; /** * Computes a 3D convolution over the input x. * * @param x The input tensor, of rank 5 or rank 4, of shape * `[batch, depth, height, width, channels]`. If rank 4, * batch of 1 is assumed. * @param filter The filter, rank 5, of shape * `[filterDepth, filterHeight, filterWidth, inChannels, outChannels]`. * inChannels must match between input and filter. * @param strides The strides of the convolution: `[strideDepth, strideHeight, * strideWidth]`. * @param pad The type of padding algorithm. * - `same` and stride 1: output will be of same size as input, * regardless of filter size. * - `valid`: output will be smaller than input if filter is larger * than 1x1. * - For more info, see this guide: * [https://www.tensorflow.org/api_guides/python/nn#Convolution]( * https://www.tensorflow.org/api_guides/python/nn#Convolution) * @param dataFormat: An optional string from: "NHWC", "NCHW". Defaults to * "NHWC". Specify the data format of the input and output data. With the * default format "NHWC", the data is stored in the order of: [batch, * depth, height, width, channels]. Only "NHWC" is currently supported. * @param dilations The dilation rates: `[dilationDepth, dilationHeight, * dilationWidth]` in which we sample input values across the height * and width dimensions in atrous convolution. Defaults to `[1, 1, 1]`. * If `dilations` is a single number, then * `dilationDepth == dilationHeight == dilationWidth`. If it is greater * than 1, then all values of `strides` must be 1. */ /** @doc {heading: 'Operations', subheading: 'Convolution'} */ declare function conv3d_<T extends Tensor4D | Tensor5D>(x: T | TensorLike, filter: Tensor5D | TensorLike, strides: [number, number, number] | number, pad: 'valid' | 'same', dataFormat?: 'NHWC' | 'NCHW', dilations?: [number, number, number] | number): T; export declare const conv1d: typeof conv1d_; export declare const conv2d: typeof conv2d_; export declare const conv3d: typeof conv3d_; export declare const conv2dDerFilter: typeof conv2dDerFilter_; export declare const depthwiseConv2d: typeof depthwiseConv2d_; export declare const separableConv2d: typeof separableConv2d_; export declare const conv2dTranspose: typeof conv2dTranspose_; export {};