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.

目录
相关文章
|
3月前
|
存储 供应链 监控
1688商品数据实战:API搜索接口开发与供应链分析应用
本文详细介绍了如何通过1688开放API实现商品数据的获取与应用,涵盖接入准备、签名流程、数据解析存储及商业化场景。开发者可完成智能选品、价格监控和供应商评级等功能,同时提供代码示例与问题解决方案,确保法律合规与数据安全。适合企业开发者快速构建供应链管理系统。
|
16天前
|
监控 供应链 数据库连接
电商API:销量监控与竞品分析利器
电商数据接口API在现代电商运营中至关重要,可实现品牌价格、销量、评论等数据监控,优化销售策略。接入主流平台如淘宝、天猫、京东等API,或使用RPA技术取数,保障数据安全与效率。通过数据库连接、ERP直连等方式整合分析数据,监控竞品与价格,掌握市场动态。同时,注重数据安全性、技术支持及成本效益,助力企业在竞争中脱颖而出,提升业务效率与竞争力。
47 0
|
3月前
|
人工智能 自然语言处理 API
零门槛,即刻拥有DeepSeek-R1满血版——调用API及部署各尺寸模型
本文介绍了如何利用阿里云技术快速部署和使用DeepSeek系列模型,涵盖满血版API调用和云端部署两种方案。DeepSeek在数学、代码和自然语言处理等复杂任务中表现出色,支持私有化部署和企业级加密,确保数据安全。通过详细的步骤和代码示例,帮助开发者轻松上手,提升工作效率和模型性能。解决方案链接:[阿里云DeepSeek方案](https://www.aliyun.com/solution/tech-solution/deepseek-r1-for-platforms?utm_content=g_1000401616)。
零门槛,即刻拥有DeepSeek-R1满血版——调用API及部署各尺寸模型
|
4月前
|
Cloud Native 安全 Serverless
云原生应用实战:基于阿里云Serverless的API服务开发与部署
随着云计算的发展,Serverless架构日益流行。阿里云函数计算(Function Compute)作为Serverless服务,让开发者无需管理服务器即可运行代码,按需付费,简化开发运维流程。本文从零开始,介绍如何使用阿里云函数计算开发简单的API服务,并探讨其核心优势与最佳实践。通过Python示例,演示创建、部署及优化API的过程,涵盖环境准备、代码实现、性能优化和安全管理等内容,帮助读者快速上手Serverless开发。
|
3月前
|
人工智能 测试技术 API
Ollama本地模型部署+API接口调试超详细指南
本文介绍了如何使用Ollama工具下载并部署AI大模型(如DeepSeek-R1、Llama 3.2等)。首先,访问Ollama的官方GitHub页面下载适合系统的版本并安装。接着,在终端输入`ollama`命令验证安装是否成功。然后,通过命令如`ollama run Llama3.2`下载所需的AI模型。下载完成后,可以在控制台与AI模型进行对话,或通过快捷键`control+d`结束会话。为了更方便地与AI互动,可以安装GUI或Web界面。此外,Ollama还提供了API接口,默认支持API调用,用户可以通过Apifox等工具调试这些API。
|
6月前
|
存储 人工智能 API
AgentScope:阿里开源多智能体低代码开发平台,支持一键导出源码、多种模型API和本地模型部署
AgentScope是阿里巴巴集团开源的多智能体开发平台,旨在帮助开发者轻松构建和部署多智能体应用。该平台提供分布式支持,内置多种模型API和本地模型部署选项,支持多模态数据处理。
1548 4
AgentScope:阿里开源多智能体低代码开发平台,支持一键导出源码、多种模型API和本地模型部署
|
4月前
|
机器学习/深度学习 JSON 数据可视化
电商API接口数据与市场趋势分析的深度融合
电商API接口数据与市场趋势分析的深度融合
|
30天前
|
开发者 Docker 容器
获取Docker基础使用方法:让容器化变得轻松。
对于Docker的初学者来说,了解这些基础知识点就足够了。实践是最好的老师,越是动手操作,对Docker的理解会越深。祝阅读这篇文章的开发者们一切顺利,愿你在Docker的海洋中航行顺利!
84 17
|
1月前
|
关系型数据库 MySQL Docker
|
2月前
|
Ubuntu Linux Docker
Docker容器的实战讲解
这只是Docker的冰山一角,但是我希望这个简单的例子能帮助你理解Docker的基本概念和使用方法。Docker是一个强大的工具,它可以帮助你更有效地开发、部署和运行应用。
144 27