How to use a registred model in a python script(in Azure) ?

vishal_c_v 11 Reputation points
2021-07-11T14:16:22.337+00:00

I used Azure AutoML service to test various models and after choosing the best one I registered it in my workspace.

Process done for registering:

  1. I downloaded the model(a zipped folder containing 3 files) into my laptop
  2. Unzipped the folder in my laptop
  3. Uploaded the unzipped folder(containing the score, environment yml and pkl file ) in the Azure "Models" pane and registered a model under the name "lgbm"

What I want to achieve:
I want to use the registered model to make some predictions on a "validation" Dataset I have in Azure(already registered) and check out the accuracy metrics once again.

Steps done:

  1. Registered the validation dataset in Azure properly
  2. Started the Azure VM and Opened a new notebook
  3. Got the validation data into the script

Where I got stuck :
Unable to get the registered model into my script and make predictions:

Code:

import azureml.core
from azureml.core import Workspace

Load the workspace from the saved config file

ws = Workspace.from_config()
print('Ready to use Azure ML {} to work with {}'.format(azureml.core.VERSION, ws.name))

from azureml.core import Dataset
import glob
tab_data_set = Dataset.Tabular.from_delimited_files(path=(default_ds, 'UI/07-11-2021_055454_UTC/test_pred.csv'))
tab_data_set = tab_data_set.to_pandas_dataframe()

model_path = Model.get_model_path('lgbm')
model = joblib.load(model_path)

Error
ModelNotFoundException: ModelNotFoundException:
Message: Model lgbm not found in cache at azureml-models or in current working directory /mnt/batch/tasks/shared/LS_root/mounts/clusters/azuremlvm201/code/Users/vishal_c_v. For more info, set logging level to DEBUG.
InnerException None
ErrorResponse
{
"error": {
"message": "Model lgbm not found in cache at azureml-models or in current working directory /mnt/batch/tasks/shared/LS_root/mounts/clusters/azuremlvm201/code/Users/vishal_c_v. For more info, set logging level to DEBUG."
}
}

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,552 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ramr-msft 17,606 Reputation points
    2021-07-12T13:49:23.027+00:00

    @vishal_c_v Thanks for the question. Can you check the get_details() and see the model name. You don't register a model by creating a Model object. To register a model from a an AutoML run, you can:

    model = run.register_model(description = description, iteration = iteration_id)

    If you don't provide the iteration id (aka child run), then the model with the best metric will be registered.

    1 person found this answer helpful.

  2. Ramr-msft 17,606 Reputation points
    2021-07-27T01:33:36.047+00:00

    @vishal_c_v Thanks for the details, AutoML does not automatically register models at this time. You can register manually via SDK or UI via the "Deploy" button (which registers and deploys the model).