Path: blob/master/site/en-snapshot/lite/guide/signatures.ipynb
25118 views
Copyright 2021 The TensorFlow Authors.
Signatures in TensorFlow Lite
TensorFlow Lite supports converting TensorFlow model's input/output specifications to TensorFlow Lite models. The input/output specifications are called "signatures". Signatures can be specified when building a SavedModel or creating concrete functions.
Signatures in TensorFlow Lite provide the following features:
They specify inputs and outputs of the converted TensorFlow Lite model by respecting the TensorFlow model's signatures.
Allow a single TensorFlow Lite model to support multiple entry points.
The signature is composed of three pieces:
Inputs: Map for inputs from input name in the signature to an input tensor.
Outputs: Map for output mapping from output name in signature to an output tensor.
Signature Key: Name that identifies an entry point of the graph.
Setup
Example model
Let's say we have two tasks, e.g., encoding and decoding, as a TensorFlow model:
In the signature wise, the above TensorFlow model can be summarized as follows:
Signature
Key: encode
Inputs: {"x"}
Output: {"encoded_result"}
Signature
Key: decode
Inputs: {"x"}
Output: {"decoded_result"}
Convert a model with Signatures
TensorFlow Lite converter APIs will bring the above signature information into the converted TensorFlow Lite model.
This conversion functionality is available on all the converter APIs starting from TensorFlow version 2.7.0. See example usages.
From Saved Model
From Keras Model
From Concrete Functions
Run Signatures
TensorFlow inference APIs support the signature-based executions:
Accessing the input/output tensors through the names of the inputs and outputs, specified by the signature.
Running each entry point of the graph separately, identified by the signature key.
Support for the SavedModel's initialization procedure.
Java, C++ and Python language bindings are currently available. See example the below sections.
Java
C++
Python
Known limitations
As TFLite interpreter does not gurantee thread safety, the signature runners from the same interpreter won't be executed concurrently.
Support for C/iOS/Swift is not available yet.
Updates
Version 2.7
The multiple signature feature is implemented.
All the converter APIs from version two generate signature-enabled TensorFlow Lite models.
Version 2.5
Signature feature is available through the
from_saved_model
converter API.