An android app for recognizing persian numbers with Tensorflow and android studio written in kotlin
Number 1 | Number 3 | Number 4 |
---|---|---|
![]() |
![]() |
![]() |
Just clone the project.
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:
- Follow the instructions on the Anaconda download site to download and install Anaconda.
- Create a conda environment named tensorflow by invoking the following command:
C:> conda create -n tensorflow pip python=3.5
- Activate the conda environment by issuing the following command:
C:> activate tensorflow
(tensorflow)C:> # Your prompt should change
- 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.
Flow of the app is pretty simple:
- Take or pick a photo from storage.
- Classify numbers.
- Show the results and confidence(probability).
The app consists of two main components:
MainActivity
which is responsible for taking a photo.ImageClassifier
which classifies the photo.
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).
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:
- Nomalizing pixels of the photo -
preprocessImageToNormalizedFloats()
method. - Run the classifier:
tensorFlowInference.run(arrayOf(outputName), ENABLE_LOG_STATS)
- 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