https://github.com/aslamanver/tflite-image
TFLite-Image for Android - TensorFlow Lite inception model image library for Android
https://github.com/aslamanver/tflite-image
ai android image-classification machine-learning model tensorflow tensorflow-lite tflite-image training
Last synced: 2 months ago
JSON representation
TFLite-Image for Android - TensorFlow Lite inception model image library for Android
- Host: GitHub
- URL: https://github.com/aslamanver/tflite-image
- Owner: aslamanver
- Created: 2020-05-02T21:03:34.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-23T16:10:05.000Z (over 3 years ago)
- Last Synced: 2025-10-22T06:37:36.592Z (8 months ago)
- Topics: ai, android, image-classification, machine-learning, model, tensorflow, tensorflow-lite, tflite-image, training
- Language: Java
- Homepage: https://aslamanver.github.io/tflite-image
- Size: 307 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TFLite-Image
Let's make machine learning simple.
Building a custom image classifier for your Android application using TensorFlow Lite.

[](https://jitpack.io/#aslamanver/tflite-image)
[](https://github.com/aslamanver/tflite-image/actions)
[](https://travis-ci.com/aslamanver/tflite-image)
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](https://teachablemachine.withgoogle.com) machine learning library.
You can use the sample inception quant or float model that we used in this project with 299 image dimension.
- [inception_quant.tflite](https://github.com/aslamanver/tflite-image/blob/master/app/src/main/assets/inception_quant.tflite)
- [inception_float.tflite](https://github.com/aslamanver/tflite-image/blob/master/app/src/main/assets/inception_float.tflite)
- [labels.txt](https://github.com/aslamanver/tflite-image/blob/master/app/src/main/assets/labels.txt)
### Initialization
Add the below repository into your project level build.gradle file.
```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Add the below dependency into your module level `build.gradle` file.
```gradle
dependencies {
...
implementation 'com.github.aslamanver:tflite-image:v1.0.9'
}
```
Make sure you have added no compress config for your model files
```gradle
android {
....
aaptOptions {
noCompress "tflite"
noCompress "lite"
}
}
```
### Simple Usage
You need to pass the model file, label text and the model type.
```java
TFLiteImage tfLite = TFLiteImage.getInstance(activity, "your_model_file.tflite", "labels.txt", TFLiteImage.TYPE.QUANT, IMG_DIM_SIZE);
List> 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
```java
TFLiteImage.TYPE.QUANT
TFLiteImage.TYPE.FLOAT
```
### Use case
```java
TFLiteImage tfLite = TFLiteImage.getInstance(this, "inception_quant.tflite", "labels.txt", TFLiteImage.TYPE.QUANT);
List> results = tfLite.predictImage(binding.imgView);
for (Map map : results) {
Log.e("RESULT", map.get("LABEL") + " - " + map.get("CONFIDENCE"));
}
```
Result
```java
map.get("LABEL");
map.get("CONFIDENCE");
```
Sunglass - 99%
Glass - 85%
Jeans - 70%
### Demonstration
[](/screenshots/1.png)
Test the sample app that I made for you: [TFLite-Image-v1.0.apk](https://drive.google.com/file/d/1YFNNx25bvUhahTkaL_TrRV3MLaQCXedT/view?usp=sharing)
Made with ❤️ by Aslam Anver