none
requests.post(scoring_uri, data=input_data, headers=headers) failed when call model service RRS feed

  • Question

  • hi,
    I use Microsoft AML to do some test, when one train task done, i deploy one model and get one score url. Then I refer to following link: https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-deploy-and-where#script, use Python code to do predict with this restful API call:
    requests.post(scoring_uri, data=input_data, headers=headers)

    My question is about the format of "input_data" variable:
    Here is one example:
    '{"data": [[1360.0, 150.0, 11.9, 1046.0, 166.0, 1056.0, 113.0, 1692.0, 1268.0, 13.6, 48.9, 0.7578]]}'
    this kind of data format works well before, but recently, it doesn't work, the error msg is:
    'Invalid input array: an array with 1 dimensions is expected; input has 2 [shape (1, 12)]'

    If I changed the data to :
    '{"data": [1360.0, 150.0, 11.9, 1046.0, 166.0, 1056.0, 113.0, 1692.0, 1268.0, 13.6, 48.9, 0.7578]}', the call failed too, error message is:

    '"{\\"error\\": \\"TransformException:\\\\n\\\\tMessage: Expected 2D array, got 1D array instead:\\\\narray=[1.360e+03 1.500e+02 1.190e+01 1.046e+03 1.660e+02 1.056e+03 1.130e+02\\\\n 1.692e+03 1.268e+03 1.360e+01 4.890e+01 7.578e-01].\\\\nReshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.\\\\n\\\\tInnerException Expected 2D array, got 1D array instead:

    How can I fix this issue?







    Sunday, September 29, 2019 5:30 AM

All replies

  • Hello,

    Could you please print your service's swagger property and check what input type it accepts? I think this will help to identify the web services input/output schema.

    print(service.swagger_uri)

    -Rohit

    Monday, September 30, 2019 5:27 AM
    Moderator
  • hi Rohit,

    Thanks.

    I use restful API to call the service, here is one example and error message:

    And another example is:

    Monday, October 7, 2019 1:55 AM