Coder Social home page Coder Social logo

keras-face's Introduction

keras-face

face verification and recognition using Keras

The project contains two implementations: DeepFace and VGG16 + Siamese

Usage

DeepFace

Below shows the sample codes which verifies whether a particular camera image is a person in an image database or whether a particular camera image is which person in the image database (or not at all)

from keras_face.library.face_net import FaceNet


def main():
    model_dir_path = './models'
    image_dir_path = "./data/images"

    fnet = FaceNet()
    fnet.load_model(model_dir_path)

    database = {}
    database["danielle"] = fnet.img_to_encoding(image_dir_path + "/danielle.png")
    database["younes"] = fnet.img_to_encoding(image_dir_path + "/younes.jpg")
    database["tian"] = fnet.img_to_encoding(image_dir_path + "/tian.jpg")
    database["andrew"] = fnet.img_to_encoding(image_dir_path + "/andrew.jpg")
    database["kian"] = fnet.img_to_encoding(image_dir_path + "/kian.jpg")
    database["dan"] = fnet.img_to_encoding(image_dir_path + "/dan.jpg")
    database["sebastiano"] = fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")
    database["bertrand"] = fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")
    database["kevin"] = fnet.img_to_encoding(image_dir_path + "/kevin.jpg")
    database["felix"] = fnet.img_to_encoding(image_dir_path + "/felix.jpg")
    database["benoit"] = fnet.img_to_encoding(image_dir_path + "/benoit.jpg")
    database["arnaud"] = fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")

    # verifies whether a particular camera image is a person in the image database
    dist, is_valid = fnet.verify(image_dir_path + "/camera_0.jpg", "younes", database)
    print('camera_0.jpg is' + (' ' if is_valid else ' not ') + 'yournes')
    dist, is_valid = fnet.verify(image_dir_path + "/camera_2.jpg", "kian", database)
    print('camera_0.jpg is' + (' ' if is_valid else ' not ') + 'yournes')
    
    # whether a particular camera image is which person in the image database (or not at all)
    dist, identity = fnet.who_is_it(image_dir_path + "/camera_0.jpg", database)
    if identity is None:
        print('camera_0.jpg is not found in database')
    else:
        print('camera_0.jpg is ' + str(identity))


if __name__ == '__main__':
    main()

VGG16 + Siamese

Below shows sample codes how to train the V166+Siamese network:

from keras_face.library.siamese import SiameseFaceNet


def main():
    fnet = SiameseFaceNet()
    fnet.vgg16_include_top = True # default is False

    model_dir_path = './models'
    image_dir_path = "./data/images"

    database = dict()
    database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
    database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
    database["tian"] = [fnet.img_to_encoding(image_dir_path + "/tian.jpg")]
    database["andrew"] = [fnet.img_to_encoding(image_dir_path + "/andrew.jpg")]
    database["kian"] = [fnet.img_to_encoding(image_dir_path + "/kian.jpg")]
    database["dan"] = [fnet.img_to_encoding(image_dir_path + "/dan.jpg")]
    database["sebastiano"] = [fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")]
    database["bertrand"] = [fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")]
    database["kevin"] = [fnet.img_to_encoding(image_dir_path + "/kevin.jpg")]
    database["felix"] = [fnet.img_to_encoding(image_dir_path + "/felix.jpg")]
    database["benoit"] = [fnet.img_to_encoding(image_dir_path + "/benoit.jpg")]
    database["arnaud"] = [fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")]

    fnet.fit(database=database, model_dir_path=model_dir_path)

if __name__ == '__main__':
    main()

Below shows the sample codes which verifies whether a particular camera image is a person in an image database or whether a particular camera image is which person in the image database (or not at all)

from keras_face.library.siamese import SiameseFaceNet


def main():
    fnet = SiameseFaceNet()

    model_dir_path = './models'
    image_dir_path = "./data/images"
    fnet.load_model(model_dir_path)

    database = dict()
    database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
    database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
    database["tian"] = [fnet.img_to_encoding(image_dir_path + "/tian.jpg")]
    database["andrew"] = [fnet.img_to_encoding(image_dir_path + "/andrew.jpg")]
    database["kian"] = [fnet.img_to_encoding(image_dir_path + "/kian.jpg")]
    database["dan"] = [fnet.img_to_encoding(image_dir_path + "/dan.jpg")]
    database["sebastiano"] = [fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")]
    database["bertrand"] = [fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")]
    database["kevin"] = [fnet.img_to_encoding(image_dir_path + "/kevin.jpg")]
    database["felix"] = [fnet.img_to_encoding(image_dir_path + "/felix.jpg")]
    database["benoit"] = [fnet.img_to_encoding(image_dir_path + "/benoit.jpg")]
    database["arnaud"] = [fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")]

    fnet.verify(image_dir_path + "/camera_0.jpg", "younes", database)
    fnet.verify(image_dir_path + "/camera_2.jpg", "kian", database)
    fnet.who_is_it(image_dir_path + "/camera_0.jpg", database)


if __name__ == '__main__':
    main()

Configure to run on GPU on Windows

  • Step 1: Change tensorflow to tensorflow-gpu in requirements.txt and install tensorflow-gpu
  • Step 2: Download and install the CUDA® Toolkit 9.0 (Please note that currently CUDA® Toolkit 9.1 is not yet supported by tensorflow, therefore you should download CUDA® Toolkit 9.0)
  • Step 3: Download and unzip the cuDNN 7.4 for CUDA@ Toolkit 9.0 and add the bin folder of the unzipped directory to the $PATH of your Windows environment

Todo

For VGG16 + Siamese, the training was not well-done as there are currently very limited number of sample images used for training (only 12 images for 12 persons). Ideally, need to train using 100,000 images for 10,000 persons. Will need to add in larger dataset for the training

Note

For DeepFace (namely keras_face/library/face_net.py), some utility classes and weights are taken from https://github.com/shahariarrabby/deeplearning.ai , also it contains only the prediction part

keras-face's People

Contributors

chen0040 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

keras-face's Issues

ValueError

ValueError: Shape must be rank 1 but is rank 0 for 'bn1/cond/Reshape_4' (op: 'Reshape') with input shapes: [1,64,1,1], [].

What is causing this error?

argument error

usage: deep_learning_object_detection.py [-h] -i IMAGE -p PROTOTXT -m MODEL
[-c CONFIDENCE]
deep_learning_object_detection.py: error: the following arguments are required: -i/--image, -p/--prototxt, -m/--model
MobileNetSSD_deploy.prototxt.txt

More images for every object in database

Hello,
Your model was trained with only 1 image every object in database so It has less accuracy. Thus, I want to train more images. Please help me idea to modify your code.
Thank you.

Model accuracy

Now I use 7000 photos as input, but the model accuracy is around 80%. How can I improve the accuracy of the model?

problem when comparing face

I put one more face (my face) in the image bank of the code and I used "face_net_demo.py" for tests, however, the distance is at 1.0380375385284424 (threshold = 0.7)
What can I do wrong? How can I see the validation loss of keras?

ps: in the grayscale image I'm wearing glasses while in the other I'm not.

verify this
y7ftQvwV-
on this
334280345SP

Error while running python file

Hi
I tried to run python script siamese_demo_predict.py but error is thrown-

File "siamese_demo_predict.py", line 1, in
from keras_face.library.siamese import SiameseFaceNet
ModuleNotFoundError: No module named 'keras_face'

How tor resolve this.Please tell.

About siamese_demo_predict and train

Hi, I would like to know why I have to create an database in siamese_demo_predict.py again if I did in siamese_demo_train.py
thanks in advance.

Does not support Tensorflow version 1.8

I was getting "Illegal Instruction" error, after tracing the error the problem is with the version of Tensorflow.
Works perfectly with tensorflow version 1.5

Face Landmark Localization

Hi,

Can I train DeepFace or VGG16 + Siamese model to locate face landmarks?

I want to reach something like this.

I am planning to use CelebA dataset.

Thanks.

model weights

could you please give a link for the model weights? or just tell me if the normal facenet weights will do, thank you

how train?

hi.
I run siamese_demo_train.py but why it didn't save weights in models/weights??

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.