by arunponnusamy

arunponnusamy / gender-detection-keras

Gender detection (from scratch) using deep learning with keras and cvlib.

140 Stars 53 Forks Last release: about 1 year ago (v0.1) MIT License 25 Commits 1 Releases

Available items

No Items, yet!

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:

Gender detection (from scratch) using deep learning with keras and cvlib

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

face detection
on the images gathered from Google Images. It acheived around 96% training accuracy and ~90% validation accuracy. (20% of the dataset is used for validation)

Update :

Checkout the gender detection functionality implemented in cvlib which can be accessed through a single function call


Python packages

  • numpy
  • opencv-python
  • tensorflow
  • keras
  • requests
  • progressbar
  • cvlib

Install the required packages by executing the following command.

$ pip install -r requirements.txt

Note: Python 2.x is not supported

Make sure

is linked to Python 3.x (
pip -V
will display this info).


is linked to Python 2.7. Use
can be installed using the command
sudo apt-get install python3-pip

Using Python virtual environment is highly recommended.


image input

$ python -i 


$ python

When you run the script for the first time, it will download the pre-trained model from this link and place it under

directory in the current path.


command invokes default Python 2.7, use

Sample output :


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.

Additional packages

  • scikit-learn
  • matplotlib

Install them by typing

pip install scikit-learn matplotlib


Start the training by running the command

$ python -d 

(i.e) $ python -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

package. It will make things run a lot faster.


If you are facing any difficulty, feel free to create a new issue or reach out on twitter @ponnusamy_arun .

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.