@yjay Thanks, Here is the example, for the Multiclass Classification - Letter Recognition sample, the inference results are as follows:
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to consume a model that I deployed from Azure Machine Learning as a web service but I keep getting an error: 'str' object has no attribute 'items' Help: https://go.microsoft.com/fwlink/?linkid=2146748
.
I am following the Consume an Azure Machine Learning model deployed as a web service tutorial for calling the service using python.
I followed the formatting as shown in the documentation but I still keep getting this error.
import requests
import json
# URL for the web service
scoring_uri = 'http://00.00.00.00:00/api/v1/service/test/score'
# If the service is authenticated, set the key or token
# Two sets of data to score, so we get two results back
data = {"data":
[
{'volume': 0.23,
'temp': 0.66, }
]
}
# Convert to JSON string
input_data = json.dumps(data)
print(input_data)
# Set the content type
headers = {'Content-Type': 'application/json'}
# Make the request and display the response
resp = requests.post(scoring_uri, input_data, headers=headers)
print(resp.text)
Any ideas would be great, thanks!
UPDATE:
Scoring script:
import os
import json
from azureml.studio.core.io.model_directory import ModelDirectory
from pathlib import Path
from azureml.studio.modules.ml.score.score_generic_module.score_generic_module import ScoreModelModule
from azureml.designer.serving.dagengine.converter import create_dfd_from_dict
from collections import defaultdict
from azureml.designer.serving.dagengine.utils import decode_nan
from azureml.studio.common.datatable.data_table import DataTable
model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'trained_model_outputs')
schema_file_path = Path(model_path) / '_schema.json'
with open(schema_file_path) as fp:
schema_data = json.load(fp)
def init():
global model
model = ModelDirectory.load(model_path).model
def run(data):
data = json.loads(data)
input_entry = defaultdict(list)
for row in data:
for key, val in row.items():
input_entry[key].append(decode_nan(val))
data_frame_directory = create_dfd_from_dict(input_entry, schema_data)
score_module = ScoreModelModule()
result, = score_module.run(
learner=model,
test_data=DataTable.from_dfd(data_frame_directory),
append_or_result_only=True)
return json.dumps({"result": result.data_frame.values.tolist()})