Amazon sagemaker 无法使用sagemaker调用端点
我正在使用aws sagemaker调用端点:Amazon sagemaker 无法使用sagemaker调用端点,amazon-sagemaker,Amazon Sagemaker,我正在使用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(EndpointNam
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
ParamValidationError回溯(最近一次调用上次)
在()
1 response=runtime.invoke_端点(EndpointName=r_端点,
2 ContentType='text/csv',
---->3车身=有效载荷)
4.
5 result=json.load(响应['Body'].read().decode())
~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in\u api\u调用(self,*args,**kwargs)
312“%s()只接受关键字参数。“%py\u操作\u名称)
313#此范围中的“自我”指的是BaseClient。
-->314返回self.\u make\u api\u调用(操作名称,kwargs)
315
316\u api\u调用。\u名称\u=str(py\u操作\u名称)
~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in\u make\u api\u调用(self、operation\u name、api\u参数)
584 }
585请求\u dict=self.\u将\u转换为\u请求\u dict(
-->586 api参数,操作模型,上下文=请求上下文)
587
588处理程序,事件\u响应=self.meta.events.emit\u直到\u响应(
~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in\u convert\u to\u request\u dict(self、api参数、操作模型、上下文)
619 api参数、操作模型、上下文)
620 request\u dict=self.\u serializer.serialize\u to\u request(
-->621 api_参数,操作模式)
622准备请求记录(请求记录,端点url=self.\u endpoint.host,
623 user\u agent=self.\u client\u config.user\u agent,
序列化到请求(self、参数、操作模型)中的~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/validate.py
289操作(U型。输入(U型)
290如果报告有错误():
-->291 raise ParamValidationError(report=report.generate_report())
292返回self.\u序列化程序。将\u序列化为\u请求(参数,
293操作(U型)
ParamValidationError:参数验证失败:
参数正文的类型无效,值: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,类型:,有效类型:,类文件对象
我只是在使用与aws教程中相同的代码/步骤
你能帮我解决这个问题吗
谢谢有效负载变量是熊猫的数据帧,而预期的是
Body=b'bytes'|文件
尝试以下方法(盲编码):
更多关于。
确保文件不包含头
或者,将数据帧转换为字节,并传递这些字节,而不是传递数据帧
response = runtime.invoke_endpoint(EndpointName=r_endpoint,
ContentType='text/csv',
Body=open('payload.csv'))