Performs actual feature vector extraction on the provided TensorImage.
Args
image
Tensor image, used to extract the feature vectors.
bounding_box
Bounding box, optional. If set, performed feature vector
extraction only on the provided region of interest. Note that the region
of interest is not clamped, so this method will fail if the region is
out of bounds of the input image.
Gets the embedding in the embedding result by output_index.
Args
result
embedding result.
output_index
output index of the output layer.
Returns
The Embedding output by the output_index'th layer. In (the most common)
case where a single embedding is produced, you can just call
get_feature_vector_by_index(result, 0).
[[["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.ImageEmbedder\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/image_embedder.py#L47-L172) |\n\nClass that performs dense feature vector extraction on images. \n\n tflite_support.task.vision.ImageEmbedder(\n options: ../../../tflite_support/task/vision/ImageEmbedderOptions,\n cpp_embedder: _CppImageEmbedder\n ) -\u003e None\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|---------------------------|------------------------------------------------|\n| `number_of_output_layers` | Gets the number of output layers of the model. |\n| `options` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `cosine_similarity`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L148-L151) \n\n cosine_similarity(\n u: ../../../tflite_support/task/processor/FeatureVector,\n v: ../../../tflite_support/task/processor/FeatureVector\n ) -\u003e float\n\nComputes cosine similarity \\[1\\] between two feature vectors.\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/image_embedder.py#L57-L74) \n\n @classmethod\n create_from_file(\n file_path: str\n ) -\u003e 'ImageEmbedder'\n\nCreates the `ImageEmbedder` object from a TensorFlow Lite model.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------|--------------------|\n| `file_path` | Path to the model. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `ImageEmbedder` object that's created from the model file. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|-----------------------------------------------------------------------------------------|\n| `ValueError` | If failed to create `ImageEmbedder` object from the provided file such as invalid file. |\n| `RuntimeError` | If other types of error occurred. |\n\n\u003cbr /\u003e\n\n### `create_from_options`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L76-L94) \n\n @classmethod\n create_from_options(\n options: ../../../tflite_support/task/vision/ImageEmbedderOptions\n ) -\u003e 'ImageEmbedder'\n\nCreates the `ImageEmbedder` object from image embedder options.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------|--------------------------------------|\n| `options` | Options for the image embedder task. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `ImageEmbedder` object that's created from `options`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|--------------------------------------------------------------------------------------------------|\n| `ValueError` | If failed to create `ImageEmbdder` object from `ImageEmbedderOptions` such as missing the model. |\n| `RuntimeError` | If other types of error occurred. |\n\n\u003cbr /\u003e\n\n### `embed`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L96-L124) \n\n embed(\n image: ../../../tflite_support/task/vision/TensorImage,\n bounding_box: Optional[../../../tflite_support/task/processor/BoundingBox] = None\n ) -\u003e ../../../tflite_support/task/processor/EmbeddingResult\n\nPerforms actual feature vector extraction on the provided TensorImage.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `image` | Tensor image, used to extract the feature vectors. |\n| `bounding_box` | Bounding box, optional. If set, performed feature vector extraction only on the provided region of interest. Note that the region of interest is not clamped, so this method will fail if the region is out of bounds of the input image. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The embedding result. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|----------------------------------------------|\n| `ValueError` | If any of the input arguments is invalid. |\n| `RuntimeError` | If failed to calculate the embedding vector. |\n\n\u003cbr /\u003e\n\n### `get_embedding_by_index`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L126-L146) \n\n get_embedding_by_index(\n result: ../../../tflite_support/task/processor/EmbeddingResult,\n output_index: int\n ) -\u003e ../../../tflite_support/task/processor/Embedding\n\nGets the embedding in the embedding result by `output_index`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------|-----------------------------------|\n| `result` | embedding result. |\n| `output_index` | output index of the output layer. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The Embedding output by the output_index'th layer. In (the most common) case where a single embedding is produced, you can just call get_feature_vector_by_index(result, 0). ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|---|---|\n| ValueError if the output index is out of bound. ||\n\n\u003cbr /\u003e\n\n### `get_embedding_dimension`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L153-L163) \n\n get_embedding_dimension(\n output_index: int\n ) -\u003e int\n\nGets the dimensionality of the embedding output.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------|-----------------------------------|\n| `output_index` | The output index of output layer. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| Dimensionality of the embedding output by the output_index'th output layer. Returns -1 if `output_index` is out of bounds. ||\n\n\u003cbr /\u003e"]]