我正在尝试使用 Azure 的 automl 功能使用简单的数据集来训练模型,该数据集在手动或通过笔记本时工作正常,但不能在 azure devops 管道中工作。创建了一个 azure devops 管道,其中包含与 ML 工作区的所需服务连接。
下面的python代码状态需要的文件已上传,但在运行以下命令进行注册时我无法找到模型,而下面所述的代码上传了它:
我正在尝试通过 az cli 命令而不是通过 python 来训练模型。任何建议。参考https://github.com/SaschaDittmann/MLOps-Lab作为参考,但已更改为 automl 部分,因为此 git repo 不适用于 auto ml,但其余步骤相同。
az ml 模型寄存器 -g $(azureml.resourceGroup) -w $(azureml.workspaceName) -n $(model.Name) -f metadata/run.json --asset-path outputs/models/abc.pkl -d " test" --tag "data"="test" --model-framework ScikitLearn -t metadata/model.json
上面的命令总是给我:- {'Azure-cli-ml Version': '1.12.0', 'Error': ModelPathNotFoundException: Message: Could not locate the provided model_path outputs/models/abc.pkl
##local_run 是 automl 的另一个运行 ID,run.getContext() 是当前运行 ID。
automl_config = AutoMLConfig(task = 'classification',
primary_metric = 'accuracy',
X = X_train,
y = y_train,
n_cross_validations = 2,
**automl_settings)
local_run = exp.submit(automl_config, show_output = True)
local_run = list(exp.get_runs())[0]
children = list(local_run.get_children())
metricslist = {}
for run in children:
properties = run.get_properties()
metrics = {k: v for k, v in run.get_metrics().items() if isinstance(v, float)}
metricslist[int(properties['iteration'])] = metrics
rundata = pd.DataFrame(metricslist).sort_index(1)
best_run, fitted_model = local_run.get_output()
model_path = os.path.join(outputs_folder, model_filename)
#dump(fitted_model, model_path)
# upload the model file explicitly into artifacts
print("Uploading the model into run artifacts RUN ***** ...")
run.upload_file(name="./outputs/models/" +`enter code here` model_filename, path_or_stream=model_path1)
run.upload_file("outputs/models/abc.pkl", path_or_stream=model_path1)
print("Uploaded the model {} to experiment {}".format(model_filename, run.experiment.name))
dirpath = os.getcwd()
print(dirpath)
print("Following files are uploaded ")
print(run.get_file_names())
print("Uploading the model into run artifacts NEW **** ...")
local_run.upload_file(name="./outputs/models/" + model_filename, path_or_stream=model_path1)
local_run.upload_file("outputs/models/abc.pkl", path_or_stream=model_path1)
print("Uploaded the model {} to experiment {}".format(model_filename, local_run.experiment.name))
dirpath = os.getcwd()
print(dirpath)
print("Following files are uploaded ")
print(local_run.get_file_names())
run.complete()