Giter Site home page Giter Site logo

arunponnusamy / gender-detection-keras Goto Github PK

View Code? Open in Web Editor NEW
185.0 11.0 70.0 4.38 MB

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

Home Page: http://arunponnusamy.com

License: MIT License

Python 100.00%
gender-detection face-detection computer-vision machine-learning deep-learning keras python cvlib gender-classification

gender-detection-keras's Introduction

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 using cvlib 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 detect_gender().

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 pip is linked to Python 3.x (pip -V will display this info).

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

Using Python virtual environment is highly recommended.

Usage

image input

$ python detect_gender.py -i <input_image>

webcam

$ 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-trained directory in the current path.

(If python command invokes default Python 2.7, use python3 instead)

Sample output :

Training

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

Usage

Start the training by running the command

$ python train.py -d <path-to-dataset>

(i.e) $ python train.py -d ~/Downloads/gender_dataset_face/

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 gender_detection.model.

If you have an Nvidia GPU, then you can install tensorflow-gpu package. It will make things run a lot faster.

Help

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

gender-detection-keras's People

Contributors

arunponnusamy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gender-detection-keras's Issues

How to use other models?

How to use inception_resnet_v2 instead of smallervggnet? What modifications should I do in the code?

Layer vggnet

Hi I saw you used svvgnet, could I know what kind of configuration you gave him to get the model?
in particular how many weights and how many layers did you use to get this result?

gender_dataset.model

Hi,
Thank you for providing such a nice script to work with gender prediction. I am able to generate the gender_dataset.model file from my own dataset by using train.py. After generating the model,i am using it in pre-dataset folder to check the accurate and running the detect_gender_webcam.py script to predict the gender from video.
While running the script with my own dataset model it is throwing error like as below.

'''Using TensorFlow backend.
C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:469: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:470: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:471: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:472: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:473: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:476: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
Traceback (most recent call last):
File "C:\Users\Ashok\computer vision\threshold gender\detect_gender_webcam.py", line 20, in
model = load_model(model_path)
File "C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\models.py", line 270, in load_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\models.py", line 347, in model_from_config
return layer_module.deserialize(config, custom_objects=custom_objects)
File "C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers_init
.py", line 55, in deserialize
printable_module_name='layer')
File "C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\generic_utils.py", line 144, in deserialize_keras_object
list(custom_objects.items())))
File "C:\Users\Ashok\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\models.py", line 1406, in from_config
if 'class_name' not in config[0] or config[0]['class_name'] == 'Merge':
KeyError: 0
'''
Can you please guide me how to resolve this issue.

How to fine tuning SmallerVGGNet model

I'm machine learning beginner. I want to Fine tuning your pre-trained model. but I don't know How to load pre-trained model's weights and save weights in SmallerVGGNet. Can you advise me?

Web cam

HI. i have checked Your code and its working fine on still. When i ran the model of Webcam, it always displayed man and women as man. can you please provide some help?

This is final step query

File "train.py", line 87, in
H = model.fit_generator(aug.flow(trainX, trainY, batch_size=batch_size),
File "C:\Users\xyz\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\preprocessing\image.py", line 359, in flow
subset=subset
File "C:\Users\xyz\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\preprocessing\image.py", line 182, in init
dtype=dtype)
File "C:\Users\xyz\AppData\Local\Programs\Python\Python36\lib\site-packages\keras_preprocessing\image\numpy_array_iterator.py", line 117, in init
'with shape', self.x.shape)
ValueError: ('Input data in NumpyArrayIterator should have rank 4. You passed an array with shape', (0,))

Version of Libraries

Thanks for sharing your program source code! Can you tell me the versions of the libraries you can use? Many thanks

Feature Request

Hey Arun,

Great Lib ! Can you please share more info about "training our own models" ? How can i do that ?

Thank you in advance,

Dataset

Which dataset you have used sir..?
And what accuracy you got..?
I also trained one but giving training set 96 % acc but the predictions are not satisfying to me.?

Child face detection

Hello!
i want to ask a query. If we have to add another class to man and women, like if we want to add child face detection as 3rd class. how will we do that? and also guide about its training.

cpu

does it work with a cpu only?

Trouble with irl use of train.py script

Hey, you should really work on learning parametres, coz what I got using your default train.py was just kinda very unstable validation loss (jumping literally from 0.01 to 2.0+) during the whole learning process. It makes model unable to be used in real situations..
p_TZsxWC6IE
Снимок экрана от 2020-07-17 00-02-23

First is your variant, but isn`t my result better? Or you just threw that script like a template?

Detection as an API

Feature Request

Rewrite this as a Class so that it can be used in other scripts to perform gander recognition on the go.

P.S. Pretty good script btw. Really helpful.

SmallerVGGNet

Hi, you said you have trained on SmallerVGGNet, where i can find the Full VGGNet Framework? and What size does VGGNet takes input images?

issue with train.py

Getting an error, can you help me

Traceback (most recent call last):
File "train.py", line 12, in
from sklearn.model_selection import train_test_split
File "C:\Python\Python37\lib\site-packages\sklearn_init_.py", line 75, in
from .utils._show_versions import show_versions
File "C:\Python\Python37\lib\site-packages\sklearn\utils_show_versions.py", line 12, in
from ._openmp_helpers import _openmp_parallelism_enabled
ImportError: DLL load failed: The specified module could not be found.

no module named cvlib

but i have installed it and other error is Could not find a version that satisfies the requirement tensorflow (from -r requirements.txt (line 5)) (from versions: )
No matching distribution found for tensorflow (from -r requirements.txt (line 5))
i

DLL load failed: The specified module could not be found.

Using TensorFlow backend.
Traceback (most recent call last):

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\HP.spyder-py3\autosave\detect_gender.py", line 4, in
from keras.preprocessing.image import img_to_array

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\keras_init_.py", line 3, in
from . import utils

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\keras\utils_init_.py", line 6, in
from . import conv_utils

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\keras\utils\conv_utils.py", line 9, in
from .. import backend as K

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\keras\backend_init_.py", line 1, in
from .load_backend import epsilon

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\keras\backend\load_backend.py", line 90, in
from .tensorflow_backend import *

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in
import tensorflow as tf

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\tensorflow_init_.py", line 41, in
from tensorflow.python.tools import module_util as _module_util

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python_init_.py", line 40, in
from tensorflow.python.eager import context

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python\eager\context.py", line 35, in
from tensorflow.python import pywrap_tfe

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in
from tensorflow.python import pywrap_tensorflow

File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)

ImportError: Traceback (most recent call last):
File "C:\Users\HP\anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

profile face

how good is this for profile faces?
Also, to train on profile faces, all I have to do is augment the man folder of the dataset with profile face images and run the training? Is it that simple?

numpy version

I m facing a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. windows
which version is used?

Fast Speed

Hi there and thank you for this perfect lib!
Do you have any ideas, what can be make detect gender process more fast?
Regards.

Issue with train.py file

Hello arun,

Trying to execute train.py file , showing syntax in

(( File "train.py", line 26
ap.add_argument("-m", "--model", type=str, default="gender_detection.model",

 ^

SyntaxError: invalid syntax ))

What is the solution for this error.

Sorryyyyy I had spotted my mistake please reply for next issue I am facing.

Thanks
Krishna

Algorithm

Can you tell me which algorithm you have used and which all facial features you have used to distinguish between a man and a woman?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.