我在 Azure DevOps 仓库中保存了一个 pkl 包
使用下面的代码会在工作区中搜索包。如何提供仓库中保存的包呢?
ws = Workspace.get( name=workspace_name, subscription_id=subscription_id, resource_group=resource_group, auth=cli_auth)image_config = ContainerImage.image_configuration( execution_script="score.py", runtime="python-slim", conda_file="conda.yml", description="包含岭回归模型的镜像", tags={"area": "ml", "type": "dev"},)image = Image.create( name=image_name, models=[model], image_config=image_config, workspace=ws)image.wait_for_creation(show_output=True)if image.creation_state != "Succeeded": raise Exception("镜像创建状态: {image.creation_state}")print( "{}(v.{} [{}]) 存储在 {},构建日志在 {}".format( image.name, image.version, image.creation_state, image.image_location, image.image_build_log_uri, ))# 将镜像详情写入 /aml_config/image.jsonimage_json = {}image_json["image_name"] = image.nameimage_json["image_version"] = image.versionimage_json["image_location"] = image.image_locationwith open("aml_config/image.json", "w") as outfile: json.dump(image_json, outfile)
我尝试提供模型的路径,但它失败了,提示包未找到
models = $(System.DefaultWorkingDirectory)/package_model.pkl
回答:
注册模型:通过调用 Model.register() 注册一个文件或文件夹为模型。
除了模型文件本身的内容,您的注册模型还将存储模型元数据——模型描述、标签和框架信息——这些在管理和部署工作区中的模型时会很有用。例如,使用标签,您可以对模型进行分类,并在列出工作区中的模型时应用过滤器。
model = Model.register(workspace=ws, model_name='', # 工作区中注册模型的名称。 model_path='', # 上传并注册为模型的本地文件。 model_framework=Model.Framework.SCIKITLEARN, # 创建模型时使用的框架。 model_framework_version=sklearn.__version__, # 创建模型时使用的 scikit-learn 版本。 sample_input_dataset=input_dataset, sample_output_dataset=output_dataset, resource_configuration=ResourceConfiguration(cpu=1, memory_in_gb=0.5), description='用于预测糖尿病进展的岭回归模型。', tags={'area': 'diabetes', 'type': 'regression'})print('名称:', model.name)print('版本:', model.version)
将机器学习模型部署到 Azure:https://learn.microsoft.com/en-us/azure/machine-learning/how-to-deploy-and-where?tabs=python
要解决远程模型部署问题,请遵循文档。