标签的默认值为“serve”,signature_keys 的默认值为“serving_default”。您可以使用 python API 中的标签参数覆盖它
看https://www.tensorflow.org/lite/api_docs/python/tf/lite/TFLiteConverter#from_saved_model https://www.tensorflow.org/lite/api_docs/python/tf/lite/TFLiteConverter#from_saved_model
编辑:
在传递正确的标签和签名密钥后添加有关失败的详细信息。
EDIT2:更新了示例代码
这看起来像一个旧模型。它是使用旧版本保存的。
首先,让我们解决这个保存的模型版本问题。
你需要重新保存
MODEL_DIR = 'model_path'
SIGNATURE_KEYS = ['default']
SIGNATURE_TAGS = set()
saved_model = tf.saved_model.load(MODEL_DIR, tags=SIGNATURE_TAGS)
tf.saved_model.save(saved_model, 'new_model_path', signatures=saved_model.signatures)
# You can now convert like this.
converter = tf.lite.TFLiteConverter.from_saved_model(
'new_model_path', signature_keys=SIGNATURE_KEYS, tags=['serve'])
现在,如果您尝试转换,您将不会看到此问题,但您会看到新问题:)
从错误信息日志总结有2点
Some ops are not supported by the native TFLite runtime, you can enable TF kernels fallback using TF Select. See instructions: https://www.tensorflow.org/lite/guide/ops_select
Flex ops: TensorArrayGatherV3, TensorArrayReadV3, TensorArrayScatterV3, TensorArraySizeV3, TensorArrayV3, TensorArrayWriteV3
and
Some ops in the model are custom ops, See instructions to implement custom ops: https://www.tensorflow.org/lite/guide/ops_custom
Custom ops: HashTableV2, LookupTableFindV2, LookupTableImportV2
新问题是因为该模型正在使用 TFLite 目前不支持的操作。
例如,TensorArray、哈希表。
其中一些操作可以使用 TF 选择模式来支持,请参阅here https://www.tensorflow.org/lite/guide/ops_select其他操作“HashTableV2、LookupTableFindV2、LookupTableImportV2”在 TFLite 中可作为自定义操作使用。
看到这个answer https://github.com/tensorflow/tensorflow/issues/37844#issuecomment-605336360关于如何启用它。
此外,TFLite 团队正在努力添加对哈希表作为内置操作的支持,因此很快您将不需要执行额外的步骤。