Giter VIP home page Giter VIP logo

face-gender-classification's Introduction

Face Gender Classification

Requirements

  1. TensorFlow 2.3.0

  2. onnx2keras

  3. Onnx

  4. Python 3

  5. GPU [Optional]

Usage

  1. Install Miniconda. Follow instructions here: https://docs.conda.io/en/latest/miniconda.html

  2. Once ready, use the environment.yml file to get the virtual environment up and running using the following command:

    conda env create -f environment.yml
  1. Download the pre-trained Caffe model from here: http://www.robots.ox.ac.uk/~vgg/software/vgg_face/.

    Also download the fold_0_data.txt to fold_4_data.txt files for getting the labels.

  2. Convert the Caffe model to ONNX model using this: https://github.com/htshinichi/caffe-onnx

    python convert2onnx.py \
          vgg_face_caffe/VGG_FACE_deploy.prototxt \
          vgg_face_caffe/VGG_FACE.caffemodel \
          vgg_face onnxmodel
  1. Convert the ONNX model to Keras model using this: https://github.com/nerox8664/onnx2keras

    For conversion of onnx model to keras model, run the following jupyter notebook.

    ONNX to Keras.ipynb
  1. Once you have the Keras model ready, we are now ready for Transfer Learning.

  2. In the Model Training and Prediction directory, unzip the faces.zip file and run the following Jupyter Notebook:

    Face_gender_classification.ipynb

This above notebook does the following:

a) Loads in the Dataset using the fold_x_data.txt files.

b) Splits the data into Train/Val/Test set.

c) Converts and Saves the dataset into TFRecords format for efficiency.

d) Loads the keras model converted above.

e) Removes the unnecessary layers from the model.

f) Freezes the trained layers and adds the new layers on top of it.

g) Defines the Loss and optimizer functions.

h) Trains the model for set number of epochs by streaming data efficiently from TFRecords using tf.data API in batches.

i) Saves the trained model as well as it's chekpoints.

j) Shows a plot between model loss and accuracy w.r.t number of epochs.

k) Makes predictions on the test dataset and computes accuracy, Precision, Recall, F1 Score and the confusion matrix.

l) Shows an example of how to load the trained model for making inference on random images.

References

  1. https://github.com/htshinichi/caffe-onnx

  2. https://github.com/nerox8664/onnx2keras

  3. http://www.robots.ox.ac.uk/~vgg/software/vgg_face/

  4. https://www.tensorflow.org/guide/data

  5. https://www.tensorflow.org/api_docs/python/tf/data/Dataset

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.