type TensorConstructor defines the constructors of 'Tensor' to create CPU tensor instances.

interface TensorConstructor {
    new TensorConstructornew (type, data, dims?): TypedTensor<"string">;
    new TensorConstructornew (type, data, dims?): TypedTensor<"bool">;
    new TensorConstructornew <T>(type, data, dims?): TypedTensor<T>;
    new TensorConstructornew <T>(type, data, dims?): TypedTensor<T>;
    new TensorConstructornew (data, dims?): TypedTensor<"float32">;
    new TensorConstructornew (data, dims?): TypedTensor<"int8">;
    new TensorConstructornew (data, dims?): TypedTensor<"uint8">;
    new TensorConstructornew (data, dims?): TypedTensor<"uint16">;
    new TensorConstructornew (data, dims?): TypedTensor<"int16">;
    new TensorConstructornew (data, dims?): TypedTensor<"int32">;
    new TensorConstructornew (data, dims?): TypedTensor<"int64">;
    new TensorConstructornew (data, dims?): TypedTensor<"string">;
    new TensorConstructornew (data, dims?): TypedTensor<"bool">;
    new TensorConstructornew (data, dims?): TypedTensor<"float64">;
    new TensorConstructornew (data, dims?): TypedTensor<"uint32">;
    new TensorConstructornew (data, dims?): TypedTensor<"uint64">;
    new TensorConstructornew (type, data, dims?): Tensor;
    new TensorConstructornew (data, dims?): Tensor;
    fromGpuBuffer<T>(buffer, options): TypedTensor<T>;
    fromImage(imageData, options?): Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>;
    fromImage(imageElement, options?): Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>;
    fromImage(urlSource, options?): Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>;
    fromImage(bitmap, options): Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>;
    fromPinnedBuffer<T>(type, buffer, dims?): TypedTensor<T>;
    fromTexture<T>(texture, options): TypedTensor<"float32">;
}

Hierarchy (view full)

Constructors

  • Construct a new string tensor object from the given type, data and dims.

    Parameters

    • type: "string"

      Specify the element type.

    • data: string[] | readonly string[]

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"string">

  • Construct a new bool tensor object from the given type, data and dims.

    Parameters

    • type: "bool"

      Specify the element type.

    • data: Uint8Array | readonly boolean[]

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"bool">

  • Construct a new 64-bit integer typed tensor object from the given type, data and dims.

    Type Parameters

    • T extends "int64" | "uint64"

    Parameters

    • type: T

      Specify the element type.

    • data: readonly number[] | DataTypeMap[T] | readonly bigint[]

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<T>

  • Construct a new numeric tensor object from the given type, data and dims.

    Type Parameters

    • T extends "float32" | "uint8" | "int8" | "uint16" | "int16" | "int32" | "float16" | "float64" | "uint32"

    Parameters

    • type: T

      Specify the element type.

    • data: readonly number[] | DataTypeMap[T]

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<T>

  • Construct a new float32 tensor object from the given data and dims.

    Parameters

    • data: Float32Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"float32">

  • Construct a new int8 tensor object from the given data and dims.

    Parameters

    • data: Int8Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"int8">

  • Construct a new uint8 tensor object from the given data and dims.

    Parameters

    • data: Uint8Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"uint8">

  • Construct a new uint16 tensor object from the given data and dims.

    Parameters

    • data: Uint16Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"uint16">

  • Construct a new int16 tensor object from the given data and dims.

    Parameters

    • data: Int16Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"int16">

  • Construct a new int32 tensor object from the given data and dims.

    Parameters

    • data: Int32Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"int32">

  • Construct a new int64 tensor object from the given data and dims.

    Parameters

    • data: BigInt64Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"int64">

  • Construct a new string tensor object from the given data and dims.

    Parameters

    • data: readonly string[]

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"string">

  • Construct a new bool tensor object from the given data and dims.

    Parameters

    • data: readonly boolean[]

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"bool">

  • Construct a new float64 tensor object from the given data and dims.

    Parameters

    • data: Float64Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"float64">

  • Construct a new uint32 tensor object from the given data and dims.

    Parameters

    • data: Uint32Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"uint32">

  • Construct a new uint64 tensor object from the given data and dims.

    Parameters

    • data: BigUint64Array

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<"uint64">

  • Construct a new tensor object from the given type, data and dims.

    Parameters

    • type: keyof DataTypeMap

      Specify the element type.

    • data: readonly string[] | readonly number[] | DataType | readonly boolean[] | readonly bigint[]

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns Tensor

  • Construct a new tensor object from the given data and dims.

    Parameters

    • data: DataType

      Specify the CPU tensor data.

    • Optional dims: readonly number[]

      Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns Tensor

Methods

  • create a tensor from a WebGPU buffer

    Type Parameters

    Parameters

    • buffer: GpuBufferType

      the GPUBuffer object to create tensor from

    • options: TensorFromGpuBufferOptions<T>

      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.

    Returns TypedTensor<T>

    a tensor object

  • create a tensor from an ImageData object

    Parameters

    • imageData: ImageData

      the ImageData object to create tensor from

    • Optional options: TensorFromImageDataOptions

      An optional object representing options for creating tensor from ImageData.

      The following default settings will be applied:

      • tensorFormat: 'RGB'
      • tensorLayout: 'NCHW'
      • dataType: 'float32'

    Returns Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>

    A promise that resolves to a tensor object

  • create a tensor from a HTMLImageElement object

    Parameters

    • imageElement: HTMLImageElement

      the HTMLImageElement object to create tensor from

    • Optional options: TensorFromImageElementOptions

      An optional object representing options for creating tensor from HTMLImageElement.

      The following default settings will be applied:

      • tensorFormat: 'RGB'
      • tensorLayout: 'NCHW'
      • dataType: 'float32'

    Returns Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>

    A promise that resolves to a tensor object

  • create a tensor from URL

    Parameters

    • urlSource: string

      a string as a URL to the image or a data URL containing the image data.

    • Optional options: TensorFromUrlOptions

      An optional object representing options for creating tensor from URL.

      The following default settings will be applied:

      • tensorFormat: 'RGB'
      • tensorLayout: 'NCHW'
      • dataType: 'float32'

    Returns Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>

    A promise that resolves to a tensor object

  • create a tensor from an ImageBitmap object

    Parameters

    • bitmap: ImageBitmap

      the ImageBitmap object to create tensor from

    • options: TensorFromImageBitmapOptions

      An optional object representing options for creating tensor from URL.

      The following default settings will be applied:

      • tensorFormat: 'RGB'
      • tensorLayout: 'NCHW'
      • dataType: 'float32'

    Returns Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>

    A promise that resolves to a tensor object

  • create a tensor from a pre-allocated buffer. The buffer will be used as a pinned buffer.

    Type Parameters

    • T extends "float32" | "uint8" | "int8" | "uint16" | "int16" | "int32" | "int64" | "bool" | "float16" | "float64" | "uint32" | "uint64"

    Parameters

    • type: T

      the tensor element type.

    • buffer: DataTypeMap[T]

      a TypedArray corresponding to the type.

    • Optional dims: readonly number[]

      specify the dimension of the tensor. If omitted, a 1-D tensor is assumed.

    Returns TypedTensor<T>

    a tensor object

  • create a tensor from a WebGL texture

    Type Parameters

    • T extends "float32" = "float32"

    Parameters

    • texture: WebGLTexture

      the WebGLTexture object to create tensor from

    • options: TensorFromTextureOptions<T>

      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.

    Returns TypedTensor<"float32">

    a tensor object

Generated using TypeDoc