AWS DeepAR 预测回报 400

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

我正在尝试运行 DeepAR,根据当前和前几个月对接下来的 15 条记录进行一些估计。

我按照示例进行操作,我相信一切都很好。我仍然有一个非常神秘的错误。

我把代码放在这里:

predictor = estimator.deploy(
    initial_instance_count=1,
    instance_type='ml.m5.large',   
    serializer=JSONSerializer(),
    deserializer=JSONDeserializer()
    )

json_request = json.dumps({
    "instances": ts,
    "configuration": {
        "num_samples": 10,
        "output_types": ["quantiles", "samples"],
        "quantiles": ['0.2', '0.5', '0.8']
    }
})

prediction = predictor.predict(json_request)

我的 json 看起来像这样:

{"instances": 
    [{"start": "2024-03-01", 
      "target":[60,10,86,62,21,25,7,79,33,82,34,43,14,99,5,37,85,84,88,25,2,14,15,98,14,75,70,99,12]
      }, 
     {"start": "2024-04-01", 
      "target": [55,89,40,81,87,7,49,77,37,42,48,27,89,45,85]
      }], 
 "configuration": {"num_samples": 15, "output_types": ["quantiles", "samples"], "quantiles": ["0.2", "0.5", "0.8"]}}

但是我有以下错误:

---------------------------------------------------------------------------
ModelError                                Traceback (most recent call last)
Cell In[22], line 2
      1 print(type('json_request'))
----> 2 prediction = predictor.predict(json_request)
      3 print(prediction)

File c:\Users\civan\PycharmProjects\JupyterBooks\.venv\Lib\site-packages\sagemaker\base_predictor.py:212, in Predictor.predict(self, data, initial_args, target_model, target_variant, inference_id, custom_attributes, component_name)
    209 if inference_component_name:
    210     request_args["InferenceComponentName"] = inference_component_name
--> 212 response = self.sagemaker_session.sagemaker_runtime_client.invoke_endpoint(**request_args)
    213 return self._handle_response(response)

File c:\Users\civan\PycharmProjects\JupyterBooks\.venv\Lib\site-packages\botocore\client.py:553, in ClientCreator._create_api_method.<locals>._api_call(self, *args, **kwargs)
    549     raise TypeError(
    550         f"{py_operation_name}() only accepts keyword arguments."
    551     )
    552 # The "self" in this scope is referring to the BaseClient.
--> 553 return self._make_api_call(operation_name, kwargs)

File c:\Users\civan\PycharmProjects\JupyterBooks\.venv\Lib\site-packages\botocore\client.py:1009, in BaseClient._make_api_call(self, operation_name, api_params)
   1005     error_code = error_info.get("QueryErrorCode") or error_info.get(
   1006         "Code"
   1007     )
   1008     error_class = self.exceptions.from_code(error_code)
-> 1009     raise error_class(parsed_response, operation_name)
   1010 else:
   1011     return parsed_response

ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (400) from primary with message "Unable to evaluate payload provided".

我尝试过不使用序列化器/desearilzer,它也会给出错误,但不是这个,与格式相关的事情。

python amazon-web-services time-series amazon-sagemaker deepar
1个回答
0
投票

不需要对 estimator.deploy() 使用以下序列化器 = JSONSerializer() 并导致错误,因为您的输入已经序列化为 JSON 字符串。

或者如果你想使用JSONSerializer,你需要在序列化之前传递参数。

© www.soinside.com 2019 - 2024. All rights reserved.