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.

目录
相关文章
|
6月前
|
应用服务中间件 网络安全 nginx
手把手教你使用 Docker 部署 Nginx 教程
本文详解Nginx核心功能与Docker部署优势,涵盖镜像拉取、容器化部署(快速、挂载、Compose)、HTTPS配置及常见问题处理,助力高效搭建稳定Web服务。
2624 4
|
6月前
|
应用服务中间件 Linux nginx
在虚拟机Docker环境下部署Nginx的步骤。
以上就是在Docker环境下部署Nginx的步骤。需要注意,Docker和Nginix都有很多高级用法和细节需要掌握,以上只是一个基础入门级别的教程。如果你想要更深入地学习和使用它们,请参考官方文档或者其他专业书籍。
305 5
|
6月前
|
自然语言处理 监控 API
速卖通商品详情API秘籍!轻松获取SKU属性数据
速卖通商品详情API(aliexpress.item.get)支持通过编程获取商品标题、价格、SKU、库存、销量、物流模板、评价及店铺信息,适用于价格监控、选品分析等场景。接口支持多语言返回,采用AppKey+AppSecret+Token认证,需签名验证,确保安全调用。
|
6月前
|
安全 API
亚马逊商品详情 API 秘籍!轻松获取 SKU 属性数据
亚马逊商品详情API是官方接口,通过ASIN获取商品标题、价格、库存、评价等50余项数据,支持多站点查询。包含Product Advertising API与MWS两类,分别用于商品信息获取和卖家店铺管理,采用AWS4-HMAC-SHA256认证,保障请求安全。
|
6月前
|
存储 NoSQL Redis
手把手教你用 Docker 部署 Redis
Redis是高性能内存数据库,支持多种数据结构,适用于缓存、消息队列等场景。本文介绍如何通过Docker快速拉取轩辕镜像并部署Redis,涵盖快速启动、持久化存储及docker-compose配置,助力开发者高效搭建稳定服务。
1960 8
|
6月前
|
JSON 缓存 API
淘宝天猫商品详情API秘籍!轻松获取SKU属性数据
淘宝商品详情API(taobao.item.get)可获取商品标题、价格、SKU、库存等全量信息,支持RESTful调用,返回JSON数据,适用于电商导购与竞品分析。需企业实名认证,申请权限后通过签名加密请求。Python示例展示如何调用接口,配合fields参数可优化性能,应对频率限制与数据延迟建议轮询+缓存策略。
|
6月前
|
存储 关系型数据库 MySQL
MySQL Docker 容器化部署全指南
MySQL是一款开源关系型数据库,广泛用于Web及企业应用。Docker容器化部署可解决环境不一致、依赖冲突问题,实现高效、隔离、轻量的MySQL服务运行,支持数据持久化与快速迁移,适用于开发、测试及生产环境。
906 4
|
6月前
|
缓存 监控 前端开发
顺企网 API 开发实战:搜索 / 详情接口从 0 到 1 落地(附 Elasticsearch 优化 + 错误速查)
企业API开发常陷参数、缓存、错误处理三大坑?本指南拆解顺企网双接口全流程,涵盖搜索优化、签名验证、限流应对,附可复用代码与错误速查表,助你2小时高效搞定开发,提升响应速度与稳定性。
|
6月前
|
JSON 算法 API
Python采集淘宝商品评论API接口及JSON数据返回全程指南
Python采集淘宝商品评论API接口及JSON数据返回全程指南

热门文章

最新文章