عکس parham29
Android application for classifying persian numbers(0-9) using Tensorflow, Android studio & kotlinKotlin
موضوع‌ها
۰
فورک‌ها
۲
ستاره‌ها
۵
تاریخ ایجاد
۷ مرداد ۱۳۹۷
آخرین بروزرسانی
حدود ۴ سال قبل
لایسنس
Other

Android Image Classifier

An android app for recognizing persian numbers with Tensorflow and android studio written in kotlin

Number 1 Number 3 Number 4
first test second test third test

Getting Started

Just clone the project.

Prerequisites

If you want to build your own image classifier you shoud install Tensorflow on your pc furthermore you need your own dataset. Note: python (version 3.+) required.

this command are for windows users:

C:\> pip3 install --upgrade tensorflow

To install the GPU version of TensorFlow, enter the following command:

C:\> pip3 install --upgrade tensorflow-gpu

Installing with Anaconda:

  1. Follow the instructions on the Anaconda download site to download and install Anaconda.
  2. Create a conda environment named tensorflow by invoking the following command:
    C:> conda create -n tensorflow pip python=3.5 
    
  3. Activate the conda environment by issuing the following command:
    C:> activate tensorflow
     (tensorflow)C:>  # Your prompt should change 
    
  4. Issue the appropriate command to install TensorFlow inside your conda environment. To install the CPU-only version of TensorFlow, enter the following command:
    (tensorflow)C:> pip install --ignore-installed --upgrade tensorflow 
    
    To install the GPU version of TensorFlow, enter the following command (on a single line):
    (tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu 
    

for more help visit this website.

Usage

Flow of the app is pretty simple:

  1. Take or pick a photo from storage.
  2. Classify numbers.
  3. Show the results and confidence(probability).

Code structure

The app consists of two main components:

  1. MainActivity which is responsible for taking a photo.
  2. ImageClassifier which classifies the photo.

Classifier

ImageClassifier properties:

  • inputName - the name of the classifier's input (the photo pixels goes in there),
  • outputName - the name of the classifier's output (the results can be found there),
  • imageSize - the size of the photo,
  • labels - the list of the labels (in our case "hot" and "not"),
  • imageBitmapPixels - the array with bitmap pixels (int values before normalization),
  • imageNormalizedPixels - the array with normalized pixels,
  • results - the list with the results,
  • tensorFlowInference - the TensorFlow API object (which is used for inference).

Classification process

For classifying photos the app is using retrained MobileNet model. The model can be found inside the assets folder together with the labels file.

Before classification the photo needs to be prepared to fit the input of the classifier which is 224x224 pixels. Because of that the photo is resized and cropped which is happening inside the ImageUtils.

Prepared photo is passed to the ImageClassifier. The class responsibilities are as follows:

  1. Nomalizing pixels of the photo - preprocessImageToNormalizedFloats() method.
  2. Run the classifier: tensorFlowInference.run(arrayOf(outputName), ENABLE_LOG_STATS)
  3. Get the results from the output: tensorFlowInference.fetch(outputName, results)

The results are then passed to the MainActivity and shown on the screen (including probability).

Special thanks to @makorowy