表示多維陣列,用於向模型推理提供資料或從中獲取資料。

interface Tensor {
    data: string[] | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
    dims: readonly number[];
    gpuBuffer: GpuBufferTypeFallback;
    location: DataLocation;
    mlTensor: MLTensorTypeFallback;
    size: number;
    texture: WebGLTexture;
    type: keyof DataTypeMap;
    dispose(): void;
    getData(releaseData?): Promise<string[] | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array>;
    reshape(dims): TypedTensor<keyof DataTypeMap>;
    toDataURL(options?): string;
    toImageData(options?): ImageData;
}

繼承關係

  • TypedTensorBase<Type>
  • TypedTensorUtils<Type>
    • 張量

屬性

data: string[] | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array

獲取張量的緩衝區資料。

如果資料不在 CPU 上(例如,它是 WebGL 紋理或 WebGPU 緩衝區的形式),則丟擲錯誤。

dims: readonly number[]

獲取張量的維度。

獲取儲存張量資料的 WebGPU 緩衝區。

如果資料不在 GPU 上作為 WebGPU 緩衝區,則丟擲錯誤。

location: DataLocation

獲取資料的位置。

獲取儲存張量資料的 WebNN MLTensor。

如果資料不在 WebNN MLTensor 中,則丟擲錯誤。

size: number

獲取張量中的元素數量。

texture: WebGLTexture

獲取儲存張量資料的 WebGL 紋理。

如果資料不在 GPU 上作為 WebGL 紋理,則丟擲錯誤。

type: keyof DataTypeMap

獲取張量的資料型別。

方法

  • 釋放張量資料。

    如果資料在 CPU 上,則移除其對底層資料的內部引用。如果資料在 GPU 上,則釋放 GPU 上的資料。

    呼叫此函式後,張量將被視為不再有效。其位置將被設定為 'none'。

    返回 void

  • 獲取張量的緩衝區資料。

    如果資料在 CPU 上,則立即返回資料。如果資料在 GPU 上,則下載資料並返回 Promise。

    引數

    • Optional releaseData: boolean

      是否釋放 GPU 上的資料。如果資料已在 CPU 上,則忽略此引數。

    返回 Promise<string[] | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array>

  • 從張量建立 DataURL 例項

    引數

    • Optional options: TensorToDataUrlOptions

      一個可選物件,表示從張量建立 DataURL 例項的選項。

      將應用以下預設設定

      • format: 'RGB'
      • tensorLayout: 'NCHW'

    返回 string

    表示從張量資料轉換而來的影像的 DataURL 字串

  • 從張量建立 ImageData 例項

    引數

    • Optional options: TensorToImageDataOptions

      一個可選物件,表示從張量建立 ImageData 例項的選項。

      將應用以下預設設定

      • format: 'RGB'
      • tensorLayout: 'NCHW'

    返回 ImageData

    表示從張量資料轉換而來的影像的 ImageData 例項

使用 TypeDoc 生成