Keras Face 项目教程
keras-face face detection, verification and recognition using Keras 项目地址: https://gitcode.com/gh_mirrors/ke/keras-face
1. 项目的目录结构及介绍
keras-face/
├── demo/
│ └── ...
├── keras_face/
│ ├── library/
│ │ ├── face_net.py
│ │ └── siamese.py
│ └── ...
├── .gitignore
├── LICENSE
├── README.md
└── requirements.txt
目录结构说明
- demo/: 包含项目的演示代码。
- keras_face/: 核心代码目录,包含两个主要实现:
- library/face_net.py: 实现 DeepFace 算法。
- library/siamese.py: 实现 VGG16 + Siamese 网络。
- .gitignore: Git 忽略文件配置。
- LICENSE: 项目许可证文件。
- README.md: 项目说明文件。
- requirements.txt: 项目依赖文件。
2. 项目的启动文件介绍
DeepFace 启动文件
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")
# 其他图像处理代码...
# 验证图像是否在数据库中
dist, is_valid = fnet.verify(image_dir_path + "/camera_0.jpg", "younes", database)
print('camera_0.jpg is' + (' ' if is_valid else ' not ') + 'younes')
# 识别图像中的人物
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 启动文件
from keras_face.library.siamese import SiameseFaceNet
def main():
fnet = SiameseFaceNet()
model_dir_path = './models'
image_dir_path = "./data/images"
database = {}
database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
# 其他图像处理代码...
fnet.fit(database=database, model_dir_path=model_dir_path)
# 验证图像是否在数据库中
fnet.verify(image_dir_path + "/camera_0.jpg", "younes", database)
# 识别图像中的人物
fnet.who_is_it(image_dir_path + "/camera_0.jpg", database)
if __name__ == '__main__':
main()
3. 项目的配置文件介绍
requirements.txt
tensorflow==2.4.0
keras==2.4.3
numpy==1.19.5
opencv-python==4.5.1.48
配置文件说明
- requirements.txt: 列出了项目运行所需的 Python 依赖包及其版本。
其他配置
- .gitignore: 配置了 Git 忽略的文件和目录,避免将不必要的文件提交到版本控制中。
- LICENSE: 项目的开源许可证,通常为 MIT 许可证。
- README.md: 项目的说明文件,包含项目的简介、安装方法、使用说明等内容。
keras-face face detection, verification and recognition using Keras 项目地址: https://gitcode.com/gh_mirrors/ke/keras-face