AzureML部署Docker镜像至Web服务时遇模型类型错误求助
问题排查与解决方案
错误原因
报错提示Models must either be of type azureml.core.Model or a str path to a file or folder,核心问题是调用Model.package(ws, [models_latest], inf_conf)时,传入的models_latest不符合参数要求:该方法要求模型列表中的元素必须是已注册的azureml.core.Model对象,或者指向模型文件/文件夹的字符串路径,而当前models_latest的类型不满足这两个条件。
修复方案
根据模型的实际存储情况,选择以下两种修复方式之一:
方式1:模型已在Azure ML工作区注册
如果models_latest是已注册模型的名称,通过Model.get()方法获取合法的Model对象:
from azureml.core import Model # 替换为你的注册模型名称 model_name = "your-registered-model-name" models_latest = Model.get(ws, name=model_name) # 后续代码保持不变 env = Environment.from_conda_specification("env", "../Environments.yml") inf_conf = InferenceConfig( entry_script="score.py", environment=env) docker_image = Model.package(ws, [models_latest], inf_conf) docker_image.wait_for_creation(show_output=True)
方式2:模型是本地文件/文件夹
如果模型存储在本地,直接传入文件或文件夹的字符串路径:
# 替换为你的本地模型路径,比如"./models/latest_model" models_latest = "./path/to/your/local/model" # 后续代码保持不变 env = Environment.from_conda_specification("env", "../Environments.yml") inf_conf = InferenceConfig( entry_script="score.py", environment=env) docker_image = Model.package(ws, [models_latest], inf_conf) docker_image.wait_for_creation(show_output=True)
验证修复
修改后重新运行代码,Model.package()将能正确识别模型,后续的镜像打包和服务部署流程即可正常执行。
内容的提问来源于stack exchange,提问作者user17260574
相关产品推荐
相关产品推荐

