Skip to content

djain2405/Mobile-AI-Experiments

Repository files navigation

On-Device Image Classifier

A cross-platform mobile app demonstrating on-device AI for iOS and Android. This app performs real-time image classification completely locally on your device — no cloud, no network calls, 100% private.

What It Does

Choose any photo from your library, and the app instantly predicts what's in it with a confidence score. Everything runs locally using native ML frameworks (Core ML for iOS, TensorFlow Lite for Android).

Features

  • Fast ⚡ - Results appear instantly (~50ms)
  • Private 🔒 - Everything happens locally, photos never leave your device
  • Offline 🔋 - Works anywhere, no internet required
  • Accurate - Uses MobileNetV2 trained on ImageNet (1000 object classes)
  • Cross-Platform 📱 - Native implementations for both iOS and Android

Tech Stack

iOS

  • SwiftUI - Modern declarative UI framework
  • Core ML - Apple's machine learning framework
  • MobileNetV2 - Lightweight image classification model (~17MB)
  • iOS 14.0+ - Minimum deployment target

Android

  • Jetpack Compose - Modern declarative UI toolkit
  • TensorFlow Lite - Google's on-device ML framework
  • MobileNetV2 - Quantized model (~4MB)
  • Android 7.0+ (API 24+) - Minimum SDK version

How It Works

User selects photo → MobileNetV2 model → Prediction with confidence score
                     (runs on device)

The architecture is surprisingly simple:

  1. MobileNetV2 model runs locally via Core ML (iOS) or TensorFlow Lite (Android)
  2. Native UI handles the interface and image picker
  3. Image → Model → Predictions (all on device, ~50ms)

Project Structure

OnDeviceClassifierDemo/
├── OnDeviceClassifierDemo_iOS/          # iOS app
│   ├── OnDeviceClassifierDemo/
│   │   ├── ContentView.swift            # Main UI
│   │   ├── ImagePicker.swift            # Photo picker
│   │   └── Assets.xcassets
│   ├── MobileNetV2.mlmodel              # Core ML model (17MB)
│   ├── OnDeviceClassifierDemo.xcodeproj
│   └── README.md
│
├── OnDeviceClassifierDemo_android/      # Android app
│   ├── app/
│   │   └── src/
│   │       └── main/
│   │           ├── java/
│   │           ├── res/
│   │           └── assets/
│   │               └── mobilenet_v2.tflite  # TF Lite model (4MB)
│   ├── build.gradle
│   └── README.md
│
├── .gitignore                            # Combined iOS + Android
└── README.md                             # This file

Getting Started

iOS Setup

Prerequisites

  • Xcode 13.0+
  • iOS 14.0+ device or simulator
  • macOS 11.0+ (Big Sur or later)

Installation

cd OnDeviceClassifierDemo_iOS
open OnDeviceClassifierDemo.xcodeproj

Build and run in Xcode (Cmd + R)

See iOS README for detailed setup.

Android Setup

Prerequisites

  • Android Studio Arctic Fox or later
  • Android 7.0+ (API 24+) device or emulator
  • JDK 11+

Installation

cd OnDeviceClassifierDemo_android
./gradlew build

Open project in Android Studio and run.

See Android README for detailed setup.

On-Device vs Cloud AI

Cloud AI On-Device AI
Network required ✅ Works offline
~500ms latency ✅ ~50ms latency
Privacy concerns ✅ 100% private
✅ Infinitely scalable Battery constrained
✅ Complex models Limited model size

Use Cases

Perfect for:

  • Real-time image recognition
  • Privacy-sensitive applications
  • Offline functionality
  • Low-latency requirements

Demo

iOS

iOS Demo

Android

Android Demo

Tap "Choose Photo" → select any image → instant label appears with confidence score

Performance Comparison

Platform Model Size Inference Time Memory Usage
iOS (Core ML) 17MB ~50ms ~30MB
Android (TF Lite) 4MB (quantized) ~70ms ~25MB

Model Information

  • Model: MobileNetV2
  • Input: 224x224 RGB image
  • Output: 1000 ImageNet class labels with probabilities
  • Training Dataset: ImageNet
  • Accuracy: Top-1: ~71%, Top-5: ~90%

Future Enhancements

  • Support for custom ML models
  • Camera integration for real-time classification
  • History of predictions
  • Export results
  • Object detection support
  • Multi-object classification
  • Batch processing

License

MIT License - feel free to use this project for learning and building your own on-device AI apps!

Acknowledgments

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Resources

iOS

Android


If you found this helpful, consider starring the repo! ⭐

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors