<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) 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) |

Class that performs dense feature vector extraction on images.

    tflite_support.task.vision.ImageEmbedder(
        options: https://developers.google.com/edge/api/tflite/python/tflite_support/task/vision/ImageEmbedderOptions,
        cpp_embedder: _CppImageEmbedder
    ) -> None

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `number_of_output_layers` | Gets the number of output layers of the model. |
| `options` | <br /> <br /> |

<br />

## Methods

### `cosine_similarity`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L148-L151)

    cosine_similarity(
        u: https://developers.google.com/edge/api/tflite/python/tflite_support/task/processor/FeatureVector,
        v: https://developers.google.com/edge/api/tflite/python/tflite_support/task/processor/FeatureVector
    ) -> float

Computes cosine similarity \[1\] between two feature vectors.

### `create_from_file`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L57-L74)

    @classmethod
    create_from_file(
        file_path: str
    ) -> 'ImageEmbedder'

Creates the `ImageEmbedder` object from a TensorFlow Lite model.

<br />

<br />

<br />

| Args ||
|---|---|
| `file_path` | Path to the model. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `ImageEmbedder` object that's created from the model file. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If failed to create `ImageEmbedder` object from the provided file such as invalid file. |
| `RuntimeError` | If other types of error occurred. |

<br />

### `create_from_options`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L76-L94)

    @classmethod
    create_from_options(
        options: https://developers.google.com/edge/api/tflite/python/tflite_support/task/vision/ImageEmbedderOptions
    ) -> 'ImageEmbedder'

Creates the `ImageEmbedder` object from image embedder options.

<br />

<br />

<br />

| Args ||
|---|---|
| `options` | Options for the image embedder task. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `ImageEmbedder` object that's created from `options`. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If failed to create `ImageEmbdder` object from `ImageEmbedderOptions` such as missing the model. |
| `RuntimeError` | If other types of error occurred. |

<br />

### `embed`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L96-L124)

    embed(
        image: https://developers.google.com/edge/api/tflite/python/tflite_support/task/vision/TensorImage,
        bounding_box: Optional[https://developers.google.com/edge/api/tflite/python/tflite_support/task/processor/BoundingBox] = None
    ) -> https://developers.google.com/edge/api/tflite/python/tflite_support/task/processor/EmbeddingResult

Performs actual feature vector extraction on the provided TensorImage.

<br />

<br />

<br />

| 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. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The embedding result. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If any of the input arguments is invalid. |
| `RuntimeError` | If failed to calculate the embedding vector. |

<br />

### `get_embedding_by_index`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L126-L146)

    get_embedding_by_index(
        result: https://developers.google.com/edge/api/tflite/python/tflite_support/task/processor/EmbeddingResult,
        output_index: int
    ) -> https://developers.google.com/edge/api/tflite/python/tflite_support/task/processor/Embedding

Gets the embedding in the embedding result by `output_index`.

<br />

<br />

<br />

| Args ||
|---|---|
| `result` | embedding result. |
| `output_index` | output index of the output layer. |

<br />

<br />

<br />

<br />

| 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). ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| ValueError if the output index is out of bound. ||

<br />

### `get_embedding_dimension`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/image_embedder.py#L153-L163)

    get_embedding_dimension(
        output_index: int
    ) -> int

Gets the dimensionality of the embedding output.

<br />

<br />

<br />

| Args ||
|---|---|
| `output_index` | The output index of output layer. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Dimensionality of the embedding output by the output_index'th output layer. Returns -1 if `output_index` is out of bounds. ||

<br />