SignatureDef的作用

SignatureDef主要用于定义TensorFlow模型的输入输出接口,它包含input、output和method_name三部分。接口协议在构建时被封装到二进制文件,方便客户端进行参数校验。SignatureDef的使用促进了模型保存和加载的便捷性,实现了训练和预测的解耦。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SignatureDef的作用

本篇文章主要讲解SignatureDef接口的作用

概述

SignatureDef的主要作用是定义输出和输入接口协议。他在构建SaveModel时,被封装到二进制文件中。

SignatureDef结构

SignatureDef包含三个部分:

  • input:封装着TensorInfo信息的字典
  • outputs :和上面一样,封装着TensorInfo信息的字典
  • method_name:在加载的工具和系统中,对应着方法名。(我的理解是可能存在多个前面,用method_name指定一个唯一的key)

    注意:构建SignatureDef对象的时候,需要指定tensor的名字,数据类型以及它的形状。其实这些数据已经存放在graph中了,显示的指定这些信息是非常有用的,有了它,客户端就可以不需要去读取整个graph,就可以进行一些参数校验的工作了

相关的常量和工具

为了代码可以更好的复用,一般情况下都会使用和SignatureDef相关的常量。这些常量都会被tensorflow中跨语言和跨平台的支持,特别是在c++、Python环境中
另外,SaveModel也提供了一些工具,用于构建SignatureDef对象。

示例

Save:

(tensorflow) root@DESKTOP-RVNE65O:~/work/model_zoo# python extracttflite.py 2025-03-07 14:57:53.720064: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-03-07 14:57:53.772008: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used. 2025-03-07 14:57:53.999328: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered 2025-03-07 14:57:53.999476: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered 2025-03-07 14:57:54.001268: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered 2025-03-07 14:57:54.137256: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used. 2025-03-07 14:57:54.138160: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. 2025-03-07 14:57:55.181380: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT INFO: Created TensorFlow Lite XNNPACK delegate for CPU. Traceback (most recent call last): File "/root/work/model_zoo/extracttflite.py", line 52, in <module> extractSubgraphToTflite(interpreter, subgraph1Inputs, subgraph1Outputs, './model/tflite/MicroISP_1.tflite') File "/root/work/model_zoo/extracttflite.py", line 39, in extractSubgraphToTflite converter = tf.lite.TFLiteConverter.from_concrete_functions([interpreter.get_signature_runner()]) File "/opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/tensorflow/lite/python/interpreter.py", line 853, in get_signature_runner raise ValueError( ValueError: SignatureDef signature_key is None and model has 0 Signatures. None is only allowed when the model has 1 SignatureDef
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值