create a tensor from a WebGPU buffer
the GPUBuffer object to create tensor from
An optional object representing options for creating tensor from WebGPU buffer.
The options include following properties:
dataType
: the data type of the tensor. If omitted, assume 'float32'.dims
: the dimension of the tensor. Required.download
: an optional function to download the tensor data from GPU to CPU. If omitted, the GPU data
will not be able to download. Usually, this is provided by a GPU backend for the inference outputs. Users don't
need to provide this function.dispose
: an optional function to dispose the tensor data on GPU. If omitted, the GPU data will not be disposed.
Usually, this is provided by a GPU backend for the inference outputs. Users don't need to provide this function.a tensor object
create a tensor from an ImageData object
the ImageData object to create tensor from
Optional
options: TensorFromImageDataOptionsAn optional object representing options for creating tensor from ImageData.
The following default settings will be applied:
tensorFormat
: 'RGB'
tensorLayout
: 'NCHW'
dataType
: 'float32'
A promise that resolves to a tensor object
create a tensor from a HTMLImageElement object
the HTMLImageElement object to create tensor from
Optional
options: TensorFromImageElementOptionsAn optional object representing options for creating tensor from HTMLImageElement.
The following default settings will be applied:
tensorFormat
: 'RGB'
tensorLayout
: 'NCHW'
dataType
: 'float32'
A promise that resolves to a tensor object
create a tensor from URL
a string as a URL to the image or a data URL containing the image data.
Optional
options: TensorFromUrlOptionsAn optional object representing options for creating tensor from URL.
The following default settings will be applied:
tensorFormat
: 'RGB'
tensorLayout
: 'NCHW'
dataType
: 'float32'
A promise that resolves to a tensor object
create a tensor from an ImageBitmap object
the ImageBitmap object to create tensor from
An optional object representing options for creating tensor from URL.
The following default settings will be applied:
tensorFormat
: 'RGB'
tensorLayout
: 'NCHW'
dataType
: 'float32'
A promise that resolves to a tensor object
create a tensor from a WebNN MLTensor
the MLTensor object to create tensor from
An optional object representing options for creating tensor from a WebNN MLTensor.
The options include following properties:
dataType
: the data type of the tensor. If omitted, assume 'float32'.dims
: the dimension of the tensor. Required.download
: an optional function to download the tensor data from the MLTensor to CPU. If omitted, the MLTensor
data will not be able to download. Usually, this is provided by the WebNN backend for the inference outputs.
Users don't need to provide this function.dispose
: an optional function to dispose the tensor data on the WebNN MLTensor. If omitted, the MLTensor will
not be disposed. Usually, this is provided by the WebNN backend for the inference outputs. Users don't need to
provide this function.a tensor object
create a tensor from a pre-allocated buffer. The buffer will be used as a pinned buffer.
the tensor element type.
a TypedArray corresponding to the type.
Optional
dims: readonly number[]specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.
a tensor object
create a tensor from a WebGL texture
the WebGLTexture object to create tensor from
An optional object representing options for creating tensor from WebGL texture.
The options include following properties:
width
: the width of the texture. Required.height
: the height of the texture. Required.format
: the format of the texture. If omitted, assume 'RGBA'.download
: an optional function to download the tensor data from GPU to CPU. If omitted, the GPU data
will not be able to download. Usually, this is provided by a GPU backend for the inference outputs. Users don't
need to provide this function.dispose
: an optional function to dispose the tensor data on GPU. If omitted, the GPU data will not be disposed.
Usually, this is provided by a GPU backend for the inference outputs. Users don't need to provide this function.a tensor object
Generated using TypeDoc
type TensorFactory defines the factory functions of 'Tensor' to create tensor instances from existing data or resources.