Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

BeGiga TFLite Benchmark

An Android app for running and benchmarking TensorFlow Lite (LiteRT) object detection models on a real device: live camera, a picked image or a video, on CPU, GPU or NNAPI, with FPS and inference time measured as you go. Bring your own .tflite model and labels, or start with the built-in MobileNet SSD and YOLOv9 models.

Made by BeGiga. Licensed under GPL-3.0-or-later.

Camera detection Performance mode Inference settings
Live camera detection with boxes Performance mode showing FPS and inference time Bottom sheet with stats and inference settings
Model selection Model details Add custom model
Model list with built-in, local and imported models Model details dialog with tensors and labels Import dialog for a custom TFLite model

Features

  • Three input sources: live camera (back or front), a still image or a video from the system photo picker. The picker needs no storage permission, and the camera permission is only requested when you choose the camera.
  • CPU, GPU or NNAPI: switch delegates in one tap. If a delegate can't run the model, the app falls back to CPU and says why.
  • Model formats:
    • YOLO raw heads (v5 / v8 / v9 / v11 style): a single output ([1, 4+nc, N], with or without objectness) or separate box and score outputs, in either orientation. Non-max suppression runs in the app.
    • NMS-free YOLO exports with one [1, N, 6] output (x1, y1, x2, y2, score, class).
    • SSD models with the built-in TFLite_Detection_PostProcess op (boxes, classes, scores, count).
    • float32, float16, dynamic-range, and full int8 / uint8 quantised models. Quantised inputs and outputs are handled from the tensors' own scale and zero point.
  • Custom models: import any .tflite detector with a labels file from the app. The output format, input scaling, frame fitting (letterbox or stretch) and background label are detected automatically, and you can override them. The model is checked and run once before it's added.
  • Model details: for every model, see the file, size, input and output tensors (with quantisation), the detected settings, and the full labels list.
  • Benchmarking:
    • Live FPS, last and average inference time, and pre- and post-processing time.
    • Record benchmark captures 10 seconds of FPS and inference time. It saves a chart (.jpg) and the data (.csv) to Download/BeGigaBenchmark, or to a folder you pick once. Show in the saved message opens that folder.
    • Bulk benchmark runs several models one after another on the same image or video and saves one CSV and one chart that compare them.
    • Performance mode turns off the camera preview, the boxes and every per-frame UI update, so only the detection pipeline uses the CPU and GPU. Only FPS and inference time are shown.
  • Fit frame to model input: choose how a camera frame (usually 4:3) goes into the model input (usually 1:1, but any shape works). The app explains each mode with numbers for the current frame and model:
    • Letterbox keeps the whole frame and pads the rest with grey. Nothing is lost, but part of the input is padding, so objects are smaller.
    • Crop fills the whole input and cuts off the edges that don't fit. Objects are bigger, but the model can't see the cut parts: 25% of a 4:3 frame in a 1:1 model.
    • Stretch squeezes the frame to the input shape, which distorts it.
    • Auto uses the model's own mode: letterbox for YOLO, stretch for SSD.
  • What the model really sees: an overlay on the preview shows the model's input area, the letterbox padding (grey) and the parts cut off by crop (dark).
  • Camera rotation: rotate frames before inference, for a sideways-mounted camera or to test rotated input.
  • Full-screen preview with the system back gesture to exit.

Requirements

  • An Android device running Android 11 (API 30) or newer.
  • Android Studio with Android Gradle Plugin 9.4 support, and JDK 17 or newer (Android Studio's bundled JBR works).

Build and run

git clone <this repository>
  1. Open the project folder in Android Studio and let Gradle sync.
  2. Connect a device with USB debugging on, then press Run.

Or from a terminal:

./gradlew installDebug     # build and install on the connected device
./gradlew test             # JVM unit tests for the detection core (no device needed)

Using the app

  1. Choose the input at the top: Camera, Image or Video. Image and Video open the picker the first time.
  2. Choose where the model runs: CPU, GPU or NNAPI.
  3. Pull up the bottom sheet for the detailed stats, confidence threshold, camera fps target and display options, and to pick a model. Tap ⓘ next to a model for its details.
  4. Record benchmark (top bar) records 10 seconds and saves a chart and a CSV. Tap Show in the message to open the folder. To save somewhere else, use Benchmark files → Change folder in the sheet. The system folder picker opens once, and later recordings go to the same folder.
  5. Performance mode (input panel) gives the cleanest FPS and inference numbers.
  6. Bulk benchmark (above the model list in the sheet) compares several models in one go, see below.

With camera input, FPS can't be higher than the camera's frame rate (30 fps by default). Raise Camera fps target in the sheet, or use a video in performance mode, which runs as fast as the model allows.

A recorded benchmark chart: FPS and inference time for each second, with their averages. The CSV has one row per second. Each row also holds the run's settings, so files from different runs can be combined:

started,model,source,delegate,input,resize,second,fps,inference_ms
2026-10-28T17:20:05,MobileNet SSD (Quant),Camera,GPU,300x300 uint8,stretch,1,29.80,12.41

Benchmark chart with FPS and inference time over 10 seconds

Bulk benchmark

Compare several models on exactly the same input. Open Bulk benchmark above the model list and go through three steps:

  1. Input: pick an image or a video. For an image, choose how many measured runs each model gets (10, 30 or 100). For a video, every frame is measured, as fast as each model allows.
  2. Models: tick the models to compare. They run one after another, in list order.
  3. Options:
    • Name the benchmark and choose CPU, GPU or NNAPI.
    • Choose whether to also save the image or video with each model's detections drawn on it.
    • The confidence threshold and frame fitting come from the main settings.

Each model first runs 3 unmeasured warm-up passes. After that, the same times as in the live view are recorded: pre-processing, inference and post-processing. Decoding the video and drawing or encoding the annotated output are not counted. The live preview pauses while the benchmark screen is open, so nothing else competes for the CPU or GPU. Stop and save ends early and keeps what was measured. A model that can't load is listed with its error, and the others still run.

The results go into a new folder, <name>_<date>_<time>/, inside the benchmark save folder (Download/BeGigaBenchmark or the folder picked under Benchmark files):

File Contents
results.csv One row per run (image) or frame (video) of every model: model, delegate, input size, frame fitting, pre-processing / inference / post-processing / total time in ms, number of detections, and an error column for models that failed.
chart.jpg Average inference time and pipeline FPS of each model, as bar charts.
01_<model>.jpg / .mp4 Optional: each model's detections drawn on the image, or on the video at its original frame rate (H.264, up to 1280 px).
benchmark,started,input_file,input_type,model,model_file,delegate,input,resize,confidence,sample,preprocess_ms,inference_ms,postprocess_ms,total_ms,detections,error
Court test,2026-10-28T18:05:12,clip.mp4,video,MobileNet SSD (Quant),coco_ssd_mobilenet_v1_1.0_quant.tflite,GPU,300x300 uint8,stretch,0.50,1,1.84,9.71,0.42,11.97,3,

Pipeline FPS is 1000 / average total time: how many frames per second the model could process, including pre- and post-processing.

Adding your own model

Tap Add custom model at the end of the model list in the bottom sheet.

What Notes
Model A .tflite file with one RGB image input, [1, H, W, 3] or [1, 3, H, W], float32, uint8 or int8.
Labels Optional .txt, one class name per line in class-id order. Lines like 0 person are fine too. Without a file, labels packed in the model's metadata are used if it has any.
Output format Auto-detected from the output shapes: YOLO (raw or NMS-free) or SSD with post-processing.
Input scaling Auto: 0..1 for YOLO and -1..1 for SSD float models; int8 models take it from their quantisation. Can be set to 0..1, -1..1 or 0..255.
Fit frame to input Auto: letterbox for YOLO, stretch for SSD. Can be set to letterbox, crop or stretch, and changed any time in the app.
Background label A first label of ??? or background (common in SSD label maps) is skipped automatically.

Imported models are copied into the app's private storage, so they stay after a restart. Delete them from their details view.

Not supported:

  • Models that need TensorFlow ops (Flex / Select TF ops). Export with built-in TFLite ops only.
  • SSD models exported without the post-processing op, which output raw anchors.
  • Models with more than one input.

Exporting a YOLO model, for example with Ultralytics:

yolo export model=yolo11n.pt format=tflite            # float32 / float16
yolo export model=yolo11n.pt format=tflite int8=True data=coco8.yaml  # int8, calibrated on data=

Import the exported .tflite with a labels file listing the classes in order.

Bundling your own models

To build your own models into the app, put them in app/src/main/assets/local/, together with their label files and a models.json that lists them:

[
  {
    "name": "My detector (int8)",
    "file": "my_detector_int8.tflite",
    "labels": "my_labels.txt",
    "type": "YOLO",
    "description": "Optional text shown in the model details."
  }
]

type is YOLO or SSD. These fields are optional:

  • labelOffset: default 0; use 1 to skip a background label.
  • normalization: ZERO_TO_ONE, MINUS_ONE_TO_ONE or RAW_0_255. Defaults from the type.
  • resize: LETTERBOX, CROP or STRETCH. Defaults from the type.

The models show up in the list marked Local. If the folder doesn't exist, the app simply has no Local models.

Built-in models

Bundled in app/src/main/assets:

Model Type Input Notes
MobileNet SSD v1 (Quant), default SSD 300×300 uint8 COCO, NMS inside the model
MobileNet SSD v1 (Quant 2) SSD 300×300 uint8 Alternative quantised export
YOLOv9-t float32 / float16 / dynamic quant YOLO 640×640 COCO, 80 classes

How it works

frame (camera RGBA / bitmap)
  → rotate upright + letterbox / crop / stretch to the input    (one Canvas draw)
  → pack as float32 / uint8 / int8 through a lookup table
  → LiteRT Interpreter on CPU (XNNPACK) / GPU / NNAPI          ← "inference time"
  → dequantise outputs, decode (YOLO or SSD), class-aware NMS
  → boxes mapped back to the frame and drawn over the preview
  • utils/tf/DetectionCore.kt: preprocessing maths, YOLO and SSD decoders, NMS, format detection and the labels parser. It has no Android dependencies and is covered by JVM unit tests.
  • utils/tf/ObjectDetectionHelper.kt: the interpreter, delegates and per-frame pipeline.
  • utils/models/: built-in, local and imported model files, the model inspector and the custom model store.
  • utils/benchmark/: the bulk benchmark runner, the save folder (MediaStore or a picked folder), CSV files and charts.
  • utils/media/: image and video decoding, plus drawing boxes and encoding annotated videos.
  • ui/: the Jetpack Compose screen, dialogs and view models.

Stack: Kotlin 2.3, Jetpack Compose (Material 3), CameraX 1.5, LiteRT 1.4 (com.google.ai.edge.litert), coroutines, MPAndroidChart.

License

Copyright (C) 2026 BeGiga

This app is free software, licensed under the GNU General Public License v3.0 or later (GPL-3.0-or-later). See LICENSE for the full text. In short:

  • You may use, study, change and share it.
  • If you distribute it, changed or not (including as an APK), you must make the source available under the same licence and keep the copyright and licence notices.

Third-party licences

Component Licence
MobileNet SSD models (TensorFlow model zoo) Apache 2.0
YOLOv9 weights (WongKinYiu/yolov9) GPL-3.0
LiteRT, AndroidX, Jetpack Compose, CameraX, Kotlin coroutines Apache 2.0
MPAndroidChart Apache 2.0

All of these are compatible with GPL-3.0. Models you import or bundle yourself keep their own licences.

Author

Created and maintained by BeGiga: begiga.dev.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages