【问题标题】:Receiving parse error from SageMaker Multi Model Endpoint using TensorFlow使用 TensorFlow 从 SageMaker Multi Model Endpoint 接收解析错误
【发布时间】:2022-01-04 12:51:18
【问题描述】:

我们目前正在将我们的模型从单一模型终端节点转移到 AWS SageMaker 中的多模型终端节点。使用预构建的 TensorFlow 容器部署多模型端点后,我在调用 predict() 方法时收到以下错误:

{"error": "JSON Parse error: The document root must not be followed by other value at offset: 17"}

我这样调用端点:

data = np.random.rand(n_samples, n_features)

predictor = Predictor(endpoint_name=endpoint_name)
prediction = predictor.predict(data=serializer.serialize(data), target_model=model_name)

我处理输入的函数如下:

def _process_input(data, context):
    data = data.read().decode('utf-8')
    data = [float(x) for x in data.split(',')]
    return json.dumps({'instances': [data]})

对于培训,我将容器配置如下:

tensorflow_container = TensorFlow(
    entry_point=path_script,
    framework_version='2.4',
    py_version='py37',
    instance_type='ml.m4.2xlarge',
    instance_count=1,
    role=EXECUTION_ROLE,
    sagemaker_session=sagemaker_session,
    hyperparameters=hyperparameters)

tensorflow_container.fit()

为了部署端点,我首先从给定的 Estimator 初始化一个模型,然后是一个 MultiDataModel:

model = estimator.create_model(
            role=EXECUTION_ROLE, 
            image_uri=estimator.training_image_uri(),
            entry_point=path_serving)

mdm = MultiDataModel(
        name=endpoint_name, 
        model_data_prefix=dir_model_data,
        model=model, 
        sagemaker_session=sagemaker.Session())

mdm.deploy(
        initial_instance_count=1, 
        instance_type=instance_type,
        endpoint_name=endpoint_name)


然后使用以下方法添加单个模型:

mdm.add_model(
    model_data_source=source_path,
    model_data_path=model_name)

感谢您的任何提示和帮助。

【问题讨论】:

    标签: python tensorflow amazon-sagemaker


    【解决方案1】:

    如果您的 JSON 数据已损坏或格式不正确,通常会出现此问题。建议您通过 JSON 验证器运行它 https://jsonlint.com/

    我在 AWS 工作,我的意见是我自己的 - 谢谢,Raghu

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 2019-01-31
      • 2020-04-17
      相关资源
      最近更新 更多