FaceNet class provides face embedding generation using a TensorFlow Lite model. It converts face images into 512-dimensional embedding vectors for face recognition tasks.
Constructor
Android application context for loading the TFLite model from assets
Enable GPU acceleration if supported by the device. Falls back to CPU with 4 threads if GPU is not available
Enable XNNPACK delegate for optimized inference on CPU
Methods
getFaceEmbedding
Generates a 512-dimensional face embedding from a cropped face image.Cropped face image to generate embedding from. Will be automatically resized to 160x160 pixels
A 512-dimensional embedding vector representing the face features
Configuration
The FaceNet model has the following fixed configurations:Input image size (160x160 pixels). Images are automatically resized to this dimension
Output embedding dimension. The model generates 512-dimensional vectors
TFLite model file loaded from the assets folder
Usage example
Implementation details
The class automatically:- Resizes input images to 160x160 pixels using bilinear interpolation
- Normalizes pixel values from [0, 255] to [0, 1]
- Detects GPU compatibility and enables GPU delegate when available
- Falls back to CPU with 4 threads if GPU is unavailable
- Enables NNAPI acceleration for compatible devices
domain/embeddings/FaceNet.kt:25