Define a dummy entry script
Sat Apr 09 2022 15:12:23 GMT+0000 (Coordinated Universal Time)
Saved by
@wessim
%%writefile $script_file
import json
import joblib
import numpy as np
from azureml.core.model import Model
# Called when the service is loaded
def init():
global model
# Get the path to the deployed model file and load it
model_path = Model.get_model_path('diabetes_model')
model = joblib.load(model_path)
# Called when a request is received
def run(raw_data):
# Get the input data as a numpy array
data = json.loads(raw_data)['data']
np_data = np.array(data)
# Get a prediction from the model
predictions = model.predict(np_data)
# print the data and predictions (so they'll be logged!)
log_text = 'Data:' + str(data) + ' - Predictions:' + str(predictions)
print(log_text)
# Get the corresponding classname for each prediction (0 or 1)
classnames = ['not-diabetic', 'diabetic']
predicted_classes = []
for prediction in predictions:
predicted_classes.append(classnames[prediction])
# Return the predictions as JSON
return json.dumps(predicted_classes)
content_copyCOPY
The entry script receives data submitted to a deployed web service and passes it to the model. It then returns the model's response to the client. The script is specific to your model. The entry script must understand the data that the model expects and returns.
The two things you need to accomplish in your entry script are:
Loading your model (using a function called init())
Running your model on input data (using a function called run())
For your initial deployment, use a dummy entry script that prints the data it receives.
https://docs.microsoft.com/en-us/azure/machine-learning/how-to-deploy-and-where?tabs=python
Comments