Azure Batch 端点作业以 TypeError 结束:JSON 对象必须是 str、bytes 或 bytearray,而不是 MiniBatch

问题描述 投票:0回答:1

我正在尝试运行 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,
)

我已经阅读/观看了各种教程/文档并尝试了它们的解决方案,但没有任何帮助,而且我已经被这个错误困扰了几个小时,所以我寻求帮助。

azure machine-learning endpoint azure-batch scoring
1个回答
0
投票

根据您提供的错误消息,CSV 格式的输入数据中似乎未提供所需的功能。

要解决此问题,请确保您的输入 CSV 文件具有与模型预期功能匹配的正确列标题。您可以参考Azure设计器中使用的训练数据来确保列标题一致。

有关更多详细信息,请参阅有关批量端点的教程

要获取有关支持的数据输入格式的更多详细信息,您可以查看此文档

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.