Grafgurke
Grafgurke

Reputation: 37

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?

Upvotes: 0

Views: 1272

Answers (2)

x4444
x4444

Reputation: 2182

To add signature serving_default:

import tensorflow as tf
m = tf.saved_model.load("tf2-preview_inception_v3_classification_4")
print(m.signatures) # _SignatureMap({}) - Empty
t_spec = tf.TensorSpec([None,None,None,3], tf.float32)
c_func = m.__call__.get_concrete_function(inputs=t_spec)
signatures = {'serving_default': c_func}
tf.saved_model.save(m, 'tf2-preview_inception_v3_classification_5', signatures=signatures)

# Test new model
m5 = tf.saved_model.load("tf2-preview_inception_v3_classification_5")
print(m5.signatures) # _SignatureMap({'serving_default': <ConcreteFunction signature_wrapper(*, inputs) at 0x17316DC50>})

Upvotes: 0

Grafgurke
Grafgurke

Reputation: 37

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

Upvotes: 1

Related Questions