.. index:: 
  !Face encoding

.. _face_encoding:

=============
Face encoding
=============

Face encoding is the process of extracting facial features from a :ref:`detected face<face_detection>`. It outputs a :ref:`face template<face_template>` to be used for :ref:`face comparison<face_comparison>` or :ref:`face search<face_search>`.

.. important:: 
  | The face encoder requires a machine learning model to be loaded into memory. The model should be selected according to the target platform and use-case.
  | See :ref:`ai_models` for details.

.. note:: Call the :ref:`id3_face_face_library_load_model_class_method` to load the chosen model on application start.

.. hint:: On startup, call the :ref:`id3_face_face_encoder_warm_up_class_method` to prepare inference of the AI model.


.. _face_template:

Face template
=============

A face template is a small representation of a face, only 140 bytes or 264 bytes depending on the encoding model used. It is used for :ref:`face comparison<face_comparison>` or :ref:`face search<face_search>`.

A face template can be also exported to the format required by id3 Face Match-on-Card solution.

Encoding quality
================

The component also provides a quality estimator that aims at predicting the power of matching of a created template.

.. important:: This functionality requires the model FaceEncodingQualityEstimator_2A to be loaded.

Example
=======

The example below demonstrates how to encode a face image and generate a :ref:`FaceTemplate<id3_face_face_template_class>`:

.. tab-set::

  .. tab-item:: Python
    :sync: Python

    .. literalinclude:: /../samples/sample.py
      :language: python
      :start-after: [face_encoding]
      :end-before: [face_encoding]
      :dedent: 4

See also
========
- :ref:`id3_face_face_encoder_class`
- :ref:`id3_face_face_template_class`