SageMaker 批量转换因 ID 列失败

SageMaker Batch Transform fails with ID Column

我正在使用 SageMaker 管道对测试数据进行推理。管道使用 SKLearn 每处理器和 XGBoost 模型。管道在没有 ID 列的数据上运行良好。但是,当我尝试包含一个 ID 列来跟踪预测时,它失败了。我在下面给出了代码片段。

import sagemaker
from sagemaker.predictor import json_serializer, csv_serializer, json_deserializer

input_data_path = 's3://batch-transform/input-data/validation_data.csv'
output_data_path = 's3://batch-transform/predictions/'

transform_job = sagemaker.transformer.Transformer(
    model_name = model_name,
    instance_count = 1,
    instance_type = 'ml.m4.xlarge',
    strategy = 'MultiRecord',
    assemble_with = 'Line',
    output_path = output_data_path,
    base_transform_job_name='pipeline_with_id',
    sagemaker_session=sagemaker.Session(),
    accept = 'text/csv')

transform_job.transform(data = input_data_path,
                        content_type = 'text/csv', 
                        split_type = 'Line',
                        input_filter='$[1:]', 
                        join_source='Input')
                        output_filter='$[0,-1]')

这会导致以下错误:

Fail to join data: mismatched line count between the input and the output

我正在按照本页中给出的示例进行操作:

https://aws.amazon.com/blogs/machine-learning/associating-prediction-results-with-input-data-using-amazon-sagemaker-batch-transform/

有人可以指出导致错误的原因吗?谢谢

遇到了同样的问题。

检查服务代码中预测后返回的行数。就我而言,我的预测输出没有 header.

例如作为 text/csv 响应,使用带连接的批量转换将 post 连接输入和输出。

单个输入记录将是 [["feature_1", "feature_2"],[0, 1]],而我的模型预测输出返回 [1].

像这样 ["result", 1] 将列名称添加到预测输出,然后返回 csv 结果将产生 [["result"],[1]] 匹配输入。

P.S。您可能需要为 multi-row 批处理找到一种可扩展的方法。不确定。