The FaceNet Android app uses TensorFlow Lite models sourced from the deepface library to generate face embeddings. Two variants are available with different embedding dimensions.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/shubham0204/OnDevice-Face-Recognition-Android/llms.txt
Use this file to discover all available pages before exploring further.
Model variants
facenet.tflite
The standard FaceNet model that outputs 128-dimensional embeddings. Input shape:[1, 160, 160, 3] - 160x160 RGB face image
Output shape: [1, 128] - 128-dimensional embedding vector
Use case: Suitable for most face recognition tasks with lower memory footprint and faster inference.
facenet_512.tflite
The extended FaceNet model that outputs 512-dimensional embeddings. Input shape:[1, 160, 160, 3] - 160x160 RGB face image
Output shape: [1, 512] - 512-dimensional embedding vector
Use case: Provides higher accuracy for face recognition at the cost of increased memory usage and slightly slower inference.
Both models require cropped face images of size 160x160 pixels as input. Face detection is performed separately using either Mediapipe or MLKit before feeding images to FaceNet.
Model source
Both FaceNet models are sourced from the deepface library, a popular Python library for face recognition and facial attribute analysis.Conversion process
The models were converted from Keras format to TensorFlow Lite with FP16 optimization using the following Python scripts:Converting facenet.tflite
Converting facenet_512.tflite
The conversion process applies FP16 (half-precision floating point) optimization to reduce model size while maintaining accuracy.
Choosing between models
To switch between the two FaceNet models in your app:- Update the model path in
FaceNet.kt:
- Update the embedding dimension in
FaceNet.kt:
- Update the database schema in
DataModels.kt:
Model architecture
FaceNet uses a deep convolutional neural network architecture based on the FaceNet paper. The model is trained using triplet loss to learn embeddings where:- Embeddings of the same person are close together in the embedding space
- Embeddings of different people are far apart
- Cosine similarity is used to measure distance between embeddings