Webservice.deploy_from_image失败,出现“ AttributeError:'str'对象没有属性'creation_state'”

时间:2018-11-29 22:01:30

标签: azure-machine-learning-service

我正在尝试使用新的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'

我从1.68版本的SDK开始,并刚刚升级到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)

2 个答案:

答案 0 :(得分:2)

我知道了。也许这会帮助别人。 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)

答案 1 :(得分:0)

我看到您已经在代码中找到错误。我只想添加一些东西。

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

但是,我可以同意,乍看之下SDK的许多功能很难理解。我也经历过类似的挣扎,但现在我开始真正地在SDK documentation中找到自己的出路。而且,如果您查看Webservice.deploy_from_image()函数的documentation,可以看到应该传递图像对象,而不是str