• Draws a tf.Tensor of pixel values to a byte array or optionally a canvas.

    When the dtype of the input is 'float32', we assume values in the range [0-1]. Otherwise, when input is 'int32', we assume values in the range [0-255].

    Returns a promise that resolves when the canvas has been drawn to.

    Parameters

    • img: Tensor2D | TensorLike | Tensor3D

      A rank-2 tensor with shape [height, width], or a rank-3 tensor of shape [height, width, numChannels]. If rank-2, draws grayscale. If rank-3, must have depth of 1, 3 or 4. When depth of 1, draws grayscale. When depth of 3, we draw with the first three components of the depth dimension corresponding to r, g, b and alpha = 1. When depth of 4, all four components of the depth dimension correspond to r, g, b, a.

    • Optionalcanvas: HTMLCanvasElement

      The canvas to draw to.

    Returns Promise<Uint8ClampedArray>