Git Product home page Git Product logo

hivisionidphotos's Introduction

HivisionIDPhoto

English / 中文 / 日本語 / 한국어

GitHub SwanHub Demo zhihu Spaces Static Badge

Zeyi-Lin%2FHivisionIDPhotos | Trendshift


相关项目

  • SwanLab:训练人像抠图模型全程用它来分析和监控,以及和实验室同学协作交流,大幅提升了训练效率。

🤩 项目更新

  • 在线体验: SwanHub DemoSpaces

  • 2024.9.5: 更新 Restful API 文档

  • 2024.9.2: 更新调整照片 KB 大小DockerHub

  • 2023.12.1: 更新API 部署(基于 fastapi)

  • 2023.6.20: 更新预设尺寸菜单

  • 2023.6.19: 更新排版照

Overview

🚀 谢谢你对我们的工作感兴趣。您可能还想查看我们在图像领域的其他成果,欢迎来信:[email protected].

HivisionIDPhoto 旨在开发一种实用的证件照智能制作算法。

它利用一套完善的模型工作流程,实现对多种用户拍照场景的识别、抠图与证件照生成。

HivisionIDPhoto 可以做到:

  1. 轻量级抠图(仅需 CPU 即可快速推理)
  2. 根据不同尺寸规格生成不同的标准证件照、六寸排版照
  3. 美颜(waiting)
  4. 智能换正装(waiting)

如果 HivisionIDPhoto 对你有帮助,请 star 这个 repo 或推荐给你的朋友,解决证件照应急制作问题!


🔧 环境安装与依赖

  • Python >= 3.7(项目主要测试在 python 3.10)
  • onnxruntime
  • OpenCV
  • Option: Linux, Windows, MacOS

1. 克隆项目

git clone https://github.com/Zeyi-Lin/HivisionIDPhotos.git
cd  HivisionIDPhotos

2. (重要)安装依赖环境

建议 conda 创建一个 python3.10 虚拟环境后,执行以下命令

pip install -r requirements.txt
pip install -r requirements-app.txt

3. 下载权重文件

在我们的Release下载权重文件hivision_modnet.onnx (24.7MB),存到项目的hivision/creator/weights目录下。


🚀 运行 Gradio Demo

python app.py

运行程序将生成一个本地 Web 页面,在页面中可完成证件照的操作与交互。


🚀 Python 推理

1. 证件照制作

输入 1 张照片,获得 1 张标准证件照和 1 张高清证件照的 4 通道透明 png

python inference.py -i demo/images/test.jpg -o ./idphoto.png --height 413 --width 295

2. 增加底色

输入 1 张 4 通道透明 png,获得 1 张增加了底色的图像)

python inference.py -t add_background -i ./idphoto.png -o ./idhoto_ab.jpg  -c 000000 -k 30

3. 得到六寸排版照

输入 1 张 3 通道照片,获得 1 张六寸排版照

python inference.py -t generate_layout_photos -i ./idhoto_ab.jpg -o ./idhoto_layout.jpg  --height 413 --width 295 -k 200

⚡️ 部署 API 服务

启动后端

python deploy_api.py

请求 API 服务 - Python Request

1. 证件照制作

输入 1 张照片,获得 1 张标准证件照和 1 张高清证件照的 4 通道透明 png

import requests

url = "http://127.0.0.1:8080/idphoto"
input_image_path = "demo/images/test.jpg"

files = {"input_image": open(input_image_path, "rb")}
data = {"height": 413, "width": 295}

response = requests.post(url, files=files, data=data).json()

# response为一个json格式字典,包含status、image_base64_standard和image_base64_hd三项
print(response)

2. 增加底色

输入 1 张 4 通道透明 png,获得 1 张增加了底色的图像

import requests

url = "http://127.0.0.1:8080/add_background"
input_image_path = "test.png"

files = {"input_image": open(input_image_path, "rb")}
data = {"color": '638cce', 'kb': None}

response = requests.post(url, files=files, data=data).json()

# response为一个json格式字典,包含status和image_base64
print(response)

3. 得到六寸排版照

输入 1 张 3 通道照片,获得 1 张六寸排版照

import requests

url = "http://127.0.0.1:8080/generate_layout_photos"
input_image_path = "test.jpg"

files = {"input_image": open(input_image_path, "rb")}
data = {"height": 413, "width": 295, "kb": 200}

response = requests.post(url, files=files, data=data).json()

# response为一个json格式字典,包含status和image_base64
print(response)

更多请求方式请参考 API 文档,含 Python 脚本请求、Python Request 请求、Java 请求。


🐳 Docker 部署

1. 拉取或构建镜像

以下方式三选一

方式一:拉取镜像:

docker pull linzeyi/hivision_idphotos:v1
docker tag linzeyi/hivision_idphotos:v1 hivision_idphotos

国内拉取加速:

docker pull registry.cn-hangzhou.aliyuncs.com/swanhub/hivision_idphotos:v1
docker tag registry.cn-hangzhou.aliyuncs.com/swanhub/hivision_idphotos:v1 hivision_idphotos

方式二:Dockrfile 直接构建镜像:

在确保将模型权重文件hivision_modnet.onnx放到hivision/creator/weights下后,在项目根目录执行:

docker build -t hivision_idphotos .

方式三:Docker compose 构建:

确保将模型权重文件 hivision_modnet.onnx 放在hivision/creator/weights下后,在项目根目录下执行:

docker compose build

镜像打包完成后,运行以下命令启动 Gradio 服务:

docker compose up -d

2. 运行 Gradio Demo

等待镜像封装完毕后,运行以下指令,即可开启 Gradio Demo 服务:

docker run -p 7860:7860 hivision_idphotos

在你的本地访问 http://127.0.0.1:7860 即可使用。

3. 运行 API 后端服务

docker run -p 8080:8080 hivision_idphotos python3 deploy_api.py

🌲 友情链接


📖 引用项目

  1. MTCNN:
@software{ipazc_mtcnn_2021,
    author = {ipazc},
    title = {{MTCNN}},
    url = {https://github.com/ipazc/mtcnn},
    year = {2021},
    publisher = {GitHub}
}
  1. ModNet:
@software{zhkkke_modnet_2021,
    author = {ZHKKKe},
    title = {{ModNet}},
    url = {https://github.com/ZHKKKe/MODNet},
    year = {2021},
    publisher = {GitHub}
}

💻 开发小贴士

1. 如何修改预设尺寸?

修改size_list_CN.csv后再次运行 app.py 即可,其中第一列为尺寸名,第二列为高度,第三列为宽度。


📧 联系我们

如果您有任何问题,请发邮件至 [email protected]


贡献者

Zeyi-LinSAKURA-CATFeudalmanswpfYKaikaikaifangShaohonChenKashiwaByte


StarHistory

Star History Chart

hivisionidphotos's People

Contributors

zeyi-lin avatar sakura-cat avatar nexisato avatar houseme avatar swpfy avatar eltociear avatar kashiwabyte avatar ronaldoshuang avatar houhoufm avatar malobaidan avatar neverbiasu avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.