简体   繁体   English

如何从 Azure ML 管道脚本步骤注册 model

[英]How to register model from the Azure ML Pipeline Script step

I am running the pipeline.submit() in AzureML, which has a PythonScriptStep .我在 AzureML 中运行pipeline.submit() ,它有一个PythonScriptStep Inside this step, I download a model from tensorflow-hub, retrain it and save it as a .zip , and finally, I would like to register it in the Azure ML.在这一步中,我从 tensorflow-hub 下载了一个 model ,重新训练并保存为.zip ,最后,我想将它注册到 Z3A580F142203677F153Z30898F6 But as inside the script I do not have a workspace, Model.register() is not the case.但由于在脚本内部我没有工作区, Model.register()并非如此。 So I am trying to use Run.register_model() method as below:所以我正在尝试使用Run.register_model()方法,如下所示:

os.replace(os.path.join('.', archive_name + '.zip'), 
           os.path.join('.', 'outputs', archive_name + '.zip'))

print(os.listdir('./outputs'))
print('========================')

run_context = Run.get_context()
finetuning_model = run_context.register_model(model_name='finetuning_similarity_model',
                                              model_path=os.path.join(archive_name+'.zip'),
                                              tags={},
                                              description="Finetuning Similarity model")

But then I have got an error:但是后来我遇到了一个错误:

ErrorResponse { "error": { "message": "Could not locate the provided model_path retrained.zip in the set of files uploaded to the run: ErrorResponse { "error": { "message": "Could not locate the provided model_path retrained.zip 在上传到运行的文件集中:

despite I have the retrained .zip in the ./outputs dir as we can see from the log:尽管我在.zip目录中有重新训练的./outputs ,我们可以从日志中看到:

['retrained.zip']
========================

I guess that I am doing something wrong?我想我做错了什么?

I was able to fix the same issue ( ModelPathNotFoundException ) by explicitly uploading the model into the run history record before trying to register the model:在尝试注册 model 之前,我可以通过将 model 显式上传到运行历史记录中来解决相同的问题( ModelPathNotFoundException ):

run.upload_file("outputs/my_model.pickle", "outputs/my_model.pickle")

Which I found surprising because this wasn't mentioned in many of the official examples and according to the upload_file() documentation :我发现这很令人惊讶,因为在许多官方示例中以及根据upload_file() 文档都没有提到这一点:

Runs automatically capture file in the specified output directory, which defaults to "./outputs" for most run types.运行自动捕获指定 output 目录中的文件,大多数运行类型默认为“./outputs”。 Use upload_file only when additional files need to be uploaded or an output directory is not specified.仅当需要上传其他文件或未指定 output 目录时才使用 upload_file。

It looks like there a part of the path missing here:看起来这里缺少路径的一部分:

model_path=os.path.join(archive_name+'.zip') model_path=os.path.join(archive_name+'.zip')

Should the path include the outputs subfolder, like this?路径是否应该包括输出子文件夹,像这样?

model_path=os.path.join("./outputs",archive_name+'.zip') model_path=os.path.join("./outputs",archive_name+'.zip')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM