public class **MetadataExtractor** Loads metadata from TFLite Model FlatBuffer.

TFLite Model FlatBuffer can be generated using the [TFLite
Model schema file.](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/schema/schema.fbs)

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.](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/schema/metadata_schema.fbs)

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.](https://www.tensorflow.org/lite/convert/cmdline_examples#specifying_subgraphs) Therefore, `https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor` omits subgraph index as an input in its methods.

<br />

<br />

<br />

<br />

<br />

### Nested Classes

|---|---|---|---|
| class | [MetadataExtractor.QuantizationParams](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor.QuantizationParams) || Quantization parameters that corresponds to the table, `QuantizationParameters`, in the [TFLite Model schema file.](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/schema/schema.fbs) |

### Public Constructors

|---|---|
|   | [MetadataExtractor](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#MetadataExtractor(java.nio.ByteBuffer))([ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html) buffer) Creates a `https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor` with TFLite model FlatBuffer. |

### Public Methods

|---|---|
| [InputStream](https://developer.android.com/reference/java/io/InputStream.html) | [getAssociatedFile](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getAssociatedFile(java.lang.String))([String](https://developer.android.com/reference/java/lang/String.html) fileName) Gets the packed associated file with the specified `fileName`. |
| [Set](https://developer.android.com/reference/java/util/Set.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\> | [getAssociatedFileNames](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getAssociatedFileNames())() Gets the file names of the associated files. |
| int | [getInputTensorCount](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getInputTensorCount())() Gets the count of input tensors in the model. |
| TensorMetadata | [getInputTensorMetadata](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getInputTensorMetadata(int))(int inputIndex) Gets the metadata for the input tensor specified by `inputIndex`. |
| [MetadataExtractor.QuantizationParams](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor.QuantizationParams) | [getInputTensorQuantizationParams](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getInputTensorQuantizationParams(int))(int inputIndex) Gets the quantization parameters for the input tensor specified by `inputIndex`. |
| int\[\] | [getInputTensorShape](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getInputTensorShape(int))(int inputIndex) Gets the shape of the input tensor with `inputIndex`. |
| byte | [getInputTensorType](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getInputTensorType(int))(int inputIndex) Gets the of the input tensor with `inputIndex`. |
| ModelMetadata | [getModelMetadata](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getModelMetadata())() Gets the root handler for the model metadata. |
| int | [getOutputTensorCount](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getOutputTensorCount())() Gets the count of output tensors in the model. |
| TensorMetadata | [getOutputTensorMetadata](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getOutputTensorMetadata(int))(int outputIndex) Gets the metadata for the output tensor specified by `outputIndex`. |
| [MetadataExtractor.QuantizationParams](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor.QuantizationParams) | [getOutputTensorQuantizationParams](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getOutputTensorQuantizationParams(int))(int outputIndex) Gets the quantization parameters for the output tensor specified by `outputIndex`. |
| int\[\] | [getOutputTensorShape](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getOutputTensorShape(int))(int outputIndex) Gets the shape of the output tensor with `outputIndex`. |
| byte | [getOutputTensorType](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#getOutputTensorType(int))(int outputIndex) Gets the of the output tensor with `outputIndex`. |
| boolean | [hasMetadata](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#hasMetadata())() Returns `true` if the model has metadata. |
| final boolean | [isMinimumParserVersionSatisfied](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor#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. |

### Inherited Methods

From class java.lang.Object

|---|---|
| boolean | equals([Object](https://developer.android.com/reference/java/lang/Object.html) arg0) |
| final [Class](https://developer.android.com/reference/java/lang/Class.html)\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| [String](https://developer.android.com/reference/java/lang/String.html) | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

## Public Constructors

#### public
**MetadataExtractor**
([ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html) buffer)

Creates a `https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor` with TFLite model FlatBuffer.

##### Parameters

| buffer | the TFLite model FlatBuffer |
|---|---|

##### Throws

| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if the number of input or output tensors in the model does not match that in the metadata |
| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if an error occurs while reading the model as a Zip file |
|---|---|

## Public Methods

#### public [InputStream](https://developer.android.com/reference/java/io/InputStream.html)
**getAssociatedFile**
([String](https://developer.android.com/reference/java/lang/String.html) fileName)

Gets the packed associated file with the specified `fileName`.

##### Parameters

| fileName | the name of the associated file |
|---|---|

##### Returns

- the raw input stream containing specified file

##### Throws

| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException.html) | if the model is not a zip file |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if the specified file does not exist in the model |
|---|---|

#### public [Set](https://developer.android.com/reference/java/util/Set.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\>
**getAssociatedFileNames**
()

Gets the file names of the associated files.

##### Returns

- the file names of the associated files

##### Throws

| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException.html) | if the model is not a zip file |
|---|---|

#### public int
**getInputTensorCount**
()

Gets the count of input tensors in the model.

#### public TensorMetadata
**getInputTensorMetadata**
(int inputIndex)

Gets the metadata for the input tensor specified by `inputIndex`.

##### Parameters

| inputIndex | the index of the desired input tensor |
|---|---|

##### Throws

| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException.html) | if this model does not contain model metadata |
|---|---|

#### public [MetadataExtractor.QuantizationParams](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor.QuantizationParams)
**getInputTensorQuantizationParams**
(int inputIndex)

Gets the quantization parameters for the input tensor specified by `inputIndex`.

##### Parameters

| inputIndex | the index of the desired input tensor |
|---|---|

#### public int\[\]
**getInputTensorShape**
(int inputIndex)

Gets the shape of the input tensor with `inputIndex`.

##### Parameters

| inputIndex | the index of the desired input tensor |
|---|---|

#### public byte
**getInputTensorType**
(int inputIndex)

Gets the of the input tensor with `inputIndex`.

##### Parameters

| inputIndex | the index of the desired input tensor |
|---|---|

#### public ModelMetadata
**getModelMetadata**
()

Gets the root handler for the model metadata.

##### Throws

| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException.html) | if this model does not contain model metadata |
|---|---|

#### public int
**getOutputTensorCount**
()

Gets the count of output tensors in the model.

#### public TensorMetadata
**getOutputTensorMetadata**
(int outputIndex)

Gets the metadata for the output tensor specified by `outputIndex`.

##### Parameters

| outputIndex | the index of the desired output tensor |
|---|---|

##### Throws

| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException.html) | if this model does not contain model metadata |
|---|---|

#### public [MetadataExtractor.QuantizationParams](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/metadata/MetadataExtractor.QuantizationParams)
**getOutputTensorQuantizationParams**
(int outputIndex)

Gets the quantization parameters for the output tensor specified by `outputIndex`.

##### Parameters

| outputIndex | the index of the desired output tensor |
|---|---|

#### public int\[\]
**getOutputTensorShape**
(int outputIndex)

Gets the shape of the output tensor with `outputIndex`.

##### Parameters

| outputIndex | the index of the desired output tensor |
|---|---|

#### public byte
**getOutputTensorType**
(int outputIndex)

Gets the of the output tensor with `outputIndex`.

##### Parameters

| outputIndex | the index of the desired output tensor |
|---|---|

#### public boolean
**hasMetadata**
()

Returns `true` if the model has metadata. Otherwise, returns `false`.

#### public 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. 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`,

- it returns `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;   
- it returns `false`, if the required minimum parser version is newer, such as `1.14.2`.

<br />

<br />