'TensorFlow Lite model Metadata

I have a segmentation model with a classification branch with the final model containing two outputs. I am trying to convert the model to TfLite while adding the metadata but I am getting this error.

ValueError: The number of output tensors (2) should match the number of output tensor metadata (1)

This is how I am adding the metadata

    def add_metadata(self, label_file_paths=[]):
        """
        adds metadata to the model to be used for inference on android and writes it to a file
        """
        print("INFO: Adding metadata")
        from tflite_support.metadata_writers import writer_utils, image_segmenter
        model_path = self.tflite_quant_model_name

        writer = image_segmenter.MetadataWriter.create_for_inference(
            writer_utils.load_file(model_path),
            [self.NORM_MEAN],
            [self.NORM_STD],
            label_file_paths=label_file_paths
        )

Is there a way I can pass the model outputs while adding the metadata?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source