Greengrass V2机器学习组件

0

【以下的问题经过翻译处理】 你好 我创建了aws greengrass v2 ml组件。

我想在已安装greengrass的树莓派上运行ml模型。因此,我编写了ml组件并部署了它。我期望的结果是我编写的ml代码在树莓派上执行。

这是自定义组件。我参考了https://docs.aws.amazon.com/greengrass/v2/developerguide/ml-customization.html 这个链接。

但是有一个问题。如果我部署了组件,那么显示部署完成。但是出现了一个错误。从日志来看,似乎存在打开虚拟环境(venv)的问题,或者是tensorflow没有下载。

我想编写一个在组件的recipe中正确打开虚拟环境的脚本。我编写的recipe如下所示。

{ "RecipeFormatVersion": "2020-01-25", "ComponentName": "com.example.jamesML", "ComponentVersion": "1.0.5", "ComponentType": "aws.greengrass.generic", "ComponentDescription": "Capstone Design james machine learning.", "ComponentPublisher": "Me", "ComponentConfiguration": { "DefaultConfiguration": { "accessControl": { "aws.greengrass.ipc.mqttproxy": { "com.example.jamesML:mqttproxy:1": { "policyDescription": "Allows access to publish via topic ml/dlr/image-classification.", "operations": [ "aws.greengrass#PublishToIoTCore" ], "resources": [ "ml/dlr/image-classification" ] } } } } }, "Manifests": [ { "Platform": { "os": "linux", "architecture": "arm" }, "Lifecycle": { "setEnv": { "Script": "cd venv&&activate venv" }, "run": { "RequiresPrivilege": "true", "script": "pip install opencv-python;pip install tensorflow==2.3;python3 james.py" } }, "Artifacts": [ { "Uri": "s3://greengrass-sagemaker-0930/james_ml.zip", "Digest": "CY6f7pUyMRrgbxbKoDMig3GWQCJ4LvKyA5xnhGWGhlY=", "Algorithm": "SHA-256", "Unarchive": "ZIP", "Permission": { "Read": "OWNER", "Execute": "NONE" } } ] } ], "Lifecycle": {} } 您能帮我解决问题吗?是不是我的配方写得有问题?我想知道答案,谢谢!

以下是我部署在树莓派上的Greengrass V2组件的日志: 2022-10-13T10:01:44.004Z [INFO] (pool-2-thread-28) com.example.jamesML: shell-runner-start. {scriptName=services.com.example.jamesML.lifecycle.run.script, serviceName=com.example.jamesML, currentState=STARTING, command=["pip install opencv-python;pip install tensorflow==2.3;python3 james.py"]} 2022-10-13T10:01:45.326Z [INFO] (Copier) com.example.jamesML: stdout. Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple. {scriptName=services.com.example.jamesML.lifecycle.run.script, serviceName=com.example.jamesML, currentState=RUNNING} 2022-10-13T10:01:45.329Z [INFO] (Copier) com.example.jamesML: stdout. Requirement already satisfied: opencv-python in /usr/local/lib/python3.9/dist-packages (4.6.0.66). {scriptName=services.com.example.jamesML.lifecycle.run.script, serviceName=com.example.jamesML, currentState=RUNNING} 2022-10-13T10:01:45.373Z [INFO] (Copier) com.example.jamesML: stdout. Requirement already satisfied: numpy>=1.14.5 in /usr/local/lib/python3.9/dist-packages (from opencv-python) (1.23.4). {scriptName=services.com.example.jamesML.lifecycle.run.script, serviceName=com.example.jamesML, currentState=RUNNING} 2022-10-13T10:01:45.901Z [WARN] (Copier) com.example.jamesML: stderr. WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. {scriptName=services.com.example.jamesML.lifecycle.run.script, serviceName=com.example.jamesML, currentState=RUNNING} 2022-10-13T10:01:47.470Z [INFO] (Copier) com.example.jamesML: stdout. Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple. {scriptName=services.com.example.jamesML.lifecycle.run.script, serviceName=com.example.jamesML, currentState=RUNNING} 2022-10-13T10:01:48.909Z [WARN] (Copier) com.example.jamesML: stderr. ERROR: Could not find a version that satisfies the requirement tensorflow==2.3 (from versions: none). {scriptName=services.com.example.jamesML.lifecycle.run.script, serviceName=com.example.jamesML, currentState=RUNNING} 2022-10-13T10:01:48.910Z [WARN] (Copier) com.example.jamesML: stderr. ERROR: No matching distribution found for tensorflow==2.3. {scriptName=services.com.example.jamesML.lifecycle.run.script, serviceName=com.example.jamesML, currentState=RUNNING} 2022-10-13T10:01:49.161Z [WARN] (Copier) com.example.jamesML: stderr. python3: can't open file 'james.py': [Errno 2] No such file or directory. {scriptName=services.com.example.jamesML.lifecycle.run.script, serviceName=com.example.jamesML, currentState=RUNNING} 2022-10-13T10:01:49.169Z [INFO] (Copier) com.example.jamesML: Run script exited. {exitCode=2, serviceName=com.example.jamesML, currentState=RUNNING}

profile picture
专家
已提问 5 个月前22 查看次数
1 回答
0

【以下的回答经过翻译处理】 你的配方似乎有问题。setenv 用于设置环境变量,而在你的情况下,你正在创建一个名为 Script 值为 cd venv && activate venv 的变量。将 cd venv && activate venv 移动到 Run 生命周期脚本中。你也应该避免使用 "RequiresPrivilege": "true",而是将正确的权限指派给执行脚本的用户(例如 ggcuser)。

tensorflow 找不到的事实可能与 virtualenv 未激活有关。

补充1: 看上去您的环境并没有创建成功,所以您不能修改其中的路径。通常它会在安装生命周期中创建。您可以参考Massimiliano 的样例:https://github.com/awslabs/aws-greengrass-labs-jupyterlab/blob/main/recipes/aws.greengrass.labs.jupyterlab.yaml

补充2: 请注意,要激活虚拟环境,您应该使用 . venv/bin/激活。不要在组件配方中使用 source venv/bin/activate,因为默认情况下这些命令是通过 /bin/sh 运行的,而 /bin/sh 没有 source 命令。

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则