Gender detection (from scratch) using deep learning with keras and cvlib.
The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:
The keras model is created by training SmallerVGGNet from scratch on around 2200 face images (~1100 for each class). Face region is cropped by applying
cvlibon the images gathered from Google Images. It acheived around 96% training accuracy and ~90% validation accuracy. (20% of the dataset is used for validation)
Checkout the gender detection functionality implemented in cvlib which can be accessed through a single function call
Install the required packages by executing the following command.
$ pip install -r requirements.txt
Note: Python 2.x is not supported
pipis linked to Python 3.x (
pip -Vwill display this info).
pipis linked to Python 2.7. Use
pip3can be installed using the command
sudo apt-get install python3-pip
Using Python virtual environment is highly recommended.
$ python detect_gender.py -i
$ python detect_gender_webcam.py
When you run the script for the first time, it will download the pre-trained model from this link and place it under
pre-traineddirectory in the current path.
pythoncommand invokes default Python 2.7, use
You can download the dataset I gathered from Google Images from this link and train the network from scratch on your own if you are interested. You can add more images and play with the hyper parameters to experiment different ideas.
Install them by typing
pip install scikit-learn matplotlib
Start the training by running the command
$ python train.py -d
(i.e) $ python train.py -d ~/Downloads/genderdatasetface/
Depending on the hardware configuration of your system, the execution time will vary. On CPU, training will be slow. After the training, the model file will be saved in the current path as
If you have an Nvidia GPU, then you can install
tensorflow-gpupackage. It will make things run a lot faster.