This Android application demonstrates image classification using TensorFlow Lite. Users can select an image from the gallery, preprocess it, run inference using a TensorFlow Lite model, and display the predicted label along with probabilities.
The project utilizes TensorFlow Lite to perform image classification tasks on Android devices. It demonstrates how to integrate a pre-trained model into an Android app, handle image preprocessing, and display classification results to the user.
-
Select an image from the gallery for classification.
-
Preprocess the image to match the input requirements of the TensorFlow Lite model.
-
Run inference using a TensorFlow Lite model stored locally in the assets folder.
-
Display the predicted label and probabilities of the image classification.
- Android Studio (with Android SDK installed)
- Android device or emulator running API level 21 (Android 5.0) or higher
- Basic understanding of Android development and TensorFlow Lite
-
Clone Repository: Clone this repository to your local machine using Git:
git clone https://github.com/0oAVIRALo0/object-prediction-v1.git
-
Open Project in Android Studio: Open the cloned project in Android Studio.
-
Build Project: Build the project to ensure that all dependencies are resolved.
- Set Up TensorFlow Lite Model:
- Place your TensorFlow Lite model file (
classify.tflite
) in theapp/src/main/assets
directory. - Create a
labels.txt
file containing the class labels corresponding to your model's output.
- Place your TensorFlow Lite model file (
- Run the App:
- Connect your Android device or start an emulator.
- Click on the "Run" button in Android Studio to install and launch the app on the device/emulator.
- Select an Image:
- Click the "Select Image" button to choose an image from the gallery.
- View Results:
- Once the image is selected and processed, the predicted label and probabilities will be displayed on the screen.
MainActivity.kt
: Contains the main activity code for image selection, preprocessing, inference, and result display.activity_main.xml
: Layout file defining the UI components for the main activity.classify.tflite
: TensorFlow Lite model file (to be placed in theassets
directory).labels.txt
: Text file containing class labels for the model's output.
- Glide: For loading and displaying images efficiently.
- TensorFlow Lite: For running inference with a pre-trained model.
- OpenCV (via
org.opencv.android
): For image preprocessing (if applicable).
- Model Loading Error: If the app reports a model loading error, ensure that the
classify.tflite
model file exists in theassets
directory and is correctly named. - Image Processing Issues: Check the logcat output for any errors related to image processing, inference, or model output.
- TensorFlow Lite Documentation
- Glide Documentation
- Android Developers Guide