基于人脸匹配算法的名人识别模型
celeb-detector的Python项目详细描述
名人识别![PyPI version](https://warehouse-camo.ingress.cmh1.psfhosted.org/ccb77ba32f85f0290229e66e4f8681fe3a0d4207/68747470733a2f2f62616467652e667572792e696f2f70792f63656c65622d6465746563746f722e737667)
![Documentation Status](https://warehouse-camo.ingress.cmh1.psfhosted.org/5d60dfede7dc6f444594c32b5762046738ed5b21/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f63656c65622d7265636f676e6974696f6e2f62616467652f3f76657273696f6e3d6d61696e)
![Anaconda-Server Badge](https://warehouse-camo.ingress.cmh1.psfhosted.org/41188cce7c9196b776b7cc6a8489a49ba77bb93f/68747470733a2f2f616e61636f6e64612e6f72672f73686f62686974393631382f63656c65622d6465746563746f722f6261646765732f696e7374616c6c65722f656e762e737667)
使用人脸匹配算法识别名人的模型。在
这个模型是基于一个数据集,包括60位名人(每人100张)的6000张照片。在
有关详细文档,请参阅this。在
算法的基本工作包括:
正在安装依赖项
- 运行
pip install -r requirements.txt
安装所有依赖项(最好是在虚拟环境中)。在
PyPI包
安装
- 要确保您拥有所有必需的附加包,请先运行
pip install -r requirements.txt
。在 - 要安装pip包,请运行:
# pip release version pip install celeb-detector # also install additional dependencies with this (if not installed via requirements.txt file) pip install annoy keras-vggface keras-applications # Directly from repo pip install git+https://github.com/shobhit9618/celeb_recognition.git
在 - 如果在linux或ubuntu上使用conda,可以使用以下命令创建并使用一个名为celeb detector的新环境:
^{pr2}$
这将安装所有必需的依赖项。要确保您使用的是包的最新版本,请同时运行(在环境中):
pip install --upgrade celeb-detector
在
使用pip pakcage
- 在
要使用我的模型进行预测,请在安装后使用以下代码行:
importceleb_detector# on running for the first time, this will download vggface modelimg_path='sample_image.jpg'celeb_detector.celeb_recognition(img_path)# on running for the first time, 2 files (celeb_mapping.json and celeb_index_60.ann) will downloaded to the home directory# if you want to use an image url, just provide the url and add url=Trueurl='https://sample/sample_image_url.jpg'celeb_detector.celeb_recognition(url,url=True)
这将返回一个字典列表,每个字典包含bbox坐标、名人姓名和在图像中检测到的每个人脸的可信度(如果没有检测到匹配的人脸,则名人姓名将是未知的)。在
在 - 在
要使用您自己的自定义模型,还需要提供json和ann文件的路径,如下所示:
importceleb_detectorimg_path='sample_image.jpg'ann_path='sample_index.ann'celeb_map='sample_mapping.json'celeb_detector.celeb_recognition(img_path,ann_path,celeb_map)
在 - 在
创建您自己的模型(有关用法的详细信息,请参阅this),并按如下方式运行:
importceleb_detectorfolder_path='celeb_images'celeb_detector.create_celeb_model(folder_path)
在
创建你自己的名人模型
- 在以下目录结构中创建名人数据集:
celeb_images/ celeb-a/ celeb-a_1.jpg celeb-a_2.jpg ... celeb-b/ celeb-b_1.jpg celeb-b_1.jpg ... ...
在 - 每个文件夹名称都将被视为模型对应的名人名(警告:名称中不要提供任何特殊字符或空格)。在
- 确保每个图像只有一张脸(所需的名人),如果有多张脸,则只考虑第一张检测到的脸。在
- 提供create_celeb_model.py文件中数据集文件夹(例如,
celeb_images
文件夹)的路径。在 - 运行create_celeb_model.py文件。在
- 成功完成代码后,我们得到
celeb_mapping.json
(用于存储索引与名人姓名)、celeb_index.ann
(用于搜索编码的ann文件)和{}文件(用于存储每个名人的编码与索引)。 (警告:您需要提供存储这些文件的路径,默认情况下存储在当前目录中)
jupyter模型预测
- 提供celeb_recognition.ipynb文件中
celeb_mapping.json
和celeb_index.ann
文件的路径。如果你想试试我的模型,忽略这一步。在 - 运行celeb_recognition.ipynb文件中的所有单元格,最终单元格将提供用于上载图像和进行预测的小部件 (这也将下载必要的模型文件)。在
- 注意:celeb_recognition.ipynb是一个独立文件,运行时不需要来自repo的任何其他文件。在
python中的模型预测
- 提供celeb_recognition.py和celeb_utils.py文件中
celeb_mapping.json
和celeb_index.ann
文件的路径。如果你想试试我的模型,忽略这一步。在 - 运行celeb_recognition.py文件,提供文件中图像的路径。在
- 输出包括已识别的面、边界框和预测的名人姓名(如果找不到,则未知)。在
- 它还显示带有边界框的输出。在
示例图像输出
粘合剂
单击以下链接可以运行活页夹应用程序:
{a1vo7}你也可以通过点击图片绑定器来上传图片。在
谷歌Colab
要在google colab中打开并运行celeb_recognition.ipynb文件,请单击以下链接:
- 项目
标签: