@tensorflow/tfjs-converter
Version:
Tensorflow model converter for javascript
144 lines (143 loc) • 5.96 kB
TypeScript
/**
* @license
* Copyright 2020 Google LLC. 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.
* =============================================================================
*/
/// <amd-module name="@tensorflow/tfjs-converter/dist/executor/tensor_list" />
import { DataType, Tensor } from '@tensorflow/tfjs-core';
/**
* TensorList stores a container of `tf.Tensor` objects, which are accessible
* via tensors field.
*
* In order to get a copy of the underlying list, use the copy method:
* ```
* TensorList b = a.copy();
* b.tensors().pushBack(t); // This does not modify a.tensors().
* ```
*
* Note that this is not a deep copy: the memory locations of the underlying
* tensors will still point to the same locations of the corresponding tensors
* in the original.
*/
export declare class TensorList {
readonly tensors: Tensor[];
readonly elementShape: number | number[];
readonly elementDtype: DataType;
readonly idTensor: Tensor;
maxNumElements: number;
get id(): number;
/**
*
* @param tensors list of tensors
* @param elementShape shape of each tensor, this can be a single number (any
* shape is allowed) or partial shape (dim = -1).
* @param elementDtype data type of each tensor
* @param maxNumElements The maximum allowed size of `tensors`. Defaults to -1
* meaning that the size of `tensors` is unbounded.
*/
constructor(tensors: Tensor[], elementShape: number | number[], elementDtype: DataType, maxNumElements?: number);
/**
* Get a new TensorList containing a copy of the underlying tensor container.
*/
copy(): TensorList;
/**
* Dispose the tensors and idTensor and clear the tensor list.
*/
clearAndClose(keepIds?: Set<number>): void;
/**
* The size of the tensors in the tensor list.
*/
size(): number;
/**
* Return a tensor that stacks a list of rank-R tf.Tensors into one rank-(R+1)
* tf.Tensor.
* @param elementShape shape of each tensor
* @param elementDtype data type of each tensor
* @param numElements the number of elements to stack
*/
stack(elementShape: number[], elementDtype: DataType, numElements?: number): Tensor;
/**
* Pop a tensor from the end of the list.
* @param elementShape shape of the tensor
* @param elementDtype data type of the tensor
*/
popBack(elementShape: number[], elementDtype: DataType): Tensor;
/**
* Push a tensor to the end of the list.
* @param tensor Tensor to be pushed.
*/
pushBack(tensor: Tensor): void;
/**
* Update the size of the list.
* @param size the new size of the list.
*/
resize(size: number): TensorList;
/**
* Retrieve the element at the provided index
* @param elementShape shape of the tensor
* @param elementDtype dtype of the tensor
* @param elementIndex index of the tensor
*/
getItem(elementIndex: number, elementShape: number[], elementDtype: DataType): Tensor;
/**
* Set the tensor at the index
* @param elementIndex index of the tensor
* @param tensor the tensor to be inserted into the list
*/
setItem(elementIndex: number, tensor: Tensor): void;
/**
* Return selected values in the TensorList as a stacked Tensor. All of
* selected values must have been written and their shapes must all match.
* @param indices indices of tensors to gather
* @param elementDtype output tensor dtype
* @param elementShape output tensor element shape
*/
gather(indices: number[], elementDtype: DataType, elementShape: number[]): Tensor;
/**
* Return the values in the TensorList as a concatenated Tensor.
* @param elementDtype output tensor dtype
* @param elementShape output tensor element shape
*/
concat(elementDtype: DataType, elementShape: number[]): Tensor;
}
/**
* Creates a TensorList which, when stacked, has the value of tensor.
* @param tensor from tensor
* @param elementShape output tensor element shape
*/
export declare function fromTensor(tensor: Tensor, elementShape: number[], elementDtype: DataType): TensorList;
/**
* Return a TensorList of the given size with empty elements.
* @param elementShape the shape of the future elements of the list
* @param elementDtype the desired type of elements in the list
* @param numElements the number of elements to reserve
* @param maxNumElements the maximum number of elements in th list
*/
export declare function reserve(elementShape: number[], elementDtype: DataType, numElements: number, maxNumElements: number): TensorList;
/**
* Put tensors at specific indices of a stacked tensor into a TensorList.
* @param indices list of indices on how to scatter the tensor.
* @param tensor input tensor.
* @param elementShape the shape of the future elements of the list
* @param numElements the number of elements to scatter
*/
export declare function scatter(tensor: Tensor, indices: number[], elementShape: number[], numElements?: number): TensorList;
/**
* Split the values of a Tensor into a TensorList.
* @param length the lengths to use when splitting value along
* its first dimension.
* @param tensor the tensor to split.
* @param elementShape the shape of the future elements of the list
*/
export declare function split(tensor: Tensor, length: number[], elementShape: number[]): TensorList;