如何使用本地包创建 Azure 机器学习评分镜像

我在 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

要解决远程模型部署问题,请遵循文档

输入图片说明

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注