This directory contains Android image segmentation samples demonstrating how to use LiteRT (Google's new runtime for TensorFlow Lite) with different hardware accelerators. The samples perform multi-class image segmentation to identify and classify objects in images.
Image segmentation is a computer vision task that involves partitioning an image into multiple segments or regions, where each pixel is assigned to a specific class. These samples demonstrate real-time segmentation on Android devices using optimized neural network models.
A standard implementation supporting CPU and GPU acceleration for broad device compatibility.
Features:
-
CPU and GPU delegate support
-
Real-time camera and gallery image segmentation
-
21-class segmentation (person, car, bicycle, etc.)
-
Compatible with a wide range of Android devices
Performance on Samsung S25 ULtra:
-
CPU: 120-140ms per frame
-
GPU: 40-50ms per frame
An advanced implementation with Neural Processing Unit (NPU) support for significantly faster inference on compatible devices.
Features:
-
CPU, GPU, and NPU delegate support
-
Optimized for Qualcomm and MediaTek NPU hardware
-
Same 21-class segmentation as CPU/GPU version
Performance on Samsung S25 Ultra:
-
CPU: 120-140ms per frame
-
GPU: 40-50ms per frame
-
NPU: 6-12ms per frame (10-20x faster than CPU!)
An iOS SwiftUI implementation using the LiteRT CompiledModel Swift API (import LiteRT).
Features:
- Native Swift
Environment,CompiledModel, andTensorBufferAPIs - CPU (XNNPACK delegate) and GPU (
LiteRtMetalAccelerator) backend switching - Real-time camera and gallery image segmentation
An iOS SwiftUI implementation using the TensorFlow Lite Interpreter Swift API (import TensorFlowLite) integrated into the LiteRT Swift Package.
Features:
- Native Swift
Interpreter,MetalDelegate, andCoreMLDelegateAPIs - 3-way hardware backend switching: CPU (XNNPACK), GPU (
MetalDelegate), and NPU / Apple Neural Engine (CoreMLDelegate) - Real-time camera and gallery image segmentation
-
Input: 256x256x3 RGB image
-
Output: 256x256x6 segmentation mask
-
Model format: TensorFlow Lite (.tflite)
-
LiteRT (
com.google.ai.edge.litert) -
Android CameraX: For camera functionality
-
Jetpack Compose: For modern UI
-
Kotlin Coroutines: For asynchronous operations
Note
The LiteRT runtime and dependency versions in these samples are pinned as a baseline reference. When testing newer releases, nightly builds, or custom-built binaries, update the corresponding project configurations to match your requirements.
-
ImageSegmentationHelper: Core segmentation logic and model management
-
MainActivity: UI orchestration with camera/gallery tabs
-
MainViewModel: State management and data flow
-
TensorUtils: Utilities for tensor inspection and debugging
When contributing to these samples:
-
Follow existing code style and patterns
-
Test on multiple devices and accelerators
-
Update documentation for any new features
-
Include performance metrics for optimizations