SSD tensorflow config_error ai_generated partial

值错误:找不到与请求的签名键 'serving_default' 对应的签名定义

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

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

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
1证据数
2023-07-18首次发现

版本兼容性

版本状态引入弃用备注
tensorflow 2.11 active
tensorflow 2.12 active
tensorflow 2.13 active
tensorflow 2.14 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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})

无效尝试

常见但无效的做法:

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

    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% 失败

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