使用Azure IoT Edge在设备端部署戴口罩识别应用

19 篇文章 0 订阅

原作者视频等教程如下,我在此进行自己的补充和总结。

Azure 智能边缘 之 Azure IoT Edge 十分钟入门系列文章目录 - 51Azure.cloud

【基础】

该教程融合了Azure中 容器/机器学习/IoT 等技术,较为复杂,因此需要提前掌握一定的相关基础。

训练并打包 Azure 机器学习模块以将其部署到 IoT Edge 设备 - Learn | Microsoft Docs

【注意】

有几个需要注意地地方:

1:mask模型可以直接使用作者的,不用自己训练。

2:在创建object-detect模型项目时,切记选择项目类型Domains为“General (compact)”。

如此,当完成训练后,才可以Export为docker(Linux)。否则只能发布为api。

3:ACR的域名是xxx.azurecr.io,不要写错为azureacr。

4:建议打开ACR的“Admin user”开关。//起初没有验证,不知是否与报错有关

5:应该创建的是IoT Edge设备,而不是IoT Devices设备。

因此建议先通过portal,在Iot hub手动创建IoT Edge设备。而【不要】使用如下命令创建设备。官方文档里个别地方有错。

XXX 不要使用!不要使用!不要使用! XXX
az iot hub device-identity create --hub-name <iot-hub-name> --device-id <device-id>

然后点击该Edge名称进入可以查看到连接字符串,也可以使用命令查看。

az iot hub device-identity connection-string show --device-id linuxedge --hub-name <youriothubname> --output table

6:Linux设备中不要安装docker。

由于ACR只支持moby-engine,需要在设备上安装moby-engine。因此如果设备中已安装docker CCE,则会被覆盖掉。

7:在为Edge 设备Set Modules之前,$edgeAgent处于Running,而$edgeHub处于Error中。这是正常的。等待Set Modules之后,$edgeAgent会变为running。

8:使用视频中的“对称加密验证”,而不是"X509"。

9:【注意】教程这里的端口号忘记了添加双引号""。

在Container Create Options 中设置容器端口相关的配置:

{
  "HostConfig": {
    "PortBindings": {
      "80/tcp": [{
        "HostPort": "81"
      }]
    }
  }
}

训练模型的部分

安装moby引擎

务必不要在已安装docker CCE的机器上重新安装moby-engin docker。

安装IoT Edge

更新设备上的包列表。

sudo apt-get update


查看可用的 IoT Edge 和 IoT 标识服务版本。

apt list -a aziot-edge aziot-identity-service


要安装最新版本的 IoT Edge 和 IoT 标识服务包,请使用以下命令:

sudo apt-get install aziot-edge

apt list -a aziot-edge aziot-identity-service
Listing... Done
aziot-edge/bionic,now 1.2.5-1 amd64 [installed]
aziot-edge/bionic 1.2.4-1 amd64
aziot-edge/bionic 1.2.3-1 amd64
aziot-edge/bionic 1.2.2-1 amd64
aziot-edge/bionic 1.2.1-1 amd64
aziot-edge/bionic 1.2.0-1 amd64
aziot-edge/bionic 1.2.0~rc4-1 amd64
aziot-edge/bionic 1.2.0~rc4~device-update-tutorial-1 amd64

aziot-identity-service/bionic,now 1.2.4-1 amd64 [installed,automatic]
aziot-identity-service/bionic 1.2.3-1 amd64
aziot-identity-service/bionic 1.2.2-1 amd64
aziot-identity-service/bionic 1.2.1-1 amd64
aziot-identity-service/bionic 1.2.0-1 amd64
aziot-identity-service/bionic 1.2.0~rc4-1 amd64
aziot-identity-service/bionic 1.2.0~rc4~device-update-tutorial-1 amd64

使用对称密钥进行身份验证

iotedge config mp --connection-string 'HostName=iothubname.azure-devices.net;DeviceId=linuxedge;SharedAccessKey=++02YJvIv6HiWP8WLx1rGI11N0mehQen3esrAFfx5rk='

sudo iotedge config apply

验证成功的配置

sudo iotedge system status
System services:
    aziot-edged             Running
    aziot-identityd         Down - activating
    aziot-keyd              Running
    aziot-certd             Ready
    aziot-tpmd              Ready

aziot-identityd is in a bad state because:
aziot-identityd.service: Down - activating : Printing the last 10 log lines.
-- Logs begin at Sat 2021-09-18 03:23:02 UTC, end at Thu 2021-12-02 02:50:51 UTC. --
Dec 02 02:50:48 fei-918-vm aziot-identityd[8191]: 2021-12-02T02:50:48Z [INFO] - Could not reconcile Identities with current device data. Reprovisioning.
Dec 02 02:50:48 fei-918-vm aziot-identityd[8191]: 2021-12-02T02:50:48Z [INFO] - Updated device info for linuxedge.
Dec 02 02:50:48 fei-918-vm aziot-identityd[8191]: 2021-12-02T02:50:48Z [ERR!] - Failed to provision with IoT Hub, and no valid device backup was found: Hub client error
Dec 02 02:50:48 fei-918-vm aziot-identityd[8191]: 2021-12-02T02:50:48Z [ERR!] - service encountered an error
Dec 02 02:50:48 fei-918-vm aziot-identityd[8191]: 2021-12-02T02:50:48Z [ERR!] - caused by: Hub client error
Dec 02 02:50:48 fei-918-vm aziot-identityd[8191]: 2021-12-02T02:50:48Z [ERR!] - caused by: ErrorCode:IotHubUnauthorizedAccess;Unauthorized
Dec 02 02:50:48 fei-918-vm aziot-identityd[8191]: 2021-12-02T02:50:48Z [ERR!] -    0: <unknown>
Dec 02 02:50:48 fei-918-vm aziot-identityd[8191]:    1: <unknown>
Dec 02 02:50:48 fei-918-vm systemd[1]: aziot-identityd.service: Main process exited, code=exited, status=1/FAILURE
Dec 02 02:50:48 fei-918-vm systemd[1]: aziot-identityd.service: Failed with result 'exit-code'.

查看其状态。如果出现[ERR!]报错,则说明以上IotHub连接字符串没有生效。

可以进入到文件查看或修改。修改完后,再次将其生效。

sudo vi /etc/aziot/config.toml

sudo iotedge config apply

接下来Portal中查看发现,$edgeAgent,已正常运行,$edgeHub还处于Error中,其中IoT Edge Runtime Response为417错误,"Agent deployment configuration is not set"。

接下来,在portal中为linuxedge Set modules,包括配置ACR Credentials和添加IoT Edge Modules。

随后回来发现,不一会儿,edgeHub和mask也都处于running状态,

IoT Edge Runtime Response也变为200——OK。说明部署正常。

sudo iotedge list
NAME             STATUS           DESCRIPTION      CONFIG
edgeAgent        running          Up 41 seconds    mcr.microsoft.com/azureiotedge-agent:1.1
edgeHub          running          Up 33 seconds    mcr.microsoft.com/azureiotedge-hub:1.1
mask             running          Up 9 seconds     feiacr.azurecr.io/mask:v1

视频中是用浏览器或以POSTMAN做测试的,由于我的Ubuntu没有homedesk用户界面,因此用命令行测试。

curl 127.0.0.1:81
CustomVision.ai model host harness

和浏览器访问返回内容一致,由此可见,部署都是正确的。

最后,测试

采用url测试方式

测试1:

curl -X POST http://127.0.0.1:81/url  -d '{"url": "https://img0.baidu.com/it/u=3815600312,411717689&fm=26&fmt=auto"}'
{"created":"2021-12-02T03:24:15.019615","id":"","iteration":"","predictions":[{"boundingBox":{"height":0.98331047,"left":0.06794183,"top":-0.03540233,"width":0.46181308},"probability":0.84679085,"tagId":0,"tagName":"mask"},{"boundingBox":{"height":0.9611762,"left":0.29011689,"top":-0.09925044,"width":0.55135872},"probability":0.50089467,"tagId":0,"tagName":"mask"}],"project":""}

测试2:

curl -X POST http://127.0.0.1:81/url  -d '{"url": "https://t7.baidu.com/it/u=3013350550,279858396&fm=193&f=GIF"}'
{"created":"2021-12-02T03:27:58.776046","id":"","iteration":"","predictions":[{"boundingBox":{"height":0.87865715,"left":-0.0263336,"top":0.03156172,"width":0.3192271},"probability":0.89614129,"tagId":1,"tagName":"nomask"},{"boundingBox":{"height":0.84089283,"left":0.16703572,"top":0.11236664,"width":0.61882507},"probability":0.87163663,"tagId":1,"tagName":"nomask"},{"boundingBox":{"height":0.91119411,"left":0.46338932,"top":0.15371524,"width":0.52660682},"probability":0.82030243,"tagId":1,"tagName":"nomask"},{"boundingBox":{"height":0.69155405,"left":0.34916137,"top":0.04281605,"width":0.54162274},"probability":0.39353225,"tagId":1,"tagName":"nomask"},{"boundingBox":{"height":0.79550083,"left":0.04651661,"top":-0.00193247,"width":0.55670231},"probability":0.12784216,"tagId":1,"tagName":"nomask"}],"project":""}

参见:

安装 Azure IoT Edge | Azure Docs

注册新设备 - Azure IoT Edge | Azure Docs

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值