I have been running a simple Linear regression model to predict prices and publishing its endpoint on the azure portal in free subscription trial.
I am facing problem in score.py program where creating the defination of init() and run()
The error that I am getting is 'list' object has no attribute 'predict' when trying to predict new observations on the published endpoint.
Please find the code of Deploy configuration
from azureml.core import Workspace, Experiment
print("Accessing the workspace from job....")
ws=Workspace.from_config()
# Get the input dataset
print("Accessing the Adult Income dataset...")
input_ds = ws.datasets.get('pricing')
# -------------------------------------------------
# Create custom environment
# -------------------------------------------------
from azureml.core import Environment
from azureml.core.environment import CondaDependencies
# Create the environment
myenv = Environment(name="MyEnvironment")
# Create the dependencies object
myenv_dep = CondaDependencies.create(conda_packages=['scikit-learn', 'pip','pandas'],
pip_packages=['azureml-defaults', 'azureml-interpret'])
myenv.python.conda_dependencies = myenv_dep
# Register the environment
print("Registering the environment...")
myenv.register(ws)
# Creat an Azure Kubernets Service provisioning Configuration
from azureml.core.compute import AksCompute, ComputeTarget
cluster_name='aks-cluster-12'
if cluster_name not in ws.compute_targets:
print(cluster_name,"does not exist.Creating a new one")
print('Creating provisiong config for Aks cluster')
aks_config=AksCompute.provisioning_configuration(location='centralindia',
vm_size='Standard_DS11_v2',
agent_count=1,
cluster_purpose='DevTest')
print("Creating the AKS cluster")
production_cluster=ComputeTarget.create(ws,cluster_name,aks_config)
production_cluster.wait_for_completion(show_output=True)
else:
print(cluster_name,"exists. using it..")
production_cluster=ws.compute_targets[cluster_name]
# Creat the inference Configuration
from azureml.core.model import InferenceConfig
inference_config= InferenceConfig(environment=myenv ,entry_script='scoringscriptnew.py',
source_directory=".")
from azureml.core.webservice import AksWebservice
deploy_config=AksWebservice.deploy_configuration(cpu_cores=1,
memory_gb=0.5)
# Deploy
from azureml.core.model import Model
model=ws.models['regression01']
service= Model.deploy(workspace=ws,name='regression',models=[model],
inference_config=inference_config,
deployment_config=deploy_config,
deployment_target=production_cluster)
service.wait_for_deployment(show_output=True)
And code of score.py
import json
import joblib
from azureml.core.model import Model
import pandas as pd
# Called when the service is loaded
def init():
global predictor
# Get the path to the registered model file and load it
model_path = Model.get_model_path('regression01')
predictor = joblib.load(model_path)
# Called when a request is received
def run(raw_data):
# Get the input data as a dictionary
data_dict = json.loads(raw_data)['data']
# Convert dictionary to pandas dataframe
data = pd.DataFrame.from_dict(data_dict)
# Transform the data
# data = one_hot.transform(data)
# difference of train and deploy
# Get a prediction from the model
predictions = predictor.predict(data)
# Return the predictions
return predictions
Can someone help me understand if the init() function is not performing and if not what could be the reason?