项目作者: aslamanver

项目描述 :
TFLite-Image for Android - TensorFlow Lite inception model image library for Android
高级语言: Java
项目地址: git://github.com/aslamanver/tflite-image.git
创建时间: 2020-05-02T21:03:34Z
项目社区:https://github.com/aslamanver/tflite-image

开源协议:

下载


TFLite-Image

Let’s make machine learning simple.

Building a custom image classifier for your Android application using TensorFlow Lite.

https://i.imgur.com/lGObtU8.png



Build Status

TFLite-Image for Android - TensorFlow Lite inception model image library for Android

Move your trained model to asset folder or prepare a new image inception model using Google teachablemachine machine learning library.

You can use the sample inception quant or float model that we used in this project with 299 image dimension.

Initialization

Add the below repository into your project level build.gradle file.

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }

Add the below dependency into your module level build.gradle file.

  1. dependencies {
  2. ...
  3. implementation 'com.github.aslamanver:tflite-image:v1.0.9'
  4. }

Make sure you have added no compress config for your model files

  1. android {
  2. ....
  3. aaptOptions {
  4. noCompress "tflite"
  5. noCompress "lite"
  6. }
  7. }

Simple Usage

You need to pass the model file, label text and the model type.

  1. TFLiteImage tfLite = TFLiteImage.getInstance(activity, "your_model_file.tflite", "labels.txt", TFLiteImage.TYPE.QUANT, IMG_DIM_SIZE);
  2. List<Map<String, String>> results = tfLite.predictImage(image view or bitmap image);

IMG_DIM_SIZE is 299 or 224 according to your model, you can visualize your model data to check IMG_DIM_SIZE.

Inception model types

  1. TFLiteImage.TYPE.QUANT
  2. TFLiteImage.TYPE.FLOAT

Use case

  1. TFLiteImage tfLite = TFLiteImage.getInstance(this, "inception_quant.tflite", "labels.txt", TFLiteImage.TYPE.QUANT);
  2. List<Map<String, String>> results = tfLite.predictImage(binding.imgView);
  3. for (Map<String, String> map : results) {
  4. Log.e("RESULT", map.get("LABEL") + " - " + map.get("CONFIDENCE"));
  5. }

Result

  1. map.get("LABEL");
  2. map.get("CONFIDENCE");

Sunglass - 99%

Glass - 85%

Jeans - 70%

Demonstration

Screenshot

Test the sample app that I made for you: TFLite-Image-v1.0.apk


Made with ❤️ by Aslam Anver