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

简介: DeepFace【部署 02】轻量级人脸识别和面部属性分析框架(实时分析+API+Docker部署+命令行接口)

2.10 Real Time Analysis

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

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

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

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

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

from deepface import DeepFace
if __name__ == "__main__":
    DeepFace.stream("tests/dataset")

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

2.11 API

DeepFace serves an API as well. You can clone [/api](https://github.com/serengil/deepface/tree/master/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

报错:

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/deepface/scripts/Dockerfile: no such file or directory
Unable to find image 'deepface:latest' locally
docker: Error response from daemon: pull access denied for deepface, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

解决【不要 cd scripts】:

./scripts/dockerize.sh
# 这个过程取决于网速【时间会比较久】

2.13 Command Line Interface

DeepFace comes with a command line interface as well. You are able to access its functions in command line as shown below. The command deepface expects the function name as 1st argument and function arguments thereafter.

#face verification
$ deepface verify -img1_path tests/dataset/img1.jpg -img2_path tests/dataset/img2.jpg
#facial analysis
$ deepface analyze -img_path tests/dataset/img1.jpg

实际的测试环境为Conda 的 deepface虚拟环境下:

You can also run these commands if you are running deepface with docker. Please follow the instructions in the shell script.

目录
相关文章
|
10天前
|
自然语言处理 监控 API
小红书爆文解码:用API分析互动数据,精准指导创作方向
在内容为王时代,爆文背后有科学公式!通过小红书API抓取百万笔记数据,提炼出点赞转化率、收藏价值系数、评论情感值三大核心指标,揭秘爆文特征不等式与内容元素矩阵,手把手教你用数据驱动创作,实现从0到百万曝光的逆袭!
84 0
|
11天前
|
数据采集 API
京东:调用用户行为API分析购买路径,优化页面跳转逻辑
京东通过整合用户行为API,构建购买路径分析体系,运用马尔可夫链模型识别高损耗、断裂与冗余路径,优化页面跳转逻辑。实施流程合并、预加载及实时干预策略,转化率提升30.2%,路径缩短34.9%,跳转失败率下降78.7%,实现数据驱动的精细化运营。
111 0
|
12天前
|
缓存 监控 供应链
唯品会自定义 API 自定义操作深度分析及 Python 实现
唯品会开放平台提供丰富API,支持商品查询、订单管理、促销活动等电商全流程操作。基于OAuth 2.0认证机制,具备安全稳定的特点。通过组合调用基础接口,可实现数据聚合、流程自动化、监控预警及跨平台集成,广泛应用于供应链管理、数据分析和智能采购等领域。结合Python实现方案,可高效完成商品搜索、订单分析、库存监控等功能,提升电商运营效率。
|
12天前
|
缓存 监控 供应链
京东自定义 API 操作深度分析及 Python 实现
京东开放平台提供丰富API接口,支持商品、订单、库存等电商全链路场景。通过自定义API组合调用,可实现店铺管理、数据分析、竞品监控等功能,提升运营效率。本文详解其架构、Python实现与应用策略。
机器学习/深度学习 搜索推荐 算法
37 0
缓存 监控 供应链
28 0
缓存 监控 数据挖掘
28 0
|
27天前
|
数据采集 数据可视化 API
巧用唯品会 API,精准分析唯品会女性时尚商品销售趋势
本文介绍如何利用唯品会API分析女性时尚商品销售趋势。通过API获取数据、清洗处理后,结合时间序列分析与可视化,精准把握市场需求变化,助力商家优化库存和营销策略,提升用户体验与营收。
84 0
|
28天前
|
数据采集 搜索推荐 API
苏宁易购 API 接口:苏宁易购平台促销活动用户参与度分析
本文探讨如何利用苏宁易购API接口进行促销活动中的用户参与度分析。通过API获取数据,定义关键指标如点击率、转化率及参与度指数,并结合统计分析与回归模型揭示用户行为模式。以“618大促”为例,展示数据驱动的优化策略及其成效,提升用户粘性与销售转化。
50 0
|
1月前
|
JSON 大数据 API
巧用苏宁易购 API,精准分析苏宁易购家电销售大数据
在数据驱动的电商时代,精准分析销售数据能助力企业优化库存、提升营销效果。本文详解如何利用苏宁易购API获取家电销售数据,结合Python进行数据清洗与统计分析,实现销量预测与洞察提取,帮助企业降本增效。
44 0