Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to solve the problem of ValueError: Expected 2D array, got 1D array instead #15

Closed
yyuankm opened this issue Jul 5, 2019 · 3 comments

Comments

@yyuankm
Copy link

yyuankm commented Jul 5, 2019

I refer to the same process to deploy the sagemaker endpoint for my own application. I can predict the results in Jupyter Notebook by using 1d array. Then, I would like invoke it in postman. It complains "ValueError: Expected 2D array, got 1D array instead".

The Content-Type is set as 'text/csv'. The body just contains the data stream.

I never met such trouble for the sagemaker built-in algorithm.

Any comments are welcome!

@ericangelokim
Copy link
Contributor

The data is expected to be any number of prediction rows. This should be solveable by wrapping in an array, or appending '\n' at end if string.

Can you provide the input_fn and the inference call you are making?

@zlufy90
Copy link

zlufy90 commented Apr 21, 2021

Hello, I have the same issue.
This data works: payload = "5.1,3.5,1.4,0.2\n6.3,3.3,6.0,2.5"
But this does not work: payload = "5.1,3.5,1.4,0.2"
This also does not work: payload = "5.1,3.5,1.4,0.2\n"

Could any one please tell me how to solve it?

My full code is

import boto3
endpoint_name= 'sagemaker-scikit-learn-2021-04-21-05-58-59-418'
client = boto3.client('runtime.sagemaker')

# payload = "5.1,3.5,1.4,0.2\n6.3,3.3,6.0,2.5" # this works
payload = "5.1,3.5,1.4,0.2\n" # this does not work

result = client.invoke_endpoint(
    EndpointName=endpoint_name,
    Body=payload,
    ContentType='text/csv')

print(result['Body'].read().decode())

I do not create input_fn function. I think it used the default one

@presich
Copy link

presich commented Sep 24, 2021

The data is expected to be any number of prediction rows. This should be solveable by wrapping in an array, or appending '\n' at end if string.

Hi,
this didn't help. We are having the same error as in the post above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants