DeepFace【部署 02】轻量级人脸识别和面部属性分析框架(实时分析+API+Docker部署

轻量级人脸识别和面部属性分析框架

2.10 Real Time Analysis

你也可以运行deepface实时视频。流功能将访问您的网络摄像头,并应用面部识别和面部属性分析。如果能连续聚焦5帧,该函数就开始分析一帧。然后,它会在5秒后显示结果。

DeepFace.stream(db_path = "C:/User/Sefik/Desktop/database")

stock-3.jpg
尽管人脸识别是基于一次性学习,但你也可以使用一个人的多张人脸照片。您应该重新安排目录结构,如下所示。

user
├── database
│   ├── Alice
│   │   ├── Alice1.jpg
│   │   ├── Alice2.jpg
│   ├── Bob
│   │   ├── Bob.jpg

这个功能是通过比对db_path下的人脸来进行识别的。实际测试代码如下:

from deepface import DeepFace

if __name__ == "\_\_main\_\_":
    DeepFace.stream("tests/dataset") 

测试截图如下,由于使用的是项目内的图片数据集,图片比对结果看看就好:

realtime.jpg

2.11 API

DeepFace serves an API as well. You can clone [/api]( ) folder and run the api via gunicorn server. This will get a rest service up. In this way, you can call deepface from an external system such as mobile app or web.

cd scripts
./service.sh

Linux系统使用这个命令是前台启动,实际的启动用的是shell脚本,内容如下:

#!/bin/bash
nohup python -u ./api/api.py > ./deepfacelog.out 2>&1 &

Face recognition, facial attribute analysis and vector representation functions are covered in the API. You are expected to call these functions as http post methods. Default service endpoints will be http://localhost:5000/verify for face recognition, http://localhost:detector_backend for facial attribute analysis, and http://localhost:5000/represent for vector representation. You can pass input images as exact image paths on your environment, base64 encoded strings or images on web. Here, you can find a postman project to find out how these methods should be called.
这里仅贴出如何传递base64进行接口调用:

{
    "img\_path": "data:image/,image\_base64\_str"
}

仅看一下base64相关源码:

def load\_image(img):
    # The image is a base64 string
    if img.startswith("data:image/"):
        return loadBase64Img(img)

def loadBase64Img(uri):
    encoded_data = uri.split(",")[1]
    nparr = np.fromstring(base64.b64decode(encoded_data), np.uint8)
    img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
    return img

2.12 Dockerized Service

You can deploy the deepface api on a kubernetes cluster with docker. The following shell script will serve deepface on localhost:5000. You need to re-configure the Dockerfile if you want to change the port. Then, even if you do not have a development environment, you will be able to consume deepface services such as verify and analyze. You can also access the inside of the docker image to run deepface related commands. Please follow the instructions in the shell script.

cd scripts
./dockerize.sh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值