SSD tensorflow config_error ai_generated partial

ValueError: Could not find signature def corresponding to requested signature key 'serving_default'

ID: tensorflow/savedmodel-signature-def-not-found

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
1Evidence
2023-07-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
tensorflow 2.11 active
tensorflow 2.12 active
tensorflow 2.13 active
tensorflow 2.14 active

Root Cause

SavedModel was exported without a default serving signature or with a different signature name, causing model loading to fail when expecting 'serving_default'.

generic

中文

SavedModel 导出时没有默认服务签名或使用了不同的签名名称,导致加载模型时因期望 'serving_default' 而失败。

Official Documentation

https://www.tensorflow.org/guide/saved_model#specifying_signatures_during_export

Workarounds

  1. 90% success List available signatures in the SavedModel: import tensorflow as tf; loaded = tf.saved_model.load('model_dir'); print(list(loaded.signatures.keys())). Then use the correct key: model = tf.saved_model.load('model_dir', tags='serve', signature='your_correct_key')
    List available signatures in the SavedModel: import tensorflow as tf; loaded = tf.saved_model.load('model_dir'); print(list(loaded.signatures.keys())). Then use the correct key: model = tf.saved_model.load('model_dir', tags='serve', signature='your_correct_key')
  2. 85% success Re-export the model with an explicit serving signature: @tf.function(input_signature=[tf.TensorSpec(shape=[None, 224, 224, 3], dtype=tf.float32)]); def serving_fn(input): return self.call(input); tf.saved_model.save(model, 'model_dir', signatures={'serving_default': serving_fn})
    Re-export the model with an explicit serving signature: @tf.function(input_signature=[tf.TensorSpec(shape=[None, 224, 224, 3], dtype=tf.float32)]); def serving_fn(input): return self.call(input); tf.saved_model.save(model, 'model_dir', signatures={'serving_default': serving_fn})

中文步骤

  1. List available signatures in the SavedModel: import tensorflow as tf; loaded = tf.saved_model.load('model_dir'); print(list(loaded.signatures.keys())). Then use the correct key: model = tf.saved_model.load('model_dir', tags='serve', signature='your_correct_key')
  2. Re-export the model with an explicit serving signature: @tf.function(input_signature=[tf.TensorSpec(shape=[None, 224, 224, 3], dtype=tf.float32)]); def serving_fn(input): return self.call(input); tf.saved_model.save(model, 'model_dir', signatures={'serving_default': serving_fn})

Dead Ends

Common approaches that don't work:

  1. Re-exporting the model with tf.saved_model.save without specifying signatures 60% fail

    If the model's call method is not defined, default signature may still be missing; need to explicitly provide signatures.

  2. Renaming the signature key in the loader to match a non-existent key 90% fail

    The key must match an actual signature in the SavedModel; guessing keys rarely works.