Age Classification App using Native Android. The quantized .tflite
model was trained and generated using TensorFlow Lite Model Maker.
Face databases used: UTKFace combined with Appa-Real.
- Screenshots
- Setting up and Running the Android project
- Android Dependencies and Versions used
- Model description
- Credits and Resources used
- License
Face images generated from ThisPersonDoesNotExist.
- Download and install Android Studio
- Clone this repository
git clone https://github.com/radualexandrub/Android-Age-Classification.git
- Search (within Windows Explorer) and Delete all
.iml
files within the project folder. This will solveUnsupported Modules Detected:
Error - Open Android Studio and click on "Configure" -> "SDK Manager" -> Check
Android 10.0 (Q)
and click "Apply", then wait for SDK to finish the installation. After that, click on "Configure" again, select "AVD Manager" -> "Create Virtual Device" -> "Pixel 3" -> Click onDownload
on "Q (API Level 29)" -> Wait for Download and Install -> Select "Q" -> click "Next", "Finish". (Note, you can also install other SDK/API versions, such as 26) - On Android Studio Welcome Screen, click on
Import Project (Gradle, Eclipse ADT, etc.)
(Do not click onOpen an Existing Project
) - Wait for Gradle to set up all the required packages
- If Error
Gradle sync failed: Module: 'app' platform 'android-29' not found.
is encountered, go toFile -> Settings -> System Settings -> Android SDK -> Check Android 10.0
and hitApply
. After installation, click onFile -> Sync Project with Gradle files
and wait for it's setup. - Click on
Run 'app' (Shift+F10)
- If Error
Unable to delete file
is encountered, just go to the specified directory and delete the file manually. Re-run the project.
Note: You can install the application directly on your Android Device via the provided .apk
file from this repository.
Android Studio 4.1.1
Build #AI-201.8743.12.41.6953283, built on November 5, 2020
Runtime version: 1.8.0_242-release-1644-b01 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
From build.gradle (app)
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.radu.GuessMyAge"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation('org.tensorflow:tensorflow-lite:0.0.0-nightly') { changing = true }
implementation('org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly') { changing = true }
implementation('org.tensorflow:tensorflow-lite-support:0.0.0-nightly') { changing = true }
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Classes used (based on The 12 Stages of Life article):
- 04 - 06 years old - early childhood
- 07 - 08 years old - middle childhood
- 09 - 11 years old - late childhood
- 12 - 19 years old - adolescence
- 20 - 27 years old - early adulthood
- 28 - 35 years old - middle adulthood
- 36 - 45 years old - midlife
- 46 - 60 years old - mature adulthood
- 61 - 75 years old - late adulthood
The model was trained with the default parameters ofimage_classifier
from tflite_model_maker
library.
INFO:tensorflow:Load image with size: 10674, num_label: 9, labels: 04-06, 07-08, 09-11, 12-19, 20-27, 28-35, 36-45, 46-60, 61-75.
Classes distribution by number of images (10 674 in total):
Model training:
Model evaluation:
loss, accuracy = model.evaluate(test_data)
34/34 [==============================] - 46s 1s/step - loss: 1.6116 - accuracy: 0.4373
Confusion Matrix:
NOTE: A small dataset of 4784 images from UTKFace was provided so you can run the AgeData.ipynb
notebook and train the model yourself. This small dataset can be found in this repository in age_data_small.zip
(~25MB). You can run the notebook using Google Colab, while uploading the .zip
to your Google Drive account.
- UTKFace Database with age, gender, and ethnicity annotations
- APPA-REAL Database that contains 7,591 images with associated real and apparent age labels
- TensorFlow Lite Model Maker Library
- Pre-made image classification App using Tensorflow Lite
- Access camera and media storage on Android (Java)
- Design:
Released under the MIT License.