mandreshope / Age-Gender-Classification-on-RaspberryPi4-with-TFLite-PyQt5

Age and Gender classification in real-time, using Convolutional Neural Networks (with MobileNet v1 network using a converted .tflite model), on Raspberry Pi 4. The app is wrapped in PyQt5 interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Real-Time Age and Gender Classification on RaspberryPi4 using TFLite and PyQt5 Interface

Automatic age and gender classification in real-time, using Convolutional Neural Networks (based on MobileNet v1 network), fitted on Raspberry Pi 4 model using a converted .tflite model. The application is wrapped in a simple and modern UI using PyQt5.

GitHub repo size GitHub stars GitHub forks GitHub license

Contents:

Demo

Screenshots

About this App

Automatic age and gender classification can be used in a large number of applications, especially in intelligent human-computer interfaces, as well as in biometrics, visual surveillance, limited access to multimedia content, and for commercial applications such as self-checkouts.

This app is proposed to be an optimal solution for the classification of age and gender in real-time, using a limited resource platform (Raspberry Pi 4 system), which does not have graphical acceleration. The app uses Convolutional Neural Networks (CNNs) in order to predict the classes. The network used is MobileNet v1 with 4 Million parameters, which is optimal in terms of resources used (compared to other CNN networks, see the table I made below).

ARCHITECTURE TOP 1 ACCURACY NUMBER OF PARAMETERS SIZE (MB) YEAR
MobileNet-224 0.706 4M 16 2017
Inception V1 0.698 5M 2014
Inception V2 0.748 11M 2015
Xception 0.790 22M 88 2016
Inception V3 0.779 23M 92 2015
ResNet-50 0.721 26M 98 2015
AlexNet - 7CNNs 0.633 60M 2012
VGG-16 0.744 138M 528 2014
VGG-19 0.745 144M 549 2014

This was a small part of my final project to obtain my Bachelor's Degree at Faculty of Electronics, UPB, Computer Science department. The final grade for the project was 10/10.

About the Model used

Classes used:

  • 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
  • female gender
  • male gender

Face datasets used: UTKFace combined with Appa-Real.

The model was trained using MobileNet v1 network using 10k images from UTKFace and Appa-Real databases, along with the following parameters:

  • Optimizer: Stochastic Gradient Descent (SGD)
  • Batch Size: 2
  • Learning Rate: 10e-4
  • Accuracy on test: 49.63%
  • Accuracy on test with 2 years overlapping limits: 68.82%

App main features

The interface is simple to use, with only three buttons on the main menu:

  • open the attached camera on the Raspberry Pi, which captures the frames in real-time and at the same time locates the human faces by drawing a square around them, classifying the person according to age and gender
  • open a single picture from a local directory, for which the age and gender classification will be made automatically if there is a person in the picture
  • select a local directory that contains only images, following that the user can view in cascade the classified images

Prerequisites and Versions Used

  • Raspberry Pi 3 or 4 or Any Linux System based on ARM chip with at least 512MB RAM.
  • Python version 3.7 or higher
  • PyQt5 version 5.11.3 or higher (usually pre-installed with Python)
  • NumPy version 1.16.2 or higher
  • TensorFlow version 1.15.0 and OpenCV version 3.4.3 (see Installation Process below)

Notes for me to find out these versions:

python3 --version
pip3 freeze # for numpy, tensorflow
python3 -c "import cv2; print(cv2.__version__)"
python3 -c "from PyQt5.Qt import PYQT_VERSION_STR; print(PYQT_VERSION_STR)"
python3 -c "import tensorflow as tf; print(tf.version.VERSION)"

Installation Process

  • Install NumPy: pip3 install numpy.
  • Install Pillow pip3 install Pillow.
  • Install OpenCV for Raspberry Pi from this tutorial (or run the commands bellow). If error undefined symbol __atomic_fetch_add_8  is encountered, try running pip install opencv-contrib-python==3.4.3.18 or pip install opencv-contrib-python==4.1.0.25.
# (optional) Update OS system:
sudo apt update
sudo apt upgrade

# Install dependencies
sudo apt install build-essential cmake pkg-config
sudo apt install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt install libxvidcore-dev libx264-dev
sudo apt install libgtk2.0-dev libgtk-3-dev
sudo apt install libatlas-base-dev gfortran

# Install OpenCV and extra dependencies for OpenCV and Camera
pip3 install opencv-python
sudo apt install libqtgui4
sudo modprobe bcm2835-v4l2
sudo apt install libqt4-test
  • Install TensorFlow library from this tutorial (or run the commands bellow).
git clone https://github.com/PINTO0309/Tensorflow-bin.git
cd Tensorflow-bin
pip3 install tensorflow-1.13.1-cp35-cp35m-linux_armv7l.whl

# test
python3 -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

If git is not installed, run sudo apt install git.

You can also refer to TensorFlow Lite official guide.

Running the app

Simply clone this repository then run using python3:

git clone https://github.com/radualexandrub/Age-Gender-Classification-on-RaspberryPi4-with-TFLite-PyQt5.git RaduApp
cd RaduApp
python3 AgeClass_MainApp.py

Find me on my Social's

My portfolio: radubulai.com
My blog: CodingTranquillity

radualexandrub   radu-alexandru-bulai   radualexandrub   RaduAlexandruB   RaduAlexandruB   RaduAlexandru  

LICENSE

Copyright © 2020, Radu-Alexandru Bulai. Released under the MIT license.

About

Age and Gender classification in real-time, using Convolutional Neural Networks (with MobileNet v1 network using a converted .tflite model), on Raspberry Pi 4. The app is wrapped in PyQt5 interface.

License:MIT License


Languages

Language:Jupyter Notebook 94.3%Language:Python 5.7%