Loads metadata from TFLite Model FlatBuffer.
TFLite Model FlatBuffer can be generated using the TFLite Model schema file.
Some models contain a TFLite Metadata Flatbuffer, which records more information about what the model does and how to interprete the model. TFLite Metadata Flatbuffer can be generated using the TFLite Metadata schema file.
It is allowed to pass in a model FlatBuffer without TFLite metadata. However, invoking methods that read from TFLite metadata will cause runtime errors.
Similarly, it is allowed to pass in a model FlatBuffer without associated files. However, invoking methods that read the associated files will cause runtime errors.
Though TFLite model FlatBuffer supports multiple subgraphs, TFLite Interpreter only supports a
single subgraph so far. See the instruction
of how to specify subgraph during convertion for more information. Therefore, MetadataExtractor
omits subgraph index as an input in its methods.
class | MetadataExtractor.QuantizationParams | Quantization parameters that corresponds to the table, QuantizationParameters , in the
TFLite
Model schema file. |
InputStream | |
Set<String> |
getAssociatedFileNames()
Gets the file names of the associated files.
|
int |
getInputTensorCount()
Gets the count of input tensors in the model.
|
TensorMetadata |
getInputTensorMetadata(int inputIndex)
Gets the metadata for the input tensor specified by
inputIndex . |
MetadataExtractor.QuantizationParams |
getInputTensorQuantizationParams(int inputIndex)
Gets the quantization parameters for the input tensor specified by
inputIndex . |
int[] |
getInputTensorShape(int inputIndex)
Gets the shape of the input tensor with
inputIndex . |
byte |
getInputTensorType(int inputIndex)
Gets the
ERROR(/TensorType) of the input tensor with inputIndex . |
ModelMetadata |
getModelMetadata()
Gets the root handler for the model metadata.
|
int |
getOutputTensorCount()
Gets the count of output tensors in the model.
|
TensorMetadata |
getOutputTensorMetadata(int outputIndex)
Gets the metadata for the output tensor specified by
outputIndex . |
MetadataExtractor.QuantizationParams |
getOutputTensorQuantizationParams(int outputIndex)
Gets the quantization parameters for the output tensor specified by
outputIndex . |
int[] |
getOutputTensorShape(int outputIndex)
Gets the shape of the output tensor with
outputIndex . |
byte |
getOutputTensorType(int outputIndex)
Gets the
ERROR(/TensorType) of the output tensor with outputIndex . |
boolean |
hasMetadata()
Returns
true if the model has metadata. |
final boolean |
isMinimumParserVersionSatisfied()
Returns
true if the minimum parser version required by the given metadata flatbuffer
precedes or equals to the version of the metadata parser that this MetadataExtractor library is
relying on. |
Creates a MetadataExtractor
with TFLite model FlatBuffer.
buffer | the TFLite model FlatBuffer |
---|
IllegalArgumentException | if the number of input or output tensors in the model does not match that in the metadata |
---|---|
IOException | if an error occurs while reading the model as a Zip file |
Gets the packed associated file with the specified fileName
.
fileName | the name of the associated file |
---|
IllegalStateException | if the model is not a zip file |
---|---|
IllegalArgumentException | if the specified file does not exist in the model |
Gets the file names of the associated files.
IllegalStateException | if the model is not a zip file |
---|
Gets the count of input tensors in the model.
Gets the metadata for the input tensor specified by inputIndex
.
inputIndex | the index of the desired input tensor |
---|
IllegalStateException | if this model does not contain model metadata |
---|
Gets the quantization parameters for the input tensor specified by inputIndex
.
inputIndex | the index of the desired input tensor |
---|
Gets the shape of the input tensor with inputIndex
.
inputIndex | the index of the desired input tensor |
---|
Gets the ERROR(/TensorType)
of the input tensor with inputIndex
.
inputIndex | the index of the desired input tensor |
---|
Gets the root handler for the model metadata.
IllegalStateException | if this model does not contain model metadata |
---|
Gets the count of output tensors in the model.
Gets the metadata for the output tensor specified by outputIndex
.
outputIndex | the index of the desired output tensor |
---|
IllegalStateException | if this model does not contain model metadata |
---|
Gets the quantization parameters for the output tensor specified by outputIndex
.
outputIndex | the index of the desired output tensor |
---|
Gets the shape of the output tensor with outputIndex
.
outputIndex | the index of the desired output tensor |
---|
Gets the ERROR(/TensorType)
of the output tensor with outputIndex
.
outputIndex | the index of the desired output tensor |
---|
Returns true
if the model has metadata. Otherwise, returns false
.
Returns true
if the minimum parser version required by the given metadata flatbuffer
precedes or equals to the version of the metadata parser that this MetadataExtractor library is
relying on. All fields in the metadata can be parsed correctly with this metadata extractor
library in this case. Otherwise, it returns false
.
For example, assume the underlying metadata parser version is 1.14.1
,
true
, if the required minimum parser version is the same or older,
such as 1.14.1
or 1.14.0
. Null version precedes all numeric versions,
because some metadata flatbuffers are generated before the first versioned release; false
, if the required minimum parser version is newer, such as 1.14.2
.