This document will walk you through the steps for creating your Android app that runs a deep learning image classification model trained in Pocket AutoML and exported in TensorFlow Lite format

Overview

Pocket AutoML: Tutorial for Creating an Android App for Image Classification with Deep Learning

Translations

Overview

This document will walk you through the steps for creating your Android app that runs a deep learning image classification model trained in Pocket AutoML and exported in TensorFlow Lite format. The app will continuously classify whatever it sees from the device's back camera.

This tutorial is based on TensorFlow Lite image classification Android example application. For an explanation of its source code, see Explore the code.

If you have any issues following this tutorial please contact me (the creator of Pocket AutoML) via email at or by creating a GitHub issue.

Requirements

  • Android Studio 4.2 (installed on a Linux, Mac or Windows machine)

  • [if not using an Android emulator] an Android device in developer mode with USB debugging enabled and a USB cable (to connect an Android device to your computer)

Step 1. Train a model in Pocket AutoML

  • Install Pocket AutoML from Google Play Store and open it

  • Create a task e.g. Kittens or Puppies by pressing + button

  • Create a class e.g. Kittens

  • Add example images of the class by taking photos with a camera or picking them from a storage

  • Go back to the task view by pressing <- and repeat these steps for each class

  • Go back to the task view by pressing <-, switch to the MODEL tab and press TRAIN

Step 2. Export a model in TF Lite format from Pocket AutoML

  • Press EXPORT IN TENSORFLOW LITE FORMAT

  • Swipe down on the status bar at the top of the screen to open the notification drawer and track the export progress. The export takes few minutes.

  • When the export is done, press Share Model on a notification to open the standard Android Sharesheet, chose a sharing method to send a model to your PC (e.g. send it to yourself via an email app like GMail or store it on your cloud storage like Google Drive or Dropbox)

Step 3. Clone the Pocket AutoML example source code

Run the following command to get the demo application.

git clone https://github.com/OutSorcerer/pocket-automl-android-tutorial

Open the example source code in Android Studio. To do this, open Android Studio and select Open an existing project, setting the folder to pocket-automl-android-tutorial

Unlike the original example, this one uses only TFLite Support library to avoid confusion. An alternative is TensorFlow Lite Task Library, see the README of the original example for details.

Step 4. Build the Android Studio project

Select Build -> Make Project and check that the project builds successfully. The build.gradle file will prompt you to download any missing libraries.

Step 5. Install and run the app

Follow this step to make sure that the example runs successfully in your environment using its built-in models. The following step will demonstrate how to add your custom model from Pocket AutoML into the example app.

Run on a device

If you are willing to test the app on an Android device, connect the device to the computer and be sure to approve any ADB permission prompts that appear on your phone. Click Run -> Run 'app' from the main menu of Android Studio. Select the deployment target in the connected devices to the device on which the app will be installed. This will install the app on the device.

Run on an an emulator

If you are willing to test the app on an Android emulator

  • select Tools -> AVD Manager -> Create Virtual Device...
  • choose a device definition e.g. Pixel 2 (this controls its screen resolution and density)
  • click Next and select a system image, Android 11 (API level 30) is recommended, click Download on the selected system image, wait for download to complete, click Next and Finish
  • close the AVD Manager, select the newly created device in a list of available devices and click Run -> Run 'app' from the main menu of Android Studio

If you want to know more, see Create and manage virtual devices in Android documentation.

To test the app, open the app called Pocket AutoML Classify on your device or emulator. When you run the app the first time, the app will request permission to access the camera. Re-installing the app may require you to uninstall the previous installations.

Step 6. Add your model from Pocket AutoML into the example app

  • At this point you must have .zip file on your PC. Extract its contents into pocket-automl-android-tutorial/models/src/main/assets. You will have .tflite and .labels.txt there.

  • Open ClassifierPocketAutoML.java (by clicking Navigate -> Search Everywhere or pressing Shift twice and typing its name)

  • Replace the implementation of getModelPath with return " .tflite";

  • Replace the implementation of getLabelPath with return " .labels.txt";

  • Run the app, swipe up the bottom sheet to expand it and select Pocket_AutoML from the Model dropdown menu

  • You will see the the predicted class and the associated probability as a bold text under an image and probabilities of other classes below. Well done!

Next steps

Applications

Do you have a task at hand that can be solved with a help of an image classification model running in a mobile app? It could be sorting lego bricks or controlling a robot with hand gestures.

I will be excited to know what you have built with the help of Pocket AutoML and this tutorial and will add links to Play Store or GitHub into this document.

Other platforms

TF Lite can run not only on Android but on other platforms as well including iOS, embedded Linux devices like Raspberry Pi or Coral and microcontrollers.

Other model training methods

You can try other no-code or low-code deep learning solutions like Teachable Machine, Lobe, Create ML, Google AutoML Vision, Azure Custom Vision or TensorFlow Lite Model Maker.

Pocket AutoML uses transfer learning approach, you can also implement it yourself using a tutorial Transfer learning and fine-tuning in Google Colab.

Learning deep learning

If you want to learn how to train better models and have a systematic understanding or deep learning I recommend Deep Learning Specialization and Machine Learning Engineering for Production (MLOps) Specialization on Coursera.

Attribution statements

TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc. Android is a trademark of Google LLC.

License

Apache License 2.0

You might also like...
A simple covid-19 response application to give users an idea of the severity of their covid-19 status and profer steps to take based on the severity.
A simple covid-19 response application to give users an idea of the severity of their covid-19 status and profer steps to take based on the severity.

COVID-19 Response 🎡 A simple covid-19 response application to give users an idea of the severity of their covid-19 status and profer steps to take ba

jtx Board allows you to manage your Journals (like meeting minutes), Notes and Tasks in one Android app. The app is compatible with the iCal standard (RFC5545) and is integrated with DAVx5 to allow the synchronisation of entries through CalDAV. Healthify - An app to track your daily water intake and sleep and boost your work efficiency. Healthify is built using Kotlin and follows all modern android Development practices and hence is a good learning resource for beginners
Healthify - An app to track your daily water intake and sleep and boost your work efficiency. Healthify is built using Kotlin and follows all modern android Development practices and hence is a good learning resource for beginners

Healthify Healthify is an app to track your daily water intake and sleep and boost your work efficiency. Video Introduction 📹 This is a small introdu

Taskify - An app to manage your daily tasks and boost your productivity. Taskify is built using kotlin and follows all modern android Development practices and hence is a good learning resource for beginners
Taskify - An app to manage your daily tasks and boost your productivity. Taskify is built using kotlin and follows all modern android Development practices and hence is a good learning resource for beginners

Taskify Taskify is an app to manage your daily tasks and boost your productivity Video Introduction 📹 This is a small introduction video about Taskif

Candash - A simple Android app that turns your phone into an instrument cluster for your Tesla Model 3 and Y
Candash - A simple Android app that turns your phone into an instrument cluster for your Tesla Model 3 and Y

What is CANdash? CANdash is an Android app that turns your Android device into a

An educational android app that provides services like notes, online videos and visualization calculator to learn and understand deep concepts of DSA.
An educational android app that provides services like notes, online videos and visualization calculator to learn and understand deep concepts of DSA.

Aldo ALDO is a free education app for the young programmers who are desiring to master the concepts of Data Structure and Algorithms. ALDO offers prac

Deep AR android APP (Augmented reality) with face recognition and filters

quickstart-android-java To run the example Go to https://developer.deepar.ai, sign up, create the project and the Android app, copy the license key an

Astronomy Deep Sky Target Finder App for android.
Astronomy Deep Sky Target Finder App for android.

Algorithums and Astronomy Calculator App This is the android app for the algorithm running at athesto.ddns.net the repository for which is at: Algorit

Secret Codes is an Open Source application that allows you to browse through hidden codes of your Android phone.
Secret Codes is an Open Source application that allows you to browse through hidden codes of your Android phone.

####Secret Codes is an Open Source application that allows you to browse through hidden codes of your Android phone. This application will scan throug

Owner
Evgeniy Mamchenko
Evgeniy Mamchenko
An App based on MVVM architecture to track & store a user's runs using Google Maps, with options to view & sort the runs as per the user's choice along the with option to run the app in background.

An App based on MVVM architecture to track & store a user's runs using Google Maps, with options to view & sort the runs as per the user's choice along the with option to run the app in background.

Harshit Maheshwari 1 Jun 9, 2022
Age + Gender Estimation on Android - with TensorFlow Lite

Age + Gender Estimation in Android with TensorFlow Contents Python project Google Colab Notebooks Dataset Model ( Vanilla vs. Lite ) Android project O

Shubham Panchal 32 Dec 8, 2022
Detect-My-Mask: An android app which runs along with a TensorLite ML Model which detect whether a person is wearing mask or not.

Detect-My-Mask About : Detect My Mask is an Android Application which is powered by a TensorLite ML Model which is programmed and trained to detect wh

Siddharth Singh 5 Aug 8, 2022
Zotero In Your Pocket (Android App)

PocketZotero The project aims for providing a simple Android application to read the offline local Zotero databases. The idea is to ignore Zotero Clou

Saleh 1 Jan 6, 2022
Integration of ONNX with Kotlin JS - Deep Learning running in the browser

Integration of ONNX with Kotlin JS - Deep Learning running in the browser

londogard 5 Jul 22, 2022
UML model and code examples of design patterns for Kotlin/Native. The model is created with Astah.

Design Pattern Examples in Kotlin/Native Model and code examples of GoF Design Patterns for Kotlin/Native. This project is available for the following

Takaaki Teshima 3 Jun 27, 2022
Helper tool for calculating scales for Teenage Engineering Pocket Operator PO-33/133 & PO-35/137 series.

I heard you like Pocket Operators, so I made Pocket Scale Calculator for your Pocket Operator. This console app is a helper tool for calculating scale

null 9 Dec 6, 2022
Android Chinese TTS Engine Base On Tensorflow TTS , use for TfLite Models Test。安卓离线中文TTS引擎,在TensorflowTTS基础上开发,用于TfLite模型测试。

Chinese TTS TF Lite 介绍 使用Kotlin + JetPack Compose + Tensorflow Lite开发的TTS引擎,可以完全离线使用。 可选两种模型:FastSpeech和Tacotron,这两种模型均来自TensorFlowTTS 文字转拼音方法来自:Tenso

benjamin wan 116 Jan 2, 2023
Android-Java-App - Notepad app with user and password. SQL Lite

DVNote2 App Android-Java-App Notepad app with user and password Application made in Android Studio with Java language and SQLite database. How does it

DViga 1 Nov 6, 2021
A news application through which you can learn and browse all the news that interests you by choosing the country and type of news with the ability to browse and add some news to your favorites

MY-NEWS-Android A news application through which you can learn and browse all the news that interests you by choosing the country and type of news wit

Mahmoud ELramady 0 Nov 11, 2021