Giter VIP home page Giter VIP logo

pixelmaster11 / face_classifiers Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 173.32 MB

Implementation for easy Age, Gender, Ethnicity classification. Also provides face detection and face recognition using a pre-trained CNN file from dlib and OpenCV.

Python 100.00%
face-recognition classifier-model age age-recognition gender-classification gender-detection gender-recognition face-detection dlib opencv

face_classifiers's Introduction

Face_Classifiers

This project is used for different types of classifications such as gender, ethnicity, etc attributes that can be extracted from face images. This project also provides very easy face detection, face recognition using Dlib and opencv libraries.

Install dependencies:

pip install -r requirements.txt

Step 1

I. To create a classifier whether it is for gender or ethnicity or face recognition or a custom one, the image directory should be as follows:

Image Directory
    |__ Face_Recognition
    │       ├── Bruce Lee
    │       ├── Mr Bean
    │       ├── Fernando Torres
    │       ├── Mo Salah
    │       ├── Sadio Mane
    │   
    |   
    |__ Gender_Recognition
    |       ├── Male
    |       ├── Female
    |   
    |   
    |__ Ethnicity_Recognition
    |       ├── Asian
    |       ├── Black
    |       ├── Indian
    |       ├── White

This structure is important as the label names are extracted from the respective Folder Names. Thus, for face recognition the labels for all images under folder Mo Salah will be given the label as Mo Salah and so on.

Step 2

II. The next step is to extract embeddings from the images which would be our feature vectors. These embeddings are computed using a pretrained CNN model from dlib library. These are 128-D embeddings. These embeddings will be extracted and stored alongwith their labels and this will be used as the inputs to our classifier models.

To generate the embeddings use the script generate_dataset.py as follows:

python generate_dataset.py --image_dataset_dir="path/to/image_dir/" --embed_filename="somename_embeddings" --mode="save" 
--embeddings_save_dir="path/where/generated/embeddings/file/will/be/saved"

This will generate a .pkl file at your given path. This file stores embeddings, labels, image_paths in a single file.

Step 3

III. Next step will be to train our classifier model using the generated embeddings and labels. There are couple of classifier classes provided such as svm.py or knn.py which allows you to optimize the hyper parameters. If you want to skip optimization, you can directly run classifier.py which uses a SVM classifier.

 To run the classifier use the script classifier.py as follows:
 
 python classifier.py --embeddings_load_dir="path/to/generated/embeddings/file" --embed_filename="name_of_embed_file_to_load"
 --mode="save" --model_filename="name/of/generated/classifier_model/to/save" --model_save_dir="path/where/models/willbe/saved"

This will train a SVM classifier model by default on the given features and labels. By default it will scale the features using Normalization and perform a Shuffle split cross validation with 10 splits with train / test split as 70-30. It also performs a pure train-test 70-30 split without cross validation by training on the 70% train- set and testing on the remaining 30% test-set and plots a confusion matrix with a classification report for detailed summary.
Once training is completed it will save the trained classifier model as a your_model_name.pkl file

face_classifiers's People

Contributors

pixelmaster11 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.