Shortcuts

TensorImageUtils

public final class TensorImageUtils

Contains utility functions for org.pytorch.Tensor creation from android.graphics.Bitmap or android.media.Image source.

Fields

TORCHVISION_NORM_MEAN_RGB

public static float[] TORCHVISION_NORM_MEAN_RGB

TORCHVISION_NORM_STD_RGB

public static float[] TORCHVISION_NORM_STD_RGB

Methods

bitmapToFloat32Tensor

public static Tensor bitmapToFloat32Tensor(Bitmap bitmap, float[] normMeanRGB, float[] normStdRGB)

Creates new org.pytorch.Tensor from full android.graphics.Bitmap, normalized with specified in parameters mean and std.

Parameters
  • normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order

  • normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order

bitmapToFloat32Tensor

public static Tensor bitmapToFloat32Tensor(Bitmap bitmap, int x, int y, int width, int height, float[] normMeanRGB, float[] normStdRGB)

Creates new org.pytorch.Tensor from specified area of android.graphics.Bitmap, normalized with specified in parameters mean and std.

Parameters
  • bitmapandroid.graphics.Bitmap as a source for Tensor data

  • x

    • x coordinate of top left corner of bitmap’s area

  • y

    • y coordinate of top left corner of bitmap’s area

  • width

    • width of bitmap’s area

  • height

    • height of bitmap’s area

  • normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order

  • normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order

bitmapToFloatBuffer

public static void bitmapToFloatBuffer(Bitmap bitmap, int x, int y, int width, int height, float[] normMeanRGB, float[] normStdRGB, FloatBuffer outBuffer, int outBufferOffset)

Writes tensor content from specified android.graphics.Bitmap, normalized with specified in parameters mean and std to specified java.nio.FloatBuffer with specified offset.

Parameters
  • bitmapandroid.graphics.Bitmap as a source for Tensor data

  • x

    • x coordinate of top left corner of bitmap’s area

  • y

    • y coordinate of top left corner of bitmap’s area

  • width

    • width of bitmap’s area

  • height

    • height of bitmap’s area

  • normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order

  • normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order

imageYUV420CenterCropToFloat32Tensor

public static Tensor imageYUV420CenterCropToFloat32Tensor(Image image, int rotateCWDegrees, int tensorWidth, int tensorHeight, float[] normMeanRGB, float[] normStdRGB)

Creates new org.pytorch.Tensor from specified area of android.media.Image, doing optional rotation, scaling (nearest) and center cropping.

Parameters
  • imageandroid.media.Image as a source for Tensor data

  • rotateCWDegrees – Clockwise angle through which the input image needs to be rotated to be upright. Range of valid values: 0, 90, 180, 270

  • tensorWidth – return tensor width, must be positive

  • tensorHeight – return tensor height, must be positive

  • normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order

  • normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order

imageYUV420CenterCropToFloatBuffer

public static void imageYUV420CenterCropToFloatBuffer(Image image, int rotateCWDegrees, int tensorWidth, int tensorHeight, float[] normMeanRGB, float[] normStdRGB, FloatBuffer outBuffer, int outBufferOffset)

Writes tensor content from specified android.media.Image, doing optional rotation, scaling (nearest) and center cropping to specified java.nio.FloatBuffer with specified offset.

Parameters
  • imageandroid.media.Image as a source for Tensor data

  • rotateCWDegrees – Clockwise angle through which the input image needs to be rotated to be upright. Range of valid values: 0, 90, 180, 270

  • tensorWidth – return tensor width, must be positive

  • tensorHeight – return tensor height, must be positive

  • normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order

  • normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order

  • outBuffer – Output buffer, where tensor content will be written

  • outBufferOffset – Output buffer offset with which tensor content will be written

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources