【以下的问题经过翻译处理】 你好
我创建了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}