2

I am requesting online prediction for a trained model (model created with linear learner algorithm) and getting "error": "Prediction failed: unknown error."

This is my first ML model in Google AI platform. Model training was successful, training data, validation data and test data all look good in the output folder. But when I try to test the model by passing the input JSON I get this error. I have looked for similar other posts but couldn't find the solution to get a successful prediction.

metadata.json in the artifact folder looks like

{
    "feature_columns": {
    "col_0": {
      "mapping": {
        "0": 0, 
        "1": 1, 
        "10": 10, 
        "2": 2, 
        "3": 3, 
        "4": 4, 
        "5": 5, 
        "6": 6, 
        "7": 7, 
        "8": 8, 
        "9": 9
      }, 
      "mode": "0", 
      "num_category": 11, 
      "treatment": "identity", 
      "type": "categorical"
    }, 
    "col_1": {
      "mapping": {
        "0": 0, 
        "1": 1, 
        "10": 10, 
        "2": 2, 
        "3": 3, 
        "4": 4, 
        "5": 5, 
        "6": 6, 
        "7": 7, 
        "8": 8, 
        "9": 9
      }, 
      "mode": "4", 
      "num_category": 11, 
      "treatment": "identity", 
      "type": "categorical"
    }
  }, 
  "target_algorithm": "TensorFlow", 
  "target_column": {
    "type": "regression"
  }
}

The input JSON that I am passing for testing prediction is { "instances": [5,5] }

The model is expected to sum the 2 input features and give a result of 10

Can you please advise where the mistake is?

Kishor
  • 21
  • 2

2 Answers2

2

If you are using gcloud to send a file, do:

 {"col_0": "5", "col_1": "5" }

If you are sending a bunch of instances through some other client, do:

{ 
  "instances": [
    {"col_0": "5", "col_1": "5" },
    {"col_0": "3", "col_1": "2" }
  ]
} 
Lak
  • 3,876
  • 20
  • 34
  • Hello Lak, thanks for your answer. when I tried with the above, I got this error message { "error": "Prediction failed: Unexpected tensor name: col_0" } – Kishor Sep 13 '19 at 11:06
  • Hello @Lak, I am using the "Test & Use" interface provided in the google AI platform. When I open the version of the Model this "Test & Use" tab appears for online prediction. – Kishor Sep 13 '19 at 11:17
  • It looks like your model isn't expect a `col_0` in its input. What are the inputs to your model when running locally?https://stackoverflow.com/questions/51930002/ml-engine-online-prediction-unexpected-tensor-name-values – nnegrey Sep 13 '19 at 18:21
0

Lak's answer is good and does the job.
Although my input data was different I got the same error, despite successful local predictions. Here are two additional things that helped me.

Run !gcloud ai-platform predict --help to learn more about how your input should be formatted and which flag to use when making the call.

Inspect the model with !saved_model_cli show --dir ${YOUR_LOCAL_MODEL_PATH} --all to check the names of the inputs. Verify that they are in fact (in your case) inputs[col_0] and inputs[col_1].

Using the "TEST & USE" interface you mentioned above (and in this SO answer) allows quicker experimentation.

Jakob
  • 663
  • 7
  • 25