On-device CNN classification for guava leaf diseases using LiteRT & CameraX
My Guava Scanner is a privacy-first, fully offline Android application that identifies guava (Psidium guajava) leaf diseases using a custom CNN model running on-device via LiteRT (Google's edge AI runtime). Point your camera at a guava leaf β the app classifies the condition in real time with configurable FPS and hardware acceleration.
The classification model is based on the research documented in:
Kumar, R. (2024). Guava Leaf Disease Scanner using Deep Learning and Edge AI.
DOI: 10.13140/RG.2.2.12835.92961
All inference happens entirely on-device β no internet connection required after the initial model download. Your images never leave your phone.
- πΈ Real-time classification β Live camera feed with <100ms inference at 20 FPS on modern devices
- π¬ 9 disease classes β Algal Leaf Spot, Black Mold, Red Rust, Scab, Scorch, Insect Bite, Yellow Leaf Disease, plus healthy leaf & fruit
- β‘ Hardware acceleration β CPU, GPU, or NPU with automatic GPUβCPU fallback
- π· Gallery import β Analyze existing photos via the system photo picker
- π― Square crop overlay β Guides optimal framing for the 256Γ256 model input
- π¦ Flash & camera flip β Front/back camera toggle with flash control
- π Nerd info panel β Real-time metrics: inference time, memory usage, image dimensions
- βοΈ Configurable performance β Choose between 10 or 20 FPS classification rate
- π¨ Material 3 Design β Dynamic color theming with light/dark mode support
- π Fully offline β Model downloaded once via WorkManager, then zero network access
- π Exponential retry β Robust download with backoff strategy
| Label | Display Name | Severity |
|---|---|---|
healthy_leaf |
Healthy Leaf | β Low |
fruit_healthy |
Healthy Fruit | β Low |
algal_leaf_spot |
Algal Leaf Spot | |
insect_bite |
Insect Bite | |
scab |
Scab | |
black_mold |
Black Mold | π΄ High |
red_rust |
Red Rust | π΄ High |
scorch |
Leaf Scorch | π΄ High |
yellow_leaf_disease |
Yellow Leaf Disease | π΄ High |
My Guava Scanner follows a multi-module architecture with clear separation of concerns:
Download βββΊ Camera βββΊ Settings
β β
βββ (auto route) ββββββββ (pop back)
| Category | Technology | Version |
|---|---|---|
| Language | Kotlin | 2.3.20 |
| UI | Jetpack Compose + Material 3 | 2026.03.00 BOM |
| Navigation | Navigation3 Compose | 1.1.0 |
| Camera | CameraX (core, lifecycle, camera2, compose) | 1.6.0 |
| Inference | LiteRT (Google AI Edge) | 2.1.0 |
| DI | Dagger Hilt | 2.57.1 |
| Networking | OkHttp + Retrofit + kotlinx-serialization | 5.3.2 / 3.0.0 |
| Async | Kotlin Coroutines | 1.10.2 |
| Background | WorkManager + Hilt integration | 2.11.2 |
| Persistence | Room + DataStore Preferences | 2.8.4 / 1.2.1 |
| Image Loading | Coil Compose | 2.7.0 |
| Animation | Lottie Compose | 6.6.2 |
| Logging | Timber | 5.0.1 |
| Build | Android Gradle Plugin | 9.1.0 |
| Minimum SDK | Android 7.0 (API 24) | |
| Target SDK | Android 16 (API 36) |
- Android Studio Meerkat or later (with AGP 9.1+)
- JDK 21
- Android SDK 36
- A physical Android device (Android 7+) β the camera and GPU acceleration require real hardware
-
Clone the repository
git clone https://github.com/DaniZakaria63/MyGuavaScanner.git cd MyGuavaScanner -
Set the model download URL
Create or edit
gradle.propertiesand add:URI_KUMAR_MODEL_CNN_256="<your-model-url>"
The model is a TensorFlow Lite file (
best_cnn_model256.tflite) hosted at your endpoint or Google Drive. See Model Details. -
Open in Android Studio
Open the
MyPlant/directory. Android Studio will sync the Gradle project automatically. -
Run on device
Select your connected device and hit Run (
Shift+F10). The app downloads the CNN model on first launch via WorkManager.
- Debug β Timber logging enabled, debug tensor output printed to Logcat
- Release β Minification disabled (configurable), proguard rules available
# Build release APK
./gradlew :app:assembleRelease
# Run instrumented tests
./gradlew :ai:connectedAndroidTest
./gradlew :app:connectedAndroidTestThe classifier uses a custom CNN architecture trained specifically for guava leaf disease classification.
- Architecture: Convolutional Neural Network (custom design)
- Input size: 256 Γ 256 pixels (RGB)
- Normalization:
(pixel - 127.5) / 127.5 - Framework: TensorFlow β LiteRT (TFLite format)
- File name:
kumar-v1.0.0-256x256.tflite - Classes: 9 output classes
- Reference: DOI: 10.13140/RG.2.2.12835.92961
| Accelerator | Code | Fallback |
|---|---|---|
| CPU | 0 |
None (default) |
| GPU | 1 |
Automatic β CPU |
| NPU | 2 |
None |
The GPU fallback mechanism in PlantRepository.getModel() catches CompiledModel.create() failures and retries with Accelerator.CPU, ensuring broad device compatibility.
Camera frame / Gallery image
β
βΌ
Bitmap (any size)
β
βΌ
Scale to 256Γ256
β
βΌ
Rotate (0/90/180/270Β°)
β
βΌ
Normalize: (RGB - 127.5) / 127.5
β
βΌ
LiteRT CompiledModel.run()
β
βΌ
Argmax over 9 outputs
β
βΌ
GuavaHealthResult (label + severity)
Instrumented tests in :ai cover:
- Model download from network endpoint (
KumarModelDownloaderTest) - Full inference pipeline with 6 sample images at 4 rotations (
PlantClassifierTest) - Determinism verification (same input β same output across runs)
- Error handling (empty model, invalid labels, corrupted files)
- Label list integrity (9 classes, no duplicates)
Instrumented tests in :app cover:
ModelDownloadWorkerlifecycle β 16 test cases spanning success, retry, failure at all attempt counts (0β3), boundary conditions, and cache/settings integration- Fake
ModelDownloaderwith SUCCESS/EMPTY_FILE/CORRUPTED/LARGE_FILE scenarios
# AI module
./gradlew :ai:connectedAndroidTest
# App module
./gradlew :app:connectedAndroidTest
# All modules
./gradlew connectedAndroidTest- Hardware Accelerator: CPU (default) / GPU / NPU β GPU availability depends on
GLES_VERSION >= 3.0 - Classification FPS: 10 (balanced) / 20 (performance) β controls how often the camera frame is analyzed
| Property | Description |
|---|---|
URI_KUMAR_MODEL_CNN_256 |
URL for the .tflite model file |
This project is not open for contributions at this time. See License for usage restrictions.
Copyright Β© 2024 WALAWE (Dani Zakaria). All rights reserved.
Personal use is permitted β you may download, install, and use this application for your own personal, non-commercial purposes free of charge.
Any other use requires explicit written permission from the author. This includes, but is not limited to:
- Commercial use, distribution, or monetization in any form
- Modification, adaptation, or creation of derivative works
- Redistribution of the source code or compiled binaries (modified or unmodified)
- Integration into other products or services
- Academic or research publication without attribution
To obtain permission, contact:
Dani Zakaria β dani.zakaria@proton.me
Unauthorized use, distribution, or modification of this software is strictly prohibited and may result in legal action.

