image_utils.ImageData, contains raw image data, width, height
and channels info.
is_from_numpy_array
boolean, whether image_data is loaded from
numpy array. if False, it means that image_data is loaded from
stbi_load** function in C++ and need to free the storage of ImageData in
the destructor.
Attributes
buffer
Gets the numpy array that represents self.image_data.
numpy array with dtype=uint8. Its shape should be either (h, w, 3)
or (1, h, w, 3) for RGB images, either (h, w) or (1, h, w) for GRAYSCALE
images and either (h, w, 4) or (1, h, w, 4) for RGBA images.
Returns
TensorImage object.
Raises
ValueError if the dytype of the numpy array is not uint8 or the
dimention is not the valid dimention.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-05-08 UTC."],[],[],null,["# tflite_support.task.vision.TensorImage\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/core/tensor_image.py#L22-L139) |\n\nWrapper class for the Image object. \n\n tflite_support.task.vision.TensorImage(\n image_data: image_utils.ImageData, is_from_numpy_array: bool = True\n ) -\u003e None\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `image_data` | image_utils.ImageData, contains raw image data, width, height and channels info. |\n| `is_from_numpy_array` | boolean, whether `image_data` is loaded from numpy array. if False, it means that `image_data` is loaded from stbi_load\\*\\* function in C++ and need to free the storage of ImageData in the destructor. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|--------------------|---------------------------------------------------------|\n| `buffer` | Gets the numpy array that represents `self.image_data`. |\n| `color_space_type` | Gets the color space type of the image. |\n| `height` | Gets the height of the image. |\n| `width` | Gets the width of the image. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `create_from_array`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/core/tensor_image.py#L59-L79) \n\n @classmethod\n create_from_array(\n array: np.ndarray\n ) -\u003e 'TensorImage'\n\nCreates `TensorImage` object from the numpy array.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `array` | numpy array with dtype=uint8. Its shape should be either (h, w, 3) or (1, h, w, 3) for RGB images, either (h, w) or (1, h, w) for GRAYSCALE images and either (h, w, 4) or (1, h, w, 4) for RGBA images. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `TensorImage` object. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|---|---|\n| ValueError if the dytype of the numpy array is not `uint8` or the dimention is not the valid dimention. ||\n\n\u003cbr /\u003e\n\n### `create_from_buffer`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/core/tensor_image.py#L81-L96) \n\n @classmethod\n create_from_buffer(\n buffer: str\n ) -\u003e 'TensorImage'\n\nCreates `TensorImage` object from the binary buffer.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|-----------------------|\n| `buffer` | Binary memory buffer. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `TensorImage` object. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|---|---|\n| RuntimeError if the binary buffer can't be decoded into `TensorImage` object. ||\n\n\u003cbr /\u003e\n\n### `create_from_file`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/core/tensor_image.py#L43-L57) \n\n @classmethod\n create_from_file(\n file_name: str\n ) -\u003e 'TensorImage'\n\nCreates `TensorImage` object from the image file.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------|------------------|\n| `file_name` | Image file name. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `TensorImage` object. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|---|---|\n| RuntimeError if the image file can't be decoded. ||\n\n\u003cbr /\u003e"]]