ON-DEVICE AIAndroid Application

BlazeFaceONNX Android

Real-time face detection on Android using BlazeFace and ONNX Runtime. Supporting live camera inference and image-based detection directly on device.

KotlinAndroidONNX RuntimeComputer Vision

BLAZEFACE DETECTOR

Live Detection

Active
Face detectedBLAZEFACE

Model

ONNX

Runtime

On-device

01 / Overview

Project Overview

An Android implementation of BlazeFace that brings lightweight face detection to mobile devices using ONNX Runtime.

Face Detection on Android

This project integrates a pretrained BlazeFace ONNX model into an Android application. It supports real-time face detection from camera frames and image inference using pictures selected from device storage.

The application also separates debugging functionality from the main inference pipeline, making it easier to test camera input and model inference independently.

Model Information

ModelBlazeFace
FrameworkPyTorch → ONNX
RuntimeONNX Runtime
PlatformAndroid
ExecutionOn-device

02 / Capabilities

Application Features

Two primary inference workflows, supported by dedicated debugging utilities.

01

Real-time Camera Inference

Perform face detection continuously using live camera frames directly on Android devices.

02

Storage-based Inference

Select images from device storage and run face detection without requiring a live camera feed.

03

ONNX Runtime

Run the pretrained BlazeFace model using ONNX Runtime for on-device inference.

04

Dedicated Debugging

Separate camera checking and standalone inference pages to simplify development and troubleshooting.

03 / Architecture

Inference Workflow

The application supports two input sources that share the same model inference and post-processing stages.

Camera Inference

Real-time pipeline

01

Camera Input

Capture live camera frames.

02

Preprocessing

Prepare image frames for model input.

03

ONNX Runtime

Execute BlazeFace inference.

04

Post-processing

Decode predictions and filter detections.

05

Detection Results

Display detected faces.

Storage Inference

Image-based pipeline

01

Device Storage

Select an image from the device.

02

Preprocessing

Prepare the selected image for inference.

03

ONNX Runtime

Execute BlazeFace inference.

04

Post-processing

Decode predictions and filter detections.

05

Detection Results

Display detected faces.

04 / Development

Debugging Pages

Separate testing environments help isolate problems without running the complete inference pipeline.

01

Camera Inference

Real-time face detection using camera input.

camera_inference/
Inference
02

Read Storage

Load images from device storage for face detection.

read_storage/
Inference
03

Camera Check

Independent camera functionality and input debugging.

camera_check/
Debug
04

Simple Inference

Test ONNX model inference independently.

simple_inference/
Debug

Why separate debugging pages?

Camera Check focuses on camera functionality, while Simple Inference focuses on model execution. This separation helps identify whether an issue comes from camera handling, image preprocessing, or ONNX inference.

05 / Model Integration

From PyTorch to Android

The Android application uses the ONNX model exported from the companion BlazeFace conversion project.

Source Repository

BlazeFace ONNX

PyTorch model adaptation and ONNX conversion

View Source Repository
01

PyTorch

Original pretrained model

02

ONNX Export

Simplified ONNX-compatible implementation

03

Android

On-device model inference

Model Assets

blaze_face.onnxExported ONNX model
blaze_face.onnx.dataExternal tensor data

06 / Codebase

Project Structure

A look at the main Android source directories and model assets.

Source Tree

src/main/

▸ assets/
↳ blaze_face.onnx
↳ blaze_face.onnx.data
▸ blaze_face/
↳ camera_check/
↳ camera_inference/
↳ read_storage/
↳ simple_inference/
↳ BlazeFacePage.kt
▸ ui/theme/
▸ MainActivity.kt

Main Components

assets/

Model files and external tensor data.

blaze_face/

Inference, camera, storage, and debugging pages.

ui/theme/

Application theme configuration.

MainActivity.kt

Android application entry point.

Native Android

Kotlin implementation

Model execution is integrated into the Android application, allowing inference to run locally without requiring a separate inference server.

BlazeFace ONNX

Real-time face detection on Android devices.

View Model Repository
BlazeFace ONNX Android Project