1

我正在尝试使用新的 ML 服务 SDK 将映像部署到 Azure 容器实例中的 Web 服务。该Webservice.deploy_from_image方法失败并显示以下消息:

> Traceback (most recent call last):   File
> "c:/Users/chrcam/git/amlIrisClassification/deploy_iris_to_aci.py",
> line 18, in <module>
>     workspace = ws)   File "C:\Users\chrcam\AppData\Local\Programs\Python\Python36\lib\site-packages\azureml\core\webservice\webservice.py",
> line 258, in deploy_from_image
>     return deployment_config._webservice_type._deploy(workspace, name, image, deployment_config)   File
> "C:\Users\chrcam\AppData\Local\Programs\Python\Python36\lib\site-packages\azureml\core\webservice\aci.py",
> line 121, in _deploy
>     deployment_config.validate_image(image)   File "C:\Users\chrcam\AppData\Local\Programs\Python\Python36\lib\site-packages\azureml\core\webservice\webservice.py",
> line 883, in validate_image
>     if image.creation_state != 'Succeeded': AttributeError: 'str' object has no attribute 'creation_state'

我从 SDK 的 1.68 版本开始,然后升级到 1.80,结果相同。

模型和图像都注册在我的工作区中。

代码相当简单。任何反馈或方向都会有所帮助。

from azureml.core import Workspace
from azureml.core.webservice import Webservice
from azureml.core.webservice import AciWebservice

ws = Workspace.from_config()

image_name = 'irisimage'
service_name = 'aciiris'

aciconfig = AciWebservice.deploy_configuration(cpu_cores = 1, 
                                               memory_gb = 1, 
                                               tags = {"data": "iris", "type": "classification"},
                                               description = 'Iris Classification')

service = Webservice.deploy_from_image(deployment_config = aciconfig,
                                            image = image_name,
                                            name = service_name,
                                            workspace = ws)

service.wait_for_deployment(show_output = True)
print(service.state)
4

2 回答 2

5

我想到了。也许这会帮助别人。deploy_from_image 方法需要一个 Image 对象,而不是图像名称作为参数。该错误消息具有误导性,我认为 SDK 中可能存在错误。

这是更新的代码:

from azureml.core import Workspace
from azureml.core import Image
from azureml.core.webservice import Webservice
from azureml.core.webservice import AciWebservice

ws = Workspace.from_config()

image_name = 'irisimage'
service_name = 'aciiris'

image = Image(name=image_name, workspace=ws)

aciconfig = AciWebservice.deploy_configuration(cpu_cores = 1, 
                                               memory_gb = 1, 
                                               tags = {"data": "iris", "type": "classification"},
                                               description = 'Iris Classification')

service = Webservice.deploy_from_image(deployment_config = aciconfig,
                                            image = image,
                                            name = service_name,
                                            workspace = ws)

service.wait_for_deployment(show_output = True)
print(service.state)
于 2018-11-29T22:25:13.413 回答
1

我看到您已经在代码中发现了错误。我只是想补充一些东西。

错误消息实际上直接指向您的错误所在。它尝试从调用传递creation_state的对象中获取属性。但是,错误消息指出它无法从对象获取属性,这告诉您不应传递图像的名称,而应传递其他对象。imageWebservice.deploy_from_image()creation_statestrstr

但是,我同意 SDK 中的许多功能乍一看很难理解。我也有过类似的挣扎,但我现在开始真正在SDK 文档中找到自己的方式。如果您查看该函数的文档Webservice.deploy_from_image(),您会发现应该传递一个图像对象,而不是一个str.

于 2018-11-30T10:44:48.540 回答