Невозможно вызвать конечную точку с Sagemaker - PullRequest
0 голосов
/ 09 сентября 2018

Я использую aws sagemaker для вызова конечной точки:

payload = pd.read_csv('payload.csv', header=None)

>> payload


    0   1   2   3   4
0   setosa  5.1     3.5     1.4     0.2
1   setosa  5.1     3.5     1.4     0.2

с этим кодом:

response = runtime.invoke_endpoint(EndpointName=r_endpoint,
                                   ContentType='text/csv',
                                   Body=payload)

Но у меня возникла эта проблема:

ParamValidationError                      Traceback (most recent call last)
<ipython-input-304-f79f5cf7e0e0> in <module>()
      1 response = runtime.invoke_endpoint(EndpointName=r_endpoint,
      2                                    ContentType='text/csv',
----> 3                                    Body=payload)
      4 
      5 result = json.loads(response['Body'].read().decode())

~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
    312                     "%s() only accepts keyword arguments." % py_operation_name)
    313             # The "self" in this scope is referring to the BaseClient.
--> 314             return self._make_api_call(operation_name, kwargs)
    315 
    316         _api_call.__name__ = str(py_operation_name)

~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
    584         }
    585         request_dict = self._convert_to_request_dict(
--> 586             api_params, operation_model, context=request_context)
    587 
    588         handler, event_response = self.meta.events.emit_until_response(

~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _convert_to_request_dict(self, api_params, operation_model, context)
    619             api_params, operation_model, context)
    620         request_dict = self._serializer.serialize_to_request(
--> 621             api_params, operation_model)
    622         prepare_request_dict(request_dict, endpoint_url=self._endpoint.host,
    623                              user_agent=self._client_config.user_agent,

~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/validate.py in serialize_to_request(self, parameters, operation_model)
    289                                                     operation_model.input_shape)
    290             if report.has_errors():
--> 291                 raise ParamValidationError(report=report.generate_report())
    292         return self._serializer.serialize_to_request(parameters,
    293                                                      operation_model)

ParamValidationError: Parameter validation failed:
Invalid type for parameter Body, value:         0    1    2    3    4
0  setosa  5.1  3.5  1.4  0.2
1  setosa  5.1  3.5  1.4  0.2, type: <class 'pandas.core.frame.DataFrame'>, valid types: <class 'bytes'>, <class 'bytearray'>, file-like object

Я просто использую тот же код / ​​шаг, что и в учебнике по aws.

Можете ли вы помочь мне решить эту проблему, пожалуйста?

спасибо

1 Ответ

0 голосов
/ 11 сентября 2018

Переменная полезной нагрузки представляет собой DataFrame Pandas, тогда как invoke_endpoint () ожидает Body=b'bytes'|file.

Попробуйте что-то вроде этого (кодирование вслепую):

response = runtime.invoke_endpoint(EndpointName=r_endpoint,
                                   ContentType='text/csv',
                                   Body=open('payload.csv'))

Подробнее о ожидаемых форматах здесь . Убедитесь, что файл не содержит заголовка.

Кроме того, можно преобразовать ваш DataFrame в байты, , как в этом примере , и передавать эти байты вместо передачи DataFrame.

...