• Creates a tf.Tensor from an image in async way.

    const image = new ImageData(1, 1);
    image.data[0] = 100;
    image.data[1] = 150;
    image.data[2] = 200;
    image.data[3] = 255;

    (await tf.browser.fromPixelsAsync(image)).print();

    This API is the async version of fromPixels. The API will first check |WRAP_TO_IMAGEBITMAP| flag, and try to wrap the input to imageBitmap if the flag is set to true.

    Parameters

    • pixels:
          | HTMLCanvasElement
          | HTMLImageElement
          | HTMLVideoElement
          | ImageData
          | ImageBitmap
          | PixelData

      The input image to construct the tensor from. The supported image types are all 4-channel. You can also pass in an image object with following attributes: {data: Uint8Array; width: number; height: number}

    • OptionalnumChannels: number

      The number of channels of the output tensor. A numChannels value less than 4 allows you to ignore channels. Defaults to 3 (ignores alpha channel of input image).

    Returns Promise<Tensor3D>