third_party/tflite_support/src/tensorflow_lite_support/metadata/python/metadata.py
def _validate_metadata(self, metadata_buf):
    """Validates the metadata to be populated."""
    _assert_metadata_buffer_identifier(metadata_buf)

    # Verify the number of SubgraphMetadata is exactly one.
    # TFLite currently only support one subgraph.
    model_meta = _metadata_fb.ModelMetadata.GetRootAsModelMetadata(
        metadata_buf, 0)
    if model_meta.SubgraphMetadataLength() != 1:
      raise ValueError("The number of SubgraphMetadata should be exactly one, "
                       "but got {0}.".format(
                           model_meta.SubgraphMetadataLength()))

    # Verify if the number of tensor metadata matches the number of tensors.
    with open(self._model_file, "rb") as f:
      model_buf = f.read()
    model = _schema_fb.Model.GetRootAsModel(model_buf, 0)

    num_input_tensors = model.Subgraphs(0).InputsLength()
    num_input_meta = model_meta.SubgraphMetadata(0).InputTensorMetadataLength()
    if num_input_tensors != num_input_meta:
      raise ValueError(
          "The number of input tensors ({0}) should match the number of "
          "input tensor metadata ({1})".format(num_input_tensors,
                                               num_input_meta))
    num_output_tensors = model.Subgraphs(0).OutputsLength()
    num_output_meta = model_meta.SubgraphMetadata(
        0).OutputTensorMetadataLength()
    if num_output_tensors != num_output_meta:
      raise ValueError(
          "The number of output tensors ({0}) should match the number of "
          "output tensor metadata ({1})".format(num_output_tensors,
                                                num_output_meta))
Validates the metadata to be populated.
Validates the metadata to be populated.
Validates the metadata to be populated .
def _validate_metadata(self, metadata_buf):
    _assert_metadata_buffer_identifier(metadata_buf)
    model_meta = _metadata_fb.ModelMetadata.GetRootAsModelMetadata(
        metadata_buf, 0)
    if model_meta.SubgraphMetadataLength() != 1:
      raise ValueError("The number of SubgraphMetadata should be exactly one, "
                       "but got {0}.".format(
                           model_meta.SubgraphMetadataLength()))
    with open(self._model_file, "rb") as f:
      model_buf = f.read()
    model = _schema_fb.Model.GetRootAsModel(model_buf, 0)
    num_input_tensors = model.Subgraphs(0).InputsLength()
    num_input_meta = model_meta.SubgraphMetadata(0).InputTensorMetadataLength()
    if num_input_tensors != num_input_meta:
      raise ValueError(
          "The number of input tensors ({0}) should match the number of "
          "input tensor metadata ({1})".format(num_input_tensors,
                                               num_input_meta))
    num_output_tensors = model.Subgraphs(0).OutputsLength()
    num_output_meta = model_meta.SubgraphMetadata(
        0).OutputTensorMetadataLength()
    if num_output_tensors != num_output_meta:
      raise ValueError(
          "The number of output tensors ({0}) should match the number of "
          "output tensor metadata ({1})".format(num_output_tensors,
                                                num_output_meta))
def _validate_metadata ( self , metadata_buf ) : _assert_metadata_buffer_identifier ( metadata_buf ) model_meta = _metadata_fb . ModelMetadata . GetRootAsModelMetadata ( metadata_buf , 0 ) if model_meta . SubgraphMetadataLength ( ) != 1 : raise ValueError ( "The number of SubgraphMetadata should be exactly one, " "but got {0}." . format ( model_meta . SubgraphMetadataLength ( ) ) ) with open ( self . _model_file , "rb" ) as f : model_buf = f . read ( ) model = _schema_fb . Model . GetRootAsModel ( model_buf , 0 ) num_input_tensors = model . Subgraphs ( 0 ) . InputsLength ( ) num_input_meta = model_meta . SubgraphMetadata ( 0 ) . InputTensorMetadataLength ( ) if num_input_tensors != num_input_meta : raise ValueError ( "The number of input tensors ({0}) should match the number of " "input tensor metadata ({1})" . format ( num_input_tensors , num_input_meta ) ) num_output_tensors = model . Subgraphs ( 0 ) . OutputsLength ( ) num_output_meta = model_meta . SubgraphMetadata ( 0 ) . OutputTensorMetadataLength ( ) if num_output_tensors != num_output_meta : raise ValueError ( "The number of output tensors ({0}) should match the number of " "output tensor metadata ({1})" . format ( num_output_tensors , num_output_meta ) )
Validates the metadata to be populated.
Validates the metadata to be populated .
"""Validates the metadata to be populated.""" # Verify the number of SubgraphMetadata is exactly one. # TFLite currently only support one subgraph. # Verify if the number of tensor metadata matches the number of tensors.
self
metadata_buf