predictiongoogle-cloud-mlgoogle-ai-platform

Error: "serving_default not found in signature def" when testing prediction


I followed this tutorial and came to the point where I can test a prediction using the following code:

{
   "instances": [
     {"csv_row": "44, Private, 160323, Some-college, 10, Married-civ-spouse, Machine-op-inspct, Husband, Black, Male, 7688, 0, 40, United-States", "key": "dummy-key"}
   ]
 }

However, I am getting the following error:

{
  "error": "{ \"error\": \"Serving signature name: \\\"serving_default\\\" not found in signature def\" }"
}

I presume the input format doesn't represent the expected input, but am not entirely should what should be expected.

Any ideas as to what is causing the example code to throw this error?


Solution

  • I finally figured it out: I loaded the tensorflow model in jupyter notebook and printed out the signatures:

    new_model = tf.keras.models.load_model('modelPath')
    print(list(new_model.signatures.keys())) 
    

    the result was: [u'predict']

    so the command i used to get a prediction is:

    georg@Georgs-MBP ~ % gcloud ai-platform predict
    --model $MODEL_NAME
    --version "v1"
    --json-instances sample_input.json
    --format "value(predictions[0].classes[0])"
    --signature-name "predict"

    result: Using endpoint [https://europe-west3-ml.googleapis.com/] <=50K