我正在尝试运行 Azure ML Batch 端点作业,但由于输入原因,该作业始终以错误结束(见下文)。我使用了在 Azure 设计器中创建和训练的模型,如页面所述:https://learn.microsoft.com/en-us/azure/machine-learning/how-to-deploy-model-designer?view= azureml-api-1
目录“logs/azureml/stderrlogs.txt”中的错误如下:
TypeError: the JSON object must be str, bytes or bytearray, not MiniBatch
我的评分脚本(为模型自动生成):
import os
import json
from typing import List
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()})
输入定义:
input = Input(type=AssetTypes.URI_FILE, path="azureml://subscriptions/$$$$$$$$/resourcegroups/$$$$$$$$$/workspaces/$$$$$/datastores/workspaceblobstore/paths/UI/2023-08-24_193934_UTC/samples.json")
工作定义:
job = ml_client.batch_endpoints.invoke(
endpoint_name=endpoint.name,
input=input,
)
我已经阅读/观看了各种教程/文档并尝试了它们的解决方案,但没有任何帮助,而且我已经被这个错误困扰了几个小时,所以我寻求帮助。