Skip to content

DaniZakaria63/MyGuavaScanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MyPlant

My Guava Leaf Disease Classifier

On-device CNN classification for guava leaf diseases using LiteRT & CameraX

Kotlin Compose LiteRT CameraX Hilt AGP minSdk targetSdk
License


Overview

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.


Features

  • πŸ“Έ 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

Classification Outputs

Label Display Name Severity
healthy_leaf Healthy Leaf βœ… Low
fruit_healthy Healthy Fruit βœ… Low
algal_leaf_spot Algal Leaf Spot ⚠️ Medium
insect_bite Insect Bite ⚠️ Medium
scab Scab ⚠️ Medium
black_mold Black Mold πŸ”΄ High
red_rust Red Rust πŸ”΄ High
scorch Leaf Scorch πŸ”΄ High
yellow_leaf_disease Yellow Leaf Disease πŸ”΄ High

Architecture

My Guava Scanner follows a multi-module architecture with clear separation of concerns:

Classification Result


Navigation Flow

Download ──► Camera ──► Settings
   β”‚                       β”‚
   └── (auto route) β”€β”€β”€β”€β”€β”€β”€β”˜    (pop back)

Tech Stack

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)

Getting Started

Prerequisites

  • 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

Setup

  1. Clone the repository

    git clone https://github.com/DaniZakaria63/MyGuavaScanner.git
    cd MyGuavaScanner
  2. Set the model download URL

    Create or edit gradle.properties and 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.

  3. Open in Android Studio

    Open the MyPlant/ directory. Android Studio will sync the Gradle project automatically.

  4. Run on device

    Select your connected device and hit Run (Shift+F10). The app downloads the CNN model on first launch via WorkManager.

Build Variants

  • 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:connectedAndroidTest

Model Details

The 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

Hardware Acceleration

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.

Inference Pipeline

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)

Screenshots

Classification Result


Testing

AI Module Tests

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)

App Module Tests

Instrumented tests in :app cover:

  • ModelDownloadWorker lifecycle β€” 16 test cases spanning success, retry, failure at all attempt counts (0–3), boundary conditions, and cache/settings integration
  • Fake ModelDownloader with SUCCESS/EMPTY_FILE/CORRUPTED/LARGE_FILE scenarios

Running Tests

# AI module
./gradlew :ai:connectedAndroidTest

# App module
./gradlew :app:connectedAndroidTest

# All modules
./gradlew connectedAndroidTest

Configuration

Settings Screen

  • 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

Gradle Properties

Property Description
URI_KUMAR_MODEL_CNN_256 URL for the .tflite model file

Contributing

This project is not open for contributions at this time. See License for usage restrictions.


License

MyPlant Personal Use License

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.


About

CNN guava disease detection via CameraX and LiteRT

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages