AWS SageMaker-请求的图像格式无效

时间:2018-09-10 04:57:43

标签: node.js amazon-web-services express aws-sdk amazon-sagemaker

我正在使用NodeJS + AWS SDK测试Amazon SageMaker服务,并在基于this示例的情况下创建新模型和终结点之后(一切在笔记本中运行良好,包括对终结点的请求),尝试从Express应用程序创建请求,但是出现以下错误:

Error during recognition: { InvalidImageFormatException: Request has Invalid image format
  at Request.extractError (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/protocol/json.js:48:27)
  at Request.callListeners (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/sequential_executor.js:109:20)
  at Request.emit (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/sequential_executor.js:81:10)
  at Request.emit (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/request.js:683:14)
  at Request.transition (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/request.js:22:10)
  at AcceptorStateMachine.runTo (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/state_machine.js:14:12)
  at /Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/state_machine.js:26:10
  at Request.<anonymous> (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/request.js:38:9)
  at Request.<anonymous> (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/request.js:685:12)
  at Request.callListeners (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/sequential_executor.js:119:18)
  at Request.emit (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/sequential_executor.js:81:10)
  at Request.emit (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/request.js:683:14)
  at Request.transition (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/request.js:22:10)
  at AcceptorStateMachine.runTo (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/state_machine.js:14:12)
  at /Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/state_machine.js:26:10
  at Request.<anonymous> (/Users/pdonaire/Documents/workspaceNode/trsps-controller/node_modules/aws-sdk/lib/request.js:38:9)

message: 'Request has Invalid image format',
code: 'InvalidImageFormatException',
time: 2018-09-10T04:42:07.530Z,
requestId: 'de3a04ff-b4b3-11e8-9bd8-8b88f803570c',
statusCode: 400,
retryable: false,
retryDelay: 55.860720412209794 }

我的代码如下:

export function sendRequestToSageMaker(base64image) {
  const params = {
    Body: new Buffer(base64image, 'base64') , /* Strings will be Base-64 encoded on your behalf */ /* required */
    EndpointName: 'DEMO-imageclassification-ep--XXXX', /* required */
    Accept: 'application/json',
    ContentType: 'application/x-image'
  };
  sagemakerruntime.invokeEndpoint(params, function(err, data) {
    if (err) 
      console.error(err, err.stack); // an error occurred
    else     
      console.log(data);           // successful response
   });
   return null;
}

base64imagereq.body.photo,来自我正在处理带有JSON的邮递员的请求,并且只有一个photo属性和我用{{3 }}网站。

任何帮助都会有所帮助!非常感谢! :-)

1 个答案:

答案 0 :(得分:0)

SageMaker图像分类算法仅支持将图像作为有效负载,不支持base64编码的有效负载,这就是为什么您看到InvalidImageFormatException的原因。