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

interface TypedTensor<T> {
    data: DataTypeMap[T];
    dims: readonly number[];
    gpuBuffer: GpuBufferTypeFallback;
    location: DataLocation;
    mlTensor: MLTensorTypeFallback;
    size: number;
    texture: WebGLTexture;
    type: T;
    dispose(): void;
    getData(releaseData?): Promise<DataTypeMap[T]>;
    reshape(dims): TypedTensor<T>;
    toDataURL(options?): string;
    toImageData(options?): ImageData;
}

型別引數

繼承層次

  • TypedTensorBase<T>
  • TypedTensorUtils<T>
    • TypedTensor

屬性

data: DataTypeMap[T]

獲取張量的緩衝區資料。

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

dims: readonly number[]

獲取張量的維度。

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

如果資料不在GPU上以WebGPU緩衝區的形式存在,則丟擲錯誤。

location: DataLocation

獲取資料的位置。

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

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

size: number

獲取張量中的元素數量。

texture: WebGLTexture

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

如果資料不在GPU上以WebGL紋理的形式存在,則丟擲錯誤。

type: T

獲取張量的資料型別。

方法

  • 釋放張量資料。

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

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

    返回 void

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

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

    引數

    • 可選 releaseData: boolean

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

    返回 Promise<DataTypeMap[T]>

  • 使用相同的資料緩衝區和指定的維度建立一個新張量。

    引數

    • dims: readonly number[]

      新維度。大小應與舊維度匹配。

    返回 TypedTensor<T>

  • 從張量建立DataURL例項

    引數

    • 可選 options: TensorToDataUrlOptions

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

      將應用以下預設設定:

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

    返回 string

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

  • 從張量建立ImageData例項

    引數

    • 可選 options: TensorToImageDataOptions

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

      將應用以下預設設定:

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

    返回 ImageData

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

使用 TypeDoc 生成