radualexandrub / Android-Age-Classification

Age Classification App using Native Android. The model was trained using TensorFlow Lite Model Maker.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Age Classification App

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.

Android Age Classification App

Contents

Screenshots

Android Age Classification App

Face images generated from ThisPersonDoesNotExist.

Setting up and Running the Android project

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 solve Unsupported 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 on Download 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 on Open 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 to File -> Settings -> System Settings -> Android SDK -> Check Android 10.0 and hit Apply. After installation, click on File -> 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 Dependencies and Versions used

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'
}

Model description

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):

Age Classification Images Distribution

Model training:

Loss and Accuracy Graph Age Classification

Model evaluation:

loss, accuracy = model.evaluate(test_data)
34/34 [==============================] - 46s 1s/step - loss: 1.6116 - accuracy: 0.4373

Test Age Classification

Confusion Matrix:

Age Classification 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.

Credits and Resources used

License

Released under the MIT License.

About

Age Classification App using Native Android. The model was trained using TensorFlow Lite Model Maker.

License:MIT License


Languages

Language:Jupyter Notebook 87.2%Language:Java 12.8%