TensorFlow Lite Helper for Android to help getting started with TesnorFlow.

Overview

TensorFlow Lite Helper for Android

This library helps with getting started with TensorFlow Lite on Android. Inspired by TensorFlow Lite Android image classification example.

This is an experimental library and subject to change. It's written entirely in Kotlin and powered by TensorFlow Lite.

The library provides helper class for Image Classification at the minimum usage. In future releases, the library may provide helpers for Object Detection and Smart Reply.

Download

Gradle

implementation 'com.neno0o.tflitehelper:imageclassification:0.0.1'

Maven

<dependency>
  <groupId>com.neno0o.tflitehelper</groupId>
  <artifactId>imageclassification</artifactId>
  <version>0.0.1</version>
  <type>pom</type>
</dependency>

Add TensorFlow Lite library

implementation "org.tensorflow:tensorflow-lite:latest_version"

Usage

Image Classification

To get started with Image Classification, get instance by providing your model and label paths in the asset folder to create factory method

private lateinit var imageClassification: ImageClassification

imageClassification = ImageClassification.create(
                classifierModel = ClassifierModel.QUANTIZED,
                assetManager = assets,
                modelPath = MODEL_PATH,
                labelPath = LABEL_PATH
            )

To classify (recognize) an image, call classifyImage with bitmap..

val results = imageClassification.classifyImage(bitmap)

The results are list of Recognizable.

The sample app uses Coroutines while initializing ImageClassification and when calling classifyImage to not block the main thread.

val results = async { imageClassification.classifyImage(bitmap) }

withContext(Dispatchers.Main) {
    object_name.text = results.await().toString()
}

Check out the sample app for more details.

ImageClassification uses default input size 224, you should override this value depending on your model. Also, you can override the number of results that will be returned, and the default confidence threshold.

imageClassification = ImageClassification.create(
                classifierModel = ClassifierModel.QUANTIZED,
                assetManager = assets,
                modelPath = MODEL_PATH,
                labelPath = LABEL_PATH,
                inputSize = YOUR_MODEL_INPUT_SIZE,
                numberOfResults = 10,
                confidenceThreshold = .5f
            )

To configure the Interpreter via the Interpreter.Options, create instance of Interpreter.Options alongside its configurations such as the number of threads that are used to configure the Interpreter, and use it in create method.

private lateinit var imageClassification: ImageClassification

val interpreterOptions = Interpreter.Options()
interpreterOptions.setNumThreads(4)
interpreterOptions.setUseNNAPI(true) // If Android device supports NNAPI

imageClassification = ImageClassification.create(
                classifierModel = ClassifierModel.QUANTIZED,
                assetManager = assets,
                modelPath = MODEL_PATH,
                labelPath = LABEL_PATH,
                interpreterOptions = interpreterOptions
            )

License

Copyright 2019 Ahmed Gamal. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You might also like...
An Android app to help runners to find races in France
An Android app to help runners to find races in France

Onirun Onirun was an Android app to help runners to find races in France. We were a team of 4 people to create the project on our free time : me for t

A simple and easy adapter for RecyclerView. You don't have to make adapters and view holders anymore. Slush will help you.
A simple and easy adapter for RecyclerView. You don't have to make adapters and view holders anymore. Slush will help you.

한국어 No more boilerplate adapters and view holders. Slush will make using RecyclerView easy and fast. The goal of this project is to make RecyclerView,

 Movie app that receives popular movies and allows the user to search for the specific movie through the Rest API with help of retrofit library &MVVM architecture.
Movie app that receives popular movies and allows the user to search for the specific movie through the Rest API with help of retrofit library &MVVM architecture.

MovieClue Millions of movies, TV shows and people to discover. Explore now Movie app that recieves popular movies and allow the user to search for spe

An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines.

one An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines. Feature Transform different data structs to one. {errorCode, d

Koin Annotations - help declare Koin definition in a very fast and intuitive way, and generate all underlying Koin DSL for you

The goal of Koin Annotations project is to help declare Koin definition in a very fast and intuitive way, and generate all underlying Koin DSL for you. The goal is to help developer experience to scale and go fast 🚀 , thanks to Kotlin Compilers.

Backend Project to support providing help to refugees

Project Project to implement the matching of guests and hosts, with special attention to verification of matches. Get it, run it: In order to build th

Android MVVM framework write in kotlin, develop Android has never been so fun.

KBinding 中文版 Android MVVM framework write in kotlin, base on anko, simple but powerful. It depends on my another project AutoAdapter(A library for sim

Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.
Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.

Klimatic Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android. Built using Android Architectu

Oratio Library for Android Studio helps you simplify your Android TTS codes

Oratio Oratio is a library for Android Studio. This library is useful to a number of developers who are currently making apps using android TTS(Text-T

Releases(0.0.1)
Owner
Ahmed Gamal
Ahmed Gamal
A lightweight Kotlin friendly wrapper around Couchbase lite for Android.

CouchBaseKtx ?? Work In-Progress ?? A lightweight Kotlin friendly wrapper around Couchbase-lite for Android Read up a little bit of documentation abou

Jaya Surya Thotapalli 5 Feb 15, 2022
KaMP Kit by Touchlab is a collection of code and tools designed to get your mobile team started quickly with Kotlin Multiplatform.

KaMP Kit Welcome to the KaMP Kit! About Goal The goal of the KaMP Kit is to facilitate your evaluation of Kotlin Multiplatform (aka KMP). It is a coll

Touchlab 1.7k Jan 3, 2023
A set of highly-opinionated, batteries-included gradle plugins to get you started building delicious multi-module Kotlin projects

Sourdough Gradle What is Sourdough Gradle? Sourdough is a set of highly opinionated gradle plugins that aim to act as the starter for your Kotlin proj

Backbone 0 Oct 3, 2022
[Android Library] A SharedPreferences helper library to save and fetch the values easily.

Preference Helper A SharedPreferences helper library to save and fetch the values easily. Featured in Use in your project Add this to your module's bu

Naveen T P 13 Apr 4, 2020
Android SharedPreferences Helper

PocketDB Android SharedPreferences Helper This is SharedPreferences Helper like a database noSql. Support AES encryption Latest Version Download depen

Muhammad Utsman 9 Jun 20, 2021
AppCode helper for Kotlin/Native and Xcode

Kotlin Xcode compatibility Gradle plugin The plugin is used by AppCode to set up Kotlin/Native project along with Xcode Sources A multi-build sample w

Kotlin 21 Oct 23, 2022
Android Ptrace Inject for all ABIs and all APIs. Help you inject Shared Library on Android.

Android Ptrace Inject 中文可以参考我的注释内容进行理解 我写的注释相对来说比较全面了 How to build Make sure you have CMake and Ninja in your PATH Edit CMakeLists.txt. Set ANDROID_ND

SsageParuders 65 Dec 19, 2022
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

Klejvi Kapaj 7 Dec 27, 2022
👋 A common toolkit (utils) ⚒️ built to help you further reduce Kotlin boilerplate code and improve development efficiency. Do you think 'kotlin-stdlib' or 'android-ktx' is not sweet enough? You need this! 🍭

Toolkit [ ?? Work in progress ⛏ ?? ??️ ?? ] Snapshot version: repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots") }

凛 35 Jul 23, 2022