HivisionIDPhotos
⚡️HivisionIDPhotos: a lightweight and efficient AI ID photos tools. 一个轻量级的AI证件照制作算法。
Stars: 10308
HivisionIDPhoto is a practical algorithm for intelligent ID photo creation. It utilizes a comprehensive model workflow to recognize, cut out, and generate ID photos for various user photo scenarios. The tool offers lightweight cutting, standard ID photo generation based on different size specifications, six-inch layout photo generation, beauty enhancement (waiting), and intelligent outfit swapping (waiting). It aims to solve emergency ID photo creation issues.
README:
相关项目:
- SwanLab:训练人像抠图模型全程用它来分析和监控,以及和实验室同学协作交流,大幅提升了训练效率。
-
2024.09.25: 增加五寸相纸和JPEG下载选项|默认照片下载支持300DPI
-
2024.09.24: API接口增加base64图像传入选项 | Gradio Demo增加排版照裁剪线功能
-
2024.09.22: Gradio Demo增加野兽模式,可设置内存加载策略 | API接口增加dpi、face_alignment参数
-
2024.09.18: Gradio Demo增加分享模版照功能、增加美式证件照背景选项
-
2024.09.17: Gradio Demo增加自定义底色-HEX输入功能 | (社区贡献)C++版本 - HivisionIDPhotos-cpp 贡献 by zjkhahah
-
2024.09.16: Gradio Demo增加人脸旋转对齐功能,自定义尺寸输入支持毫米单位
-
2024.09.14: Gradio Demo增加自定义DPI功能,增加日语和韩语支持,增加调整亮度、对比度、锐度功能
-
2024.09.12: Gradio Demo增加美白功能 | API接口增加加水印、设置照片KB值大小、证件照裁切
🚀 谢谢你对我们的工作感兴趣。您可能还想查看我们在图像领域的其他成果,欢迎来信:[email protected].
HivisionIDPhoto 旨在开发一种实用、系统性的证件照智能制作算法。
它利用一套完善的AI模型工作流程,实现对多种用户拍照场景的识别、抠图与证件照生成。
HivisionIDPhoto 可以做到:
- 轻量级抠图(纯离线,仅需 CPU 即可快速推理)
- 根据不同尺寸规格生成不同的标准证件照、六寸排版照
- 支持 纯离线 或 端云 推理
- 美颜
- 智能换正装(waiting)
如果 HivisionIDPhoto 对你有帮助,请 star 这个 repo 或推荐给你的朋友,解决证件照应急制作问题!
我们分享了一些由社区构建的HivisionIDPhotos的有趣应用和扩展:
HivisionIDPhotos-ComfyUI | HivisionIDPhotos-wechat-weapp |
---|---|
ComfyUI证件照处理工作流 | 证件照微信小程序(JAVA后端+原生前端) |
HivisionIDPhotos-Uniapp | HivisionIDPhotos-web |
---|---|
证件照微信小程序(uniapp) | 证件照应用网页版 |
- HivisionIDPhotos-cpp: HivisionIDphotos C++版本,由 zjkhahah 构建
- ai-idphoto: HivisionIDPhotos-wechat-weapp 的uniapp多端兼容版,由 wmlcjj 贡献
- HivisionIDPhotos-uniapp-WeChat-gpto1: 由gpt-o1辅助完成开发的证件照微信小程序,由 jkm199 贡献
- HivisionIDPhotos-windows-GUI:Windows客户端应用,由 zhaoyun0071 构建
- HivisionIDPhotos-NAS: 群晖NAS部署中文教程,由 ONG-Leo 贡献
环境安装与依赖:
- Python >= 3.7(项目主要测试在 python 3.10)
- OS: Linux, Windows, MacOS
git clone https://github.com/Zeyi-Lin/HivisionIDPhotos.git
cd HivisionIDPhotos
建议 conda 创建一个 python3.10 虚拟环境后,执行以下命令
pip install -r requirements.txt
pip install -r requirements-app.txt
方式一:脚本下载
python scripts/download_model.py --models all
# 如需指定下载某个模型
# python scripts/download_model.py --models modnet_photographic_portrait_matting
方式二:直接下载
模型均存到项目的hivision/creator/weights
目录下:
人像抠图模型 | 介绍 | 下载 |
---|---|---|
MODNet | MODNet官方权重 | 下载(24.7MB) |
hivision_modnet | 对纯色换底适配性更好的抠图模型 | 下载(24.7MB) |
rmbg-1.4 | BRIA AI 开源的抠图模型 |
下载(176.2MB)后重命名为rmbg-1.4.onnx
|
birefnet-v1-lite | ZhengPeng7 开源的抠图模型,拥有最好的分割精度 |
下载(224MB)后重命名为birefnet-v1-lite.onnx
|
如果下载网速不顺利:前往SwanHub下载。
拓展人脸检测模型 | 介绍 | 使用文档 |
---|---|---|
MTCNN | 离线人脸检测模型,高性能CPU推理(毫秒级),为默认模型,检测精度较低 | Clone此项目后直接使用 |
RetinaFace | 离线人脸检测模型,CPU推理速度中等(秒级),精度较高 |
下载后放到hivision/creator/retinaface/weights 目录下 |
Face++ | 旷视推出的在线人脸检测API,检测精度较高,官方文档 | 使用文档 |
测试环境为Mac M1 Max 64GB,非GPU加速,测试图片分辨率为 512x715(1) 与 764×1146(2)。
模型组合 | 内存占用 | 推理时长(1) | 推理时长(2) |
---|---|---|---|
MODNet + mtcnn | 410MB | 0.207s | 0.246s |
MODNet + retinaface | 405MB | 0.571s | 0.971s |
birefnet-v1-lite + retinaface | 6.20GB | 7.063s | 7.128s |
在当前版本,可被英伟达GPU加速的模型为birefnet-v1-lite
,并请确保你有16GB左右的显存。
如需使用英伟达GPU加速推理,在确保你已经安装CUDA与cuDNN后,根据onnxruntime-gpu文档找到对应的onnxruntime-gpu
版本安装,以及根据pytorch官网找到对应的torch
版本安装。
# 假如你的电脑安装的是CUDA 12.x, cuDNN 8
# 安装torch是可选的,如果你始终配置不好cuDNN,那么试试安装torch
pip install onnxruntime-gpu==1.18.0
pip install torch --index-url https://download.pytorch.org/whl/cu121
完成安装后,调用birefnet-v1-lite
模型即可利用GPU加速推理。
TIPS: CUDA 支持向下兼容。比如你的 CUDA 版本为 12.6,
torch
官方目前支持的最高版本为 12.4(<12.6),torch
仍可以正常使用CUDA。
python app.py
运行程序将生成一个本地 Web 页面,在页面中可完成证件照的操作与交互。
核心参数:
-
-i
: 输入图像路径 -
-o
: 保存图像路径 -
-t
: 推理类型,有idphoto、human_matting、add_background、generate_layout_photos可选 -
--matting_model
: 人像抠图模型权重选择 -
--face_detect_model
: 人脸检测模型选择
更多参数可通过python inference.py --help
查看
输入 1 张照片,获得 1 张标准证件照和 1 张高清证件照的 4 通道透明 png
python inference.py -i demo/images/test0.jpg -o ./idphoto.png --height 413 --width 295
输入 1 张照片,获得 1张 4 通道透明 png
python inference.py -t human_matting -i demo/images/test0.jpg -o ./idphoto_matting.png --matting_model hivision_modnet
输入 1 张 4 通道透明 png,获得 1 张增加了底色的 3通道图像
python inference.py -t add_background -i ./idphoto.png -o ./idphoto_ab.jpg -c 4f83ce -k 30 -r 1
输入 1 张 3 通道照片,获得 1 张六寸排版照
python inference.py -t generate_layout_photos -i ./idphoto_ab.jpg -o ./idphoto_layout.jpg --height 413 --width 295 -k 200
输入 1 张 4 通道照片(抠图好的图像),获得 1 张标准证件照和 1 张高清证件照的 4 通道透明 png
python inference.py -t idphoto_crop -i ./idphoto_matting.png -o ./idphoto_crop.png --height 413 --width 295
python deploy_api.py
详细请求方式请参考 API 文档,包含以下请求示例:
以下方式三选一
方式一:拉取最新镜像:
docker pull linzeyi/hivision_idphotos
方式二:Dockrfile 直接构建镜像:
在确保将至少一个抠图模型权重文件放到hivision/creator/weights
下后,在项目根目录执行:
docker build -t linzeyi/hivision_idphotos .
方式三:Docker compose 构建:
在确保将至少一个抠图模型权重文件放到hivision/creator/weights
下后,在项目根目录下执行:
docker compose build
启动 Gradio Demo 服务
运行下面的命令,在你的本地访问 http://127.0.0.1:7860 即可使用。
docker run -d -p 7860:7860 linzeyi/hivision_idphotos
启动 API 后端服务
docker run -d -p 8080:8080 linzeyi/hivision_idphotos python3 deploy_api.py
两个服务同时启动
docker compose up -d
本项目提供了一些额外的配置项,使用环境变量进行设置:
环境变量 | 类型 | 描述 | 示例 |
---|---|---|---|
FACE_PLUS_API_KEY | 可选 | 这是你在 Face++ 控制台申请的 API 密钥 | 7-fZStDJ···· |
FACE_PLUS_API_SECRET | 可选 | Face++ API密钥对应的Secret | VTee824E···· |
RUN_MODE | 可选 | 运行模式,可选值为beast (野兽模式)。野兽模式下人脸检测和抠图模型将不释放内存,从而获得更快的二次推理速度。建议内存16GB以上尝试。 |
beast |
DEFAULT_LANG | 可选 | Gradio Demo启动时的默认语言 | en |
docker使用环境变量示例:
docker run -d -p 7860:7860 \
-e FACE_PLUS_API_KEY=7-fZStDJ···· \
-e FACE_PLUS_API_SECRET=VTee824E···· \
-e RUN_MODE=beast \
-e DEFAULT_LANG=en \
linzeyi/hivision_idphotos
- 尺寸:修改size_list_CN.csv后再次运行
app.py
即可,其中第一列为尺寸名,第二列为高度,第三列为宽度。 - 颜色:修改color_list_CN.csv后再次运行
app.py
即可,其中第一列为颜色名,第二列为Hex值。
- 将字体文件放到
hivision/plugin/font
文件夹下 - 修改
hivision/plugin/watermark.py
的font_file
参数值为字体文件名
- 将模板图片放到
hivision/plugin/template/assets
文件夹下。模板图片是一个4通道的透明png。 - 在
hivision/plugin/template/assets/template_config.json
文件中添加最新的模板信息,其中width
为模板图宽度(px),height
为模板图高度(px),anchor_points
为模板中透明区域的四个角的坐标(px);rotation
为透明区域相对于垂直方向的旋转角度,>0为逆时针,<0为顺时针。 - 在
demo/processor.py
的_generate_image_template
函数中的TEMPLATE_NAME_LIST
变量添加最新的模板名
- 修改
demo/assets/title.md
如果您有任何问题,请发邮件至 [email protected]
贡献者们:
Zeyi-Lin、SAKURA-CAT、Feudalman、swpfY、Kaikaikaifang、ShaohonChen、KashiwaByte
This repository is licensed under the Apache-2.0 License.
如果您在研究或项目中使用了HivisionIDPhotos,请考虑引用我们的工作。您可以使用以下BibTeX条目:
@misc{hivisionidphotos,
title={{HivisionIDPhotos: A Lightweight and Efficient AI ID Photos Tool}},
author={Zeyi Lin and SwanLab Team},
year={2024},
publisher={GitHub},
url = {\url{https://github.com/Zeyi-Lin/HivisionIDPhotos}},
}
For Tasks:
Click tags to check more tools for each tasksFor Jobs:
Alternative AI tools for HivisionIDPhotos
Similar Open Source Tools
HivisionIDPhotos
HivisionIDPhoto is a practical algorithm for intelligent ID photo creation. It utilizes a comprehensive model workflow to recognize, cut out, and generate ID photos for various user photo scenarios. The tool offers lightweight cutting, standard ID photo generation based on different size specifications, six-inch layout photo generation, beauty enhancement (waiting), and intelligent outfit swapping (waiting). It aims to solve emergency ID photo creation issues.
Awesome-ChatTTS
Awesome-ChatTTS is an official recommended guide for ChatTTS beginners, compiling common questions and related resources. It provides a comprehensive overview of the project, including official introduction, quick experience options, popular branches, parameter explanations, voice seed details, installation guides, FAQs, and error troubleshooting. The repository also includes video tutorials, discussion community links, and project trends analysis. Users can explore various branches for different functionalities and enhancements related to ChatTTS.
chatluna
Chatluna is a machine learning model plugin that provides chat services with large language models. It is highly extensible, supports multiple output formats, and offers features like custom conversation presets, rate limiting, and context awareness. Users can deploy Chatluna under Koishi without additional configuration. The plugin supports various models/platforms like OpenAI, Azure OpenAI, Google Gemini, and more. It also provides preset customization using YAML files and allows for easy forking and development within Koishi projects. However, the project lacks web UI, HTTP server, and project documentation, inviting contributions from the community.
ChuanhuChatGPT
Chuanhu Chat is a user-friendly web graphical interface that provides various additional features for ChatGPT and other language models. It supports GPT-4, file-based question answering, local deployment of language models, online search, agent assistant, and fine-tuning. The tool offers a range of functionalities including auto-solving questions, online searching with network support, knowledge base for quick reading, local deployment of language models, GPT 3.5 fine-tuning, and custom model integration. It also features system prompts for effective role-playing, basic conversation capabilities with options to regenerate or delete dialogues, conversation history management with auto-saving and search functionalities, and a visually appealing user experience with themes, dark mode, LaTeX rendering, and PWA application support.
video-subtitle-remover
Video-subtitle-remover (VSR) is a software based on AI technology that removes hard subtitles from videos. It achieves the following functions: - Lossless resolution: Remove hard subtitles from videos, generate files with subtitles removed - Fill the region of removed subtitles using a powerful AI algorithm model (non-adjacent pixel filling and mosaic removal) - Support custom subtitle positions, only remove subtitles in defined positions (input position) - Support automatic removal of all text in the entire video (no input position required) - Support batch removal of watermark text from multiple images.
Langchain-Chatchat
LangChain-Chatchat is an open-source, offline-deployable retrieval-enhanced generation (RAG) large model knowledge base project based on large language models such as ChatGLM and application frameworks such as Langchain. It aims to establish a knowledge base Q&A solution that is friendly to Chinese scenarios, supports open-source models, and can run offline.
TigerBot
TigerBot is a cutting-edge foundation for your very own LLM, providing a world-class large model for innovative Chinese-style contributions. It offers various upgrades and features, such as search mode enhancements, support for large context lengths, and the ability to play text-based games. TigerBot is suitable for prompt-based game engine development, interactive game design, and real-time feedback for playable games.
gpt_server
The GPT Server project leverages the basic capabilities of FastChat to provide the capabilities of an openai server. It perfectly adapts more models, optimizes models with poor compatibility in FastChat, and supports loading vllm, LMDeploy, and hf in various ways. It also supports all sentence_transformers compatible semantic vector models, including Chat templates with function roles, Function Calling (Tools) capability, and multi-modal large models. The project aims to reduce the difficulty of model adaptation and project usage, making it easier to deploy the latest models with minimal code changes.
AI0x0.com
AI 0x0 is a versatile AI query generation desktop floating assistant application that supports MacOS and Windows. It allows users to utilize AI capabilities in any desktop software to query and generate text, images, audio, and video data, helping them work more efficiently. The application features a dynamic desktop floating ball, floating dialogue bubbles, customizable presets, conversation bookmarking, preset packages, network acceleration, query mode, input mode, mouse navigation, deep customization of ChatGPT Next Web, support for full-format libraries, online search, voice broadcasting, voice recognition, voice assistant, application plugins, multi-model support, online text and image generation, image recognition, frosted glass interface, light and dark theme adaptation for each language model, and free access to all language models except Chat0x0 with a key.
build_MiniLLM_from_scratch
This repository aims to build a low-parameter LLM model through pretraining, fine-tuning, model rewarding, and reinforcement learning stages to create a chat model capable of simple conversation tasks. It features using the bert4torch training framework, seamless integration with transformers package for inference, optimized file reading during training to reduce memory usage, providing complete training logs for reproducibility, and the ability to customize robot attributes. The chat model supports multi-turn conversations. The trained model currently only supports basic chat functionality due to limitations in corpus size, model scale, SFT corpus size, and quality.
Semi-Auto-NovelAI-to-Pixiv
Semi-Auto-NovelAI-to-Pixiv is a powerful tool that enables batch image generation with NovelAI, along with various other useful features in a super user-friendly interface. It allows users to create images, generate random images, upload images to Pixiv, apply filters, enhance images, add watermarks, and more. The tool also supports video-to-image conversion and various image manipulation tasks. It offers a seamless experience for users looking to automate image processing tasks.
agentica
Agentica is a human-centric framework for building large language model agents. It provides functionalities for planning, memory management, tool usage, and supports features like reflection, planning and execution, RAG, multi-agent, multi-role, and workflow. The tool allows users to quickly code and orchestrate agents, customize prompts, and make API calls to various services. It supports API calls to OpenAI, Azure, Deepseek, Moonshot, Claude, Ollama, and Together. Agentica aims to simplify the process of building AI agents by providing a user-friendly interface and a range of functionalities for agent development.
RAG-Retrieval
RAG-Retrieval provides full-chain RAG retrieval fine-tuning and inference code. It supports fine-tuning any open-source RAG retrieval models, including vector (embedding, graph a), delayed interactive models (ColBERT, graph d), interactive models (cross encoder, graph c). For inference, RAG-Retrieval focuses on ranking (reranker) and has developed a lightweight Python library rag-retrieval, providing a unified way to call any different RAG ranking models.
Llama-Chinese
Llama中文社区是一个专注于Llama模型在中文方面的优化和上层建设的高级技术社区。 **已经基于大规模中文数据,从预训练开始对Llama2模型进行中文能力的持续迭代升级【Done】**。**正在对Llama3模型进行中文能力的持续迭代升级【Doing】** 我们热忱欢迎对大模型LLM充满热情的开发者和研究者加入我们的行列。
Speech-AI-Forge
Speech-AI-Forge is a project developed around TTS generation models, implementing an API Server and a WebUI based on Gradio. The project offers various ways to experience and deploy Speech-AI-Forge, including online experience on HuggingFace Spaces, one-click launch on Colab, container deployment with Docker, and local deployment. The WebUI features include TTS model functionality, speaker switch for changing voices, style control, long text support with automatic text segmentation, refiner for ChatTTS native text refinement, various tools for voice control and enhancement, support for multiple TTS models, SSML synthesis control, podcast creation tools, voice creation, voice testing, ASR tools, and post-processing tools. The API Server can be launched separately for higher API throughput. The project roadmap includes support for various TTS models, ASR models, voice clone models, and enhancer models. Model downloads can be manually initiated using provided scripts. The project aims to provide inference services and may include training-related functionalities in the future.
HaE
HaE is a framework project in the field of network security (data security) that combines artificial intelligence (AI) large models to achieve highlighting and information extraction of HTTP messages (including WebSocket). It aims to reduce testing time, focus on valuable and meaningful messages, and improve vulnerability discovery efficiency. The project provides a clear and visual interface design, simple interface interaction, and centralized data panel for querying and extracting information. It also features built-in color upgrade algorithm, one-click export/import of data, and integration of AI large models API for optimized data processing.
For similar tasks
HivisionIDPhotos
HivisionIDPhoto is a practical algorithm for intelligent ID photo creation. It utilizes a comprehensive model workflow to recognize, cut out, and generate ID photos for various user photo scenarios. The tool offers lightweight cutting, standard ID photo generation based on different size specifications, six-inch layout photo generation, beauty enhancement (waiting), and intelligent outfit swapping (waiting). It aims to solve emergency ID photo creation issues.
For similar jobs
sweep
Sweep is an AI junior developer that turns bugs and feature requests into code changes. It automatically handles developer experience improvements like adding type hints and improving test coverage.
teams-ai
The Teams AI Library is a software development kit (SDK) that helps developers create bots that can interact with Teams and Microsoft 365 applications. It is built on top of the Bot Framework SDK and simplifies the process of developing bots that interact with Teams' artificial intelligence capabilities. The SDK is available for JavaScript/TypeScript, .NET, and Python.
ai-guide
This guide is dedicated to Large Language Models (LLMs) that you can run on your home computer. It assumes your PC is a lower-end, non-gaming setup.
classifai
Supercharge WordPress Content Workflows and Engagement with Artificial Intelligence. Tap into leading cloud-based services like OpenAI, Microsoft Azure AI, Google Gemini and IBM Watson to augment your WordPress-powered websites. Publish content faster while improving SEO performance and increasing audience engagement. ClassifAI integrates Artificial Intelligence and Machine Learning technologies to lighten your workload and eliminate tedious tasks, giving you more time to create original content that matters.
chatbot-ui
Chatbot UI is an open-source AI chat app that allows users to create and deploy their own AI chatbots. It is easy to use and can be customized to fit any need. Chatbot UI is perfect for businesses, developers, and anyone who wants to create a chatbot.
BricksLLM
BricksLLM is a cloud native AI gateway written in Go. Currently, it provides native support for OpenAI, Anthropic, Azure OpenAI and vLLM. BricksLLM aims to provide enterprise level infrastructure that can power any LLM production use cases. Here are some use cases for BricksLLM: * Set LLM usage limits for users on different pricing tiers * Track LLM usage on a per user and per organization basis * Block or redact requests containing PIIs * Improve LLM reliability with failovers, retries and caching * Distribute API keys with rate limits and cost limits for internal development/production use cases * Distribute API keys with rate limits and cost limits for students
uAgents
uAgents is a Python library developed by Fetch.ai that allows for the creation of autonomous AI agents. These agents can perform various tasks on a schedule or take action on various events. uAgents are easy to create and manage, and they are connected to a fast-growing network of other uAgents. They are also secure, with cryptographically secured messages and wallets.
griptape
Griptape is a modular Python framework for building AI-powered applications that securely connect to your enterprise data and APIs. It offers developers the ability to maintain control and flexibility at every step. Griptape's core components include Structures (Agents, Pipelines, and Workflows), Tasks, Tools, Memory (Conversation Memory, Task Memory, and Meta Memory), Drivers (Prompt and Embedding Drivers, Vector Store Drivers, Image Generation Drivers, Image Query Drivers, SQL Drivers, Web Scraper Drivers, and Conversation Memory Drivers), Engines (Query Engines, Extraction Engines, Summary Engines, Image Generation Engines, and Image Query Engines), and additional components (Rulesets, Loaders, Artifacts, Chunkers, and Tokenizers). Griptape enables developers to create AI-powered applications with ease and efficiency.