基于face_recognition+tensorflow的实现的人脸一对多搜索、提供web接口。
- python完成具体的人脸对比搜索服务
- Java完成人脸Api的调用并提供对外的web接口
若需要部署项目,您需要以下环境:
- Java8
- mysql
- docker
- ubuntu(非必需)
- redis(非必需)
- nginx(非必需)
创建数据库:db_face_search_service;
使用数据库文件db_face_search_service.sql初始化数据库。
提供两种方式:
1、安装python依赖运行脚本;
2、使用Docker构建;
修改face_encoding_data_service.py中的mysql数据库连接信息:
db_host = 'localhost' | 数据库地址 |
---|---|
db_user='root' | 数据库账户 |
db_password = '123456' | 数据库密码 |
db_name = 'db_face_search_service' | 数据库名 |
1、安装gcc(请自行百度);
2、安装cmake(请自行百度);
3、安装项目依赖:
请安装requirements.txt中的所有依赖
pip install -r requirement.txt
4、运行 app.py即可。
使用Docker可以将环境隔离,不得不说,python需要安装的依赖有点多;
其它系统请自行查阅官网;
此处默认您已成功安装Docker;
使用Docker构建镜像:
进入到Dockerfile所在目录
docker build -t <username>/face-search-service:1 -f Dockerfile .
注意后面有个点 < username >
表示你的用户名,可以在DockerHub
上注册一个账户,后面可以push
自己的镜像上去;
运行镜像:
docker run -d --name face-search-service1 -p 5002:5002 --mount type=bind,source=<your local dir>,target=/usr/src/app/model jamesluozhiwei/face-search-service:1
命令中的< your local dir >
指你系统的一个目录,用于保存训练模型;
至此,您已经运行了人脸搜索的服务;
使用命令查看日志
docker logs face-search-service1
即可查看python 服务日志,如果没有异常信息则运行成功。
修改系统配置:
applicaiton.yml
-
修改数据库连接信息;
-
修改邮箱账户信息;
-
修改python提供的人脸服务地址;
-
修改redis连接信息;
示例:可以新建一个文件作为profile环境隔离: application-dev.yml
spring:
redis:
password: 123456
datasource:
url: jdbc:mysql://localhost:3306/db_face_search_service?useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8
username: root
password: 123456
mail:
default-encoding: UTF-8
# 生产环境请使用465端口、本地可以使用25端口
port: 25
host: smtp.mxhichina.com
username: xxxxx@xxx.xxx
password: 123456
使用Idea
直接运行或者使用maven
打包成jar运行即可。
访问:http://localhost:8080/swagger-ui.html 查看到API。