Skip to main content

Choose your path

There are two ways to get started with FaceNet Android:

Download APK

Fastest way to try the app (recommended)

Build from source

For developers who want to customize the app

Option 1: Download APK

The quickest way to try FaceNet Android is to download the pre-built APK.
1

Download the APK

Visit the GitHub Releases page and download the latest APK file.
2

Enable installation from unknown sources

On your Android device, go to Settings > Security and enable “Install unknown apps” for your browser or file manager.
3

Install the APK

Open the downloaded APK file and follow the installation prompts.
4

Launch the app

Open “FaceNet Android” from your app drawer.
The app requires Android 8.0 (API level 26) or higher and camera permissions to function.

Option 2: Build from source

If you want to customize the app or contribute to development, you can build it from source.
1

Clone the repository

Open a terminal and clone the repository:
git clone --depth=1 https://github.com/shubham0204/OnDevice-Face-Recognition-Android
cd OnDevice-Face-Recognition-Android
2

Open in Android Studio

Launch Android Studio and select File > Open, then choose the cloned directory.
3

Sync Gradle

Android Studio will automatically prompt you to sync Gradle. Click Sync Now and wait for dependencies to download.
4

Run the app

Connect an Android device or start an emulator, then click the Run button (green play icon) in Android Studio.
Building from source requires Android Studio Hedgehog or newer with Gradle 8.0+.

Using the app

Once you have the app installed, follow these steps to recognize faces:

Add faces to the database

1

Navigate to the add face screen

Tap the Add Person button on the home screen.
2

Enter a person's name

Type the name of the person you want to add to the database.
3

Select images

Tap Select Images and choose one or more photos containing the person’s face. The app will automatically detect and crop faces from each image.
Each image must contain exactly one face. The app will reject images with multiple faces or no faces.
4

Save the person

After selecting images, tap Save. The app will:
  • Detect faces in each image using MLKit
  • Generate 512-dimensional embeddings using FaceNet
  • Store the embeddings in the ObjectBox database

Recognize faces in real-time

1

Open the detection screen

Tap Start Detection on the home screen to open the camera.
2

Point the camera at a face

The app will:
  • Detect faces in each camera frame
  • Generate embeddings for detected faces
  • Search the database for the nearest matching embedding
  • Display the person’s name if the similarity exceeds the threshold (0.3)
3

View performance metrics

Real-time latency metrics are displayed at the top of the screen:
  • Face Detection: Time to detect faces in the frame
  • Embedding: Time to generate FaceNet embeddings
  • Search: Time to find nearest neighbors
  • Spoof: Time for anti-spoofing validation

Understanding recognition results

The app uses cosine similarity to determine if a detected face matches someone in the database:
  • Distance > 0.3: Face is recognized and the person’s name is displayed
  • Distance ≤ 0.3: Face is not recognized, displays “Not recognized”
From ImageVectorUseCase.kt:89-101:
val distance = cosineDistance(embedding, recognitionResult.faceEmbedding)
// If the distance > 0.4, we recognize the person
// else we conclude that the face does not match enough
if (distance > 0.3) {
    faceRecognitionResults.add(
        FaceRecognitionResult(recognitionResult.personName, boundingBox, spoofResult),
    )
} else {
    faceRecognitionResults.add(
        FaceRecognitionResult("Not recognized", boundingBox, spoofResult),
    )
}
You can adjust this threshold by modifying the value in ImageVectorUseCase.kt:93. Lower values are more strict (fewer false positives), higher values are more lenient (fewer false negatives).

Anti-spoofing detection

The app includes liveness detection to prevent recognition using photos or videos. When a face is detected, the spoof detection result is displayed:
  • Real: The face appears to be a real person
  • Spoof: The face appears to be a photo, screen, or 3D model
This uses FASNet models from Silent-Face-Anti-Spoofing, which analyze the face at multiple scales to detect artifacts characteristic of fake faces.

Next steps

Configuration

Learn how to customize the FaceNet model, search algorithm, and face detector

Architecture

Understand how the app works under the hood

Build docs developers (and LLMs) love