Giter Site home page Giter Site logo

winstonzhao / face-classification Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wondonghyeon/face-classification

0.0 0.0 0.0 20.13 MB

Face model to classify gender and race. Trained on LFWA+ Dataset.

Jupyter Notebook 93.14% Python 6.86%

face-classification's Introduction

Gender and Race Classification with Face Images

Let's train a simple face attribute classification model! The dataset we are going to use contains 73 different face attributes, but we are only going to focus on gender and race. Here are some sample results of the trained model. (For now, the dataset I used has only "White," "Black," and "Asian" faces. I will try to add more races in future)

Ellen's Oscar Selfie Trump Rally Korean Protest

Requirements

Packages

dlib
face_recognition
NumPy
pandas
scikit-learn

Dataset

LFWA+ dataset

Usage

Data Preprocessing

Download Dataset

You can download LFWA+ dataset here. You will see a Dropbox link for LFWA+ dataset in this page. Please unzip the lfw.zip file after you download.

Feature Extraction
python feature_extraction.py --data_dir LFWA/ --save_feature feature.csv --save_label label.csv

You can run feature_extraction.py like the above command or just run the jupyter notebook (feature-extracion.ipynb) step by step.

We are going to use the face embedding function face_encodings in face_recognition package, which is based on dlib's face_recognition_model_v1. This function takes a face image as input and outputs a 128-dimensional face embedding vector. This function is basically an implementation of Face-Net, a deep CNN trained with triplet loss. Please refer to the original paper for more details

For face detection, I just used face_recognition's face_locations. This is a histogram of oriented gradient (HOG), which is quite outdated, by default. You can use a CNN face detector by changing input parameters in line 49 of feature_extraction.py and line 20 of pred.py like the follwing

# line 49 of feature_extraction.py
X_faces_loc = face_locations(X_img, model = "cnn")
# line 20 of pred.py
locs = face_locations(X_img, number_of_times_to_upsample = N_UPSCLAE, model = "cnn")

Model Training

python train.py --feature feature.csv --label label.csv --save_model face_model.pkl

You can run train.py as above or just run the jupyter notebook (train.ipynb) step by step.

I used MLPClassifier in sklearn package for the classifier. You can change it to the classifier of your flavor but I like MLPClassifier since it is really simple!

Prediction

Classify face attributes for all images in a directory using pred.py

python pred.py --img_dir test/ --model face_model.pkl

More Examples!

blm women's march g20 grammy volleyball baskettball obama I love Obama.. Please don't get me wrong! real madrid sanders

Future Works

  • Add more data (Google Image Search)
  • Use a better face detection model (faster rcnn)

face-classification's People

Contributors

wondonghyeon avatar winstonzhao 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.