项目作者: chen0040

项目描述 :
face detection, verification and recognition using Keras
高级语言: Python
项目地址: git://github.com/chen0040/keras-face.git
创建时间: 2018-01-11T02:56:00Z
项目社区:https://github.com/chen0040/keras-face

开源协议:MIT License

下载


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)

  1. from keras_face.library.face_net import FaceNet
  2. def main():
  3. model_dir_path = './models'
  4. image_dir_path = "./data/images"
  5. fnet = FaceNet()
  6. fnet.load_model(model_dir_path)
  7. database = {}
  8. database["danielle"] = fnet.img_to_encoding(image_dir_path + "/danielle.png")
  9. database["younes"] = fnet.img_to_encoding(image_dir_path + "/younes.jpg")
  10. database["tian"] = fnet.img_to_encoding(image_dir_path + "/tian.jpg")
  11. database["andrew"] = fnet.img_to_encoding(image_dir_path + "/andrew.jpg")
  12. database["kian"] = fnet.img_to_encoding(image_dir_path + "/kian.jpg")
  13. database["dan"] = fnet.img_to_encoding(image_dir_path + "/dan.jpg")
  14. database["sebastiano"] = fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")
  15. database["bertrand"] = fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")
  16. database["kevin"] = fnet.img_to_encoding(image_dir_path + "/kevin.jpg")
  17. database["felix"] = fnet.img_to_encoding(image_dir_path + "/felix.jpg")
  18. database["benoit"] = fnet.img_to_encoding(image_dir_path + "/benoit.jpg")
  19. database["arnaud"] = fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")
  20. # verifies whether a particular camera image is a person in the image database
  21. dist, is_valid = fnet.verify(image_dir_path + "/camera_0.jpg", "younes", database)
  22. print('camera_0.jpg is' + (' ' if is_valid else ' not ') + 'yournes')
  23. dist, is_valid = fnet.verify(image_dir_path + "/camera_2.jpg", "kian", database)
  24. print('camera_0.jpg is' + (' ' if is_valid else ' not ') + 'yournes')
  25. # whether a particular camera image is which person in the image database (or not at all)
  26. dist, identity = fnet.who_is_it(image_dir_path + "/camera_0.jpg", database)
  27. if identity is None:
  28. print('camera_0.jpg is not found in database')
  29. else:
  30. print('camera_0.jpg is ' + str(identity))
  31. if __name__ == '__main__':
  32. main()

VGG16 + Siamese

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

  1. from keras_face.library.siamese import SiameseFaceNet
  2. def main():
  3. fnet = SiameseFaceNet()
  4. fnet.vgg16_include_top = True # default is False
  5. model_dir_path = './models'
  6. image_dir_path = "./data/images"
  7. database = dict()
  8. database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
  9. database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
  10. database["tian"] = [fnet.img_to_encoding(image_dir_path + "/tian.jpg")]
  11. database["andrew"] = [fnet.img_to_encoding(image_dir_path + "/andrew.jpg")]
  12. database["kian"] = [fnet.img_to_encoding(image_dir_path + "/kian.jpg")]
  13. database["dan"] = [fnet.img_to_encoding(image_dir_path + "/dan.jpg")]
  14. database["sebastiano"] = [fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")]
  15. database["bertrand"] = [fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")]
  16. database["kevin"] = [fnet.img_to_encoding(image_dir_path + "/kevin.jpg")]
  17. database["felix"] = [fnet.img_to_encoding(image_dir_path + "/felix.jpg")]
  18. database["benoit"] = [fnet.img_to_encoding(image_dir_path + "/benoit.jpg")]
  19. database["arnaud"] = [fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")]
  20. fnet.fit(database=database, model_dir_path=model_dir_path)
  21. if __name__ == '__main__':
  22. 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)

  1. from keras_face.library.siamese import SiameseFaceNet
  2. def main():
  3. fnet = SiameseFaceNet()
  4. model_dir_path = './models'
  5. image_dir_path = "./data/images"
  6. fnet.load_model(model_dir_path)
  7. database = dict()
  8. database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
  9. database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
  10. database["tian"] = [fnet.img_to_encoding(image_dir_path + "/tian.jpg")]
  11. database["andrew"] = [fnet.img_to_encoding(image_dir_path + "/andrew.jpg")]
  12. database["kian"] = [fnet.img_to_encoding(image_dir_path + "/kian.jpg")]
  13. database["dan"] = [fnet.img_to_encoding(image_dir_path + "/dan.jpg")]
  14. database["sebastiano"] = [fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")]
  15. database["bertrand"] = [fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")]
  16. database["kevin"] = [fnet.img_to_encoding(image_dir_path + "/kevin.jpg")]
  17. database["felix"] = [fnet.img_to_encoding(image_dir_path + "/felix.jpg")]
  18. database["benoit"] = [fnet.img_to_encoding(image_dir_path + "/benoit.jpg")]
  19. database["arnaud"] = [fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")]
  20. fnet.verify(image_dir_path + "/camera_0.jpg", "younes", database)
  21. fnet.verify(image_dir_path + "/camera_2.jpg", "kian", database)
  22. fnet.who_is_it(image_dir_path + "/camera_0.jpg", database)
  23. if __name__ == '__main__':
  24. 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