ONNX 模型库
返回模型

说明文档


license: mit

详细文档请参考这里。

你也可以在 Medium 上阅读我的文章这里。

算法的基本工作原理如下:

  • 人脸检测使用 face_recognition 模块完成。

  • 人脸编码使用 VGGFace 模型创建(此处已转换为 PyTorch)。

  • 人脸匹配使用 annoy 库完成。

安装依赖

  • 运行 pip install -r requirements.txt 来安装所有依赖(建议在虚拟环境中安装)。

PyPI 包

安装

  • 为确保你拥有所有必需的额外包,请先运行 pip install -r requirements.txt。
  • 要安装 pip 包,请运行:
    # pip 发布版本
    pip install celeb-detector
    # 直接从仓库安装
    pip install -e .
    

使用 pip 包

  • 若要使用我的模型进行预测,安装后请使用以下代码:

    import celeb_detector
    img_path = 'sample_image.jpg' # 支持本地路径和网络 URL,如 https://sample/sample_image_url.jpg
    celeb_detector.celeb_recognition(img_path)
    

    这将返回一个字典列表,每个字典包含边界框坐标、名人名称和置信度,对应图像中检测到的每个人脸(如果未找到匹配的人脸,名人名称将为 unknown)。

  • 若要使用你自己的自定义模型,还需提供 json 和 ann 文件的路径,如下所示:

    import celeb_detector
    img_path = 'sample_image.jpg'
    ann_path = 'sample_index.ann'
    celeb_map = 'sample_mapping.json'
    celeb_detector.celeb_recognition(img_path, ann_path, celeb_map)
    
  • 若要创建你自己的模型(更多使用详情请参考这里),请按以下方式运行:

    import celeb_detector
    folder_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
            ...
        ...
    
  • 每个文件夹名称将被视为模型中对应的名人名称(警告:名称中不要包含任何特殊字符或空格)。
  • 确保每张图片只有 1 张人脸(目标名人的),如果有多张人脸,只有第一张被检测到的人脸会被考虑。
  • 在 create_celeb_model.py 文件中提供数据集文件夹的路径(例如 celeb_images 文件夹)。
  • 运行 create_celeb_model.py 文件。
  • 代码成功运行后,我们将获得 celeb_mapping.json(用于存储索引与名人名称的对应关系)、celeb_index.ann(用于搜索编码的 ann 文件)和 celeb_name_encoding.pkl 文件(用于存储每个名人的编码与索引的对应关系)。 (警告:你需要提供存储这些文件的路径,默认存储在当前目录)

在 Jupyter 中进行模型预测

  • 在 celeb_recognition.ipynb 文件中提供 celeb_mapping.json 和 celeb_index.ann 文件的路径。如果你想尝试我的模型,可以忽略此步骤。
  • 运行 celeb_recognition.ipynb 文件中的所有单元格,最后一个单元格将提供用于上传图像和进行预测的小部件 (这也会下载必要的模型文件)。
  • 注意:celeb_recognition.ipynb 是一个独立文件,运行时不需要仓库中的任何其他文件。

在 Python 中进行模型预测

  • 在 celeb_prediction_main.py 中提供 celeb_mapping.json 和 celeb_index.ann 文件的路径。如果你想尝试我的模型,可以忽略此步骤。
  • 运行 celeb_prediction_main.py 文件,在文件中提供图像路径。
  • 输出包括识别出的人脸列表、边界框和预测的名人名称(如果未找到则为 unknown)。
  • 它还会显示带有边界框的输出结果。

resnet151/celeb_detector

作者 resnet151

↓ 0 ♥ 2

创建时间: 2024-04-13 20:01:00+00:00

更新时间: 2024-04-14 08:16:02+00:00

在 Hugging Face 上查看

文件 (22)

.gitattributes
.gitignore
LICENSE
README.md
app.py
celeb_detector/.readthedocs.yaml
celeb_detector/__init__.py
celeb_detector/celeb_prediction_main.py
celeb_detector/celeb_recognition.py
celeb_detector/create_celeb_model.py
celeb_detector/draw_utils/Roboto-Bold.ttf
celeb_detector/draw_utils/draw_bbox.py
celeb_detector/models/celeb_index_117.ann
celeb_detector/models/celeb_index_60.ann
celeb_detector/models/celeb_mapping_117.json
celeb_detector/models/celeb_mapping_60.json
celeb_detector/models/vggface_resnet50.onnx ONNX
celeb_detector/models/vggface_resnet50.pt
celeb_detector/models/vggface_resnet50_fp16.pt
celeb_recognition.ipynb
requirements.txt
setup.py