Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register model from the Azure ML Pipeline Script step

I am running the pipeline.submit() in AzureML, which has a 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. But as inside the script I do not have a workspace, Model.register() is not the case. So I am trying to use Run.register_model() method as below:

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:

despite I have the retrained .zip in the ./outputs dir as we can see from the log:

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

I guess that I am doing something wrong?

like image 702
siarblack Avatar asked Nov 19 '19 11:11

siarblack


People also ask

What is PythonScriptStep?

A PythonScriptStep is a basic, built-in step to run a Python Script on a compute target. It takes a script name and other optional parameters like arguments for the script, compute target, inputs and outputs. If no compute target is specified, the default compute target for the workspace is used.

Can Azure ML Studio apply ML model?

Create an Azure Machine Learning workspace and cloud resources that can be used to train machine learning models.


1 Answers

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:

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:

Runs automatically capture file in the specified output directory, which defaults to "./outputs" for most run types. Use upload_file only when additional files need to be uploaded or an output directory is not specified.

like image 118
tuomastik Avatar answered Oct 06 '22 09:10

tuomastik