A mutable tf.Tensor, useful for persisting state, e.g. for training.

Doc

Type Parameters

  • R extends Rank = Rank

Hierarchy

Properties

dataId: object

Id of the bucket holding the data for this tensor. Multiple arrays can point to the same bucket (e.g. when calling array.reshape()).

dtype: keyof DataTypeMap

The data type for the array.

id: number

Unique id of this tensor.

kept: boolean

Whether this tensor has been globally kept.

kerasMask?: Tensor<Rank>

The keras mask that some keras layers attach to the tensor

rankType: R

The rank type for the array (see Rank enum).

scopeId: number

The id of the scope this tensor is being tracked in.

shape: ShapeMap[R]

The shape of the tensor.

size: number

Number of elements in the tensor.

strides: number[]

Number of elements to skip in each dimension when indexing. See https://docs.scipy.org/doc/numpy/reference/generated/\ numpy.ndarray.strides.html

Methods

  • Returns the tensor data as a nested array. The transfer of data is done asynchronously.

    Returns Promise<ArrayMap[R]>

    Doc

  • Returns the tensor data as a nested array. The transfer of data is done synchronously.

    Returns ArrayMap[R]

    Doc

  • Assign a new tf.Tensor to this variable. The new tf.Tensor must have the same shape and dtype as the old tf.Tensor.

    Parameters

    • newValue: Tensor<R>

      New tensor to be assigned to this variable.

    Returns void

    Doc

  • Returns a promise of tf.TensorBuffer that holds the underlying data.

    Type Parameters

    • D extends keyof DataTypeMap = "float32"

    Returns Promise<TensorBuffer<R, D>>

    Doc

  • Returns a tf.TensorBuffer that holds the underlying data.

    Type Parameters

    • D extends keyof DataTypeMap = "float32"

    Returns TensorBuffer<R, D>

    Doc

  • Returns the underlying bytes of the tensor's data.

    Returns Promise<Uint8Array | Uint8Array[]>

  • Returns a copy of the tensor. See tf.clone for details.

    Type Parameters

    Parameters

    • this: T

    Returns T

    Doc

  • Asynchronously downloads the values from the tf.Tensor. Returns a promise of TypedArray that resolves when the computation has finished.

    Type Parameters

    • D extends keyof DataTypeMap = NumericDataType

    Returns Promise<DataTypeMap[D]>

    Doc

  • Synchronously downloads the values from the tf.Tensor. This blocks the UI thread until the values are ready, which can cause performance issues.

    Type Parameters

    • D extends keyof DataTypeMap = NumericDataType

    Returns DataTypeMap[D]

    Doc

  • Copy the tensor's data to a new GPU resource. Comparing to the dataSync() and data(), this method prevents data from being downloaded to CPU.

    For WebGL backend, the data will be stored on a densely packed texture. This means that the texture will use the RGBA channels to store value.

    For WebGPU backend, the data will be stored on a buffer. There is no parameter, so can not use a user-defined size to create the buffer.

    Parameters

    • Optional options: DataToGPUWebGLOption

    Returns GPUData

    For WebGL backend, a GPUData contains the new texture and its information. { tensorRef: The tensor that is associated with this texture, texture: WebGLTexture, texShape: [number, number] // [height, width] }

    For WebGPU backend, a GPUData contains the new buffer.
    {
    tensorRef: The tensor that is associated with this buffer,
    buffer: GPUBuffer,
    }

    Remember to dispose the GPUData after it is used by
    `res.tensorRef.dispose()`.

    Doc

  • Prints the tf.Tensor. See tf.print for details.

    Parameters

    • Optional verbose: boolean

      Whether to print verbose information about the tensor, including dtype and size.

    Returns void

    Doc

  • Returns a human-readable description of the tensor. Useful for logging.

    Parameters

    • Optional verbose: boolean

    Returns string

    Doc

Generated using TypeDoc