Ejemplo n.º 1
0
    def _create_metadata_file(self):
        associated_file1 = _metadata_fb.AssociatedFileT()
        associated_file1.name = b"file1"
        associated_file2 = _metadata_fb.AssociatedFileT()
        associated_file2.name = b"file2"
        self.expected_recorded_files = [
            six.ensure_str(associated_file1.name),
            six.ensure_str(associated_file2.name)
        ]

        output_meta = _metadata_fb.TensorMetadataT()
        output_meta.associatedFiles = [associated_file2]
        subgraph = _metadata_fb.SubGraphMetadataT()
        subgraph.outputTensorMetadata = [output_meta]

        model_meta = _metadata_fb.ModelMetadataT()
        model_meta.name = "Mobilenet_quantized"
        model_meta.associatedFiles = [associated_file1]
        model_meta.subgraphMetadata = [subgraph]
        b = flatbuffers.Builder(0)
        b.Finish(model_meta.Pack(b),
                 _metadata.MetadataPopulator.METADATA_FILE_IDENTIFIER)

        metadata_file = self.create_tempfile().full_path
        with open(metadata_file, "wb") as f:
            f.write(b.Output())
        return metadata_file
Ejemplo n.º 2
0
 def _create_metadata_buffer_with_wrong_identifier(self):
     # Creates a metadata with wrong identifier
     wrong_identifier = b"widn"
     metadata = _metadata_fb.ModelMetadataT()
     metadata_builder = flatbuffers.Builder(0)
     metadata_builder.Finish(metadata.Pack(metadata_builder),
                             wrong_identifier)
     return metadata_builder.Output()
Ejemplo n.º 3
0
  def testPopulateMetadataFileToModelWithMetadataAndAssociatedFiles(self):
    # First, creates a dummy metadata. Populates it and the associated files
    # into the model.
    model_meta = _metadata_fb.ModelMetadataT()
    model_meta.name = "Mobilenet_quantized"
    b = flatbuffers.Builder(0)
    b.Finish(
        model_meta.Pack(b),
        _metadata.MetadataPopulator.METADATA_FILE_IDENTIFIER)
    metadata_buf = b.Output()

    populator1 = _metadata.MetadataPopulator.with_model_file(self._model_file)
    populator1.load_metadata_buffer(metadata_buf)
    populator1.load_associated_files([self._file1, self._file2])
    populator1.populate()

    # Then, populates the metadata again.
    populator2 = _metadata.MetadataPopulator.with_model_file(self._model_file)
    populator2.load_metadata_file(self._metadata_file)
    populator2.populate()

    # Tests if the metadata is populated correctly.
    self._assert_golden_metadata(self._model_file)