コード例 #1
0
    def _create_metadata(self):
        """Creates the metadata for an image classifier."""

        # Creates model info.
        model_meta = _metadata_fb.ModelMetadataT()
        model_meta.name = self.model_info.name
        model_meta.description = ("Identify the most prominent object in the "
                                  "image from a set of %d categories." %
                                  self.model_info.num_classes)
        model_meta.version = self.model_info.version
        model_meta.author = "TensorFlow"
        model_meta.license = ("Apache License. Version 2.0 "
                              "http://www.apache.org/licenses/LICENSE-2.0.")

        # Creates input info.
        input_meta = _metadata_fb.TensorMetadataT()
        input_meta.name = "image"
        input_meta.description = (
            "Input image to be classified. The expected image is {0} x {1}, with "
            "three channels (red, blue, and green) per pixel. Each value in the "
            "tensor is a single byte between {2} and {3}.".format(
                self.model_info.image_width, self.model_info.image_height,
                self.model_info.image_min, self.model_info.image_max))
        input_meta.content = _metadata_fb.ContentT()
        input_meta.content.contentProperties = _metadata_fb.ImagePropertiesT()
        input_meta.content.contentProperties.colorSpace = (
            _metadata_fb.ColorSpaceType.RGB)
        input_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.ImageProperties)
        input_normalization = _metadata_fb.ProcessUnitT()
        input_normalization.optionsType = (
            _metadata_fb.ProcessUnitOptions.NormalizationOptions)
        input_normalization.options = _metadata_fb.NormalizationOptionsT()
        input_normalization.options.mean = self.model_info.mean
        input_normalization.options.std = self.model_info.std
        input_meta.processUnits = [input_normalization]
        input_stats = _metadata_fb.StatsT()
        input_stats.max = [self.model_info.image_max]
        input_stats.min = [self.model_info.image_min]
        input_meta.stats = input_stats

        # Creates output info.
        output_location_meta = _metadata_fb.TensorMetadataT()
        output_location_meta.name = "location"
        output_location_meta.description = "The locations of the detected boxes."
        output_location_meta.content = _metadata_fb.ContentT()
        output_location_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.BoundingBoxProperties)
        output_location_meta.content.contentProperties = (
            _metadata_fb.BoundingBoxPropertiesT())
        output_location_meta.content.contentProperties.index = [1, 0, 3, 2]
        output_location_meta.content.contentProperties.type = (
            _metadata_fb.BoundingBoxType.BOUNDARIES)
        output_location_meta.content.contentProperties.coordinateType = (
            _metadata_fb.CoordinateType.RATIO)
        output_location_meta.content.range = _metadata_fb.ValueRangeT()
        output_location_meta.content.range.min = 0
        output_location_meta.content.range.max = 255

        output_confidence_meta = _metadata_fb.TensorMetadataT()
        output_confidence_meta.name = "confidence"
        output_confidence_meta.description = "The confidences of the detected boxes."
        output_confidence_meta.content = _metadata_fb.ContentT()
        output_confidence_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.FeatureProperties)
        output_confidence_meta.content.contentProperties = (
            _metadata_fb.FeaturePropertiesT())
        output_confidence_meta.content.range = _metadata_fb.ValueRangeT()
        output_confidence_meta.content.range.min = 0
        output_confidence_meta.content.range.max = 255

        # label_file = _metadata_fb.AssociatedFileT()
        # label_file.name = os.path.basename("labelmap.txt")
        # label_file.description = "Label of objects that this model can recognize."
        # label_file.type = _metadata_fb.AssociatedFileType.TENSOR_VALUE_LABELS
        # output_confidence_meta.associatedFiles = [label_file]

        output_landmark_meta = _metadata_fb.TensorMetadataT()
        output_landmark_meta.name = "landmark"
        output_landmark_meta.description = "The landmark of the detected boxes."
        output_landmark_meta.content = _metadata_fb.ContentT()
        output_landmark_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.FeatureProperties)
        output_landmark_meta.content.contentProperties = (
            _metadata_fb.FeaturePropertiesT())
        output_landmark_meta.content.range = _metadata_fb.ValueRangeT()
        output_landmark_meta.content.range.min = 0
        output_landmark_meta.content.range.max = 255

        # Creates subgraph info.
        subgraph = _metadata_fb.SubGraphMetadataT()
        subgraph.inputTensorMetadata = [input_meta]
        subgraph.outputTensorMetadata = [
            output_location_meta, output_confidence_meta, output_landmark_meta
        ]
        model_meta.subgraphMetadata = [subgraph]

        b = flatbuffers.Builder(0)
        b.Finish(model_meta.Pack(b),
                 _metadata.MetadataPopulator.METADATA_FILE_IDENTIFIER)
        self.metadata_buf = b.Output()
コード例 #2
0
    def _create_metadata(self):
        """Creates the metadata for an object detector."""

        model_meta = _metadata_fb.ModelMetadataT()
        model_meta.name = self.model_info.name
        model_meta.description = (
            "Identify which of a known set of objects might be present and provide "
            "information about their positions within the given image or a video "
            "stream.")
        model_meta.version = self.model_info.version
        model_meta.author = "TensorFlow Lite Model Maker"
        model_meta.license = ("Apache License. Version 2.0 "
                              "http://www.apache.org/licenses/LICENSE-2.0.")

        # Creates input info.
        input_meta = _metadata_fb.TensorMetadataT()
        input_meta.name = "image"
        input_meta.description = (
            "Input image to be detected. The expected image is {0} x {1}, with "
            "three channels (red, blue, and green) per pixel. Each value in the "
            "tensor is a single byte between 0 and 255.".format(
                self.model_info.image_width, self.model_info.image_height))
        input_meta.content = _metadata_fb.ContentT()
        input_meta.content.contentProperties = _metadata_fb.ImagePropertiesT()
        input_meta.content.contentProperties.colorSpace = (
            _metadata_fb.ColorSpaceType.RGB)
        input_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.ImageProperties)
        input_normalization = _metadata_fb.ProcessUnitT()
        input_normalization.optionsType = (
            _metadata_fb.ProcessUnitOptions.NormalizationOptions)
        input_normalization.options = _metadata_fb.NormalizationOptionsT()
        input_normalization.options.mean = self.model_info.mean
        input_normalization.options.std = self.model_info.std
        input_meta.processUnits = [input_normalization]
        input_stats = _metadata_fb.StatsT()
        input_stats.max = [self.model_info.image_max]
        input_stats.min = [self.model_info.image_min]
        input_meta.stats = input_stats

        # Creates outputs info.
        output_location_meta = _metadata_fb.TensorMetadataT()
        output_location_meta.name = "location"
        output_location_meta.description = "The locations of the detected boxes."
        output_location_meta.content = _metadata_fb.ContentT()
        output_location_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.BoundingBoxProperties)
        output_location_meta.content.contentProperties = (
            _metadata_fb.BoundingBoxPropertiesT())
        output_location_meta.content.contentProperties.index = [1, 0, 3, 2]
        output_location_meta.content.contentProperties.type = (
            _metadata_fb.BoundingBoxType.BOUNDARIES)
        output_location_meta.content.contentProperties.coordinateType = (
            _metadata_fb.CoordinateType.RATIO)
        output_location_meta.content.range = _metadata_fb.ValueRangeT()
        output_location_meta.content.range.min = 2
        output_location_meta.content.range.max = 2

        output_class_meta = _metadata_fb.TensorMetadataT()
        output_class_meta.name = "category"
        output_class_meta.description = "The categories of the detected boxes."
        output_class_meta.content = _metadata_fb.ContentT()
        output_class_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.FeatureProperties)
        output_class_meta.content.contentProperties = (
            _metadata_fb.FeaturePropertiesT())
        output_class_meta.content.range = _metadata_fb.ValueRangeT()
        output_class_meta.content.range.min = 2
        output_class_meta.content.range.max = 2
        label_file = _metadata_fb.AssociatedFileT()
        label_file.name = os.path.basename(self.associated_files[0])
        label_file.description = "Label of objects that this model can recognize."
        label_file.type = _metadata_fb.AssociatedFileType.TENSOR_VALUE_LABELS
        output_class_meta.associatedFiles = [label_file]

        output_score_meta = _metadata_fb.TensorMetadataT()
        output_score_meta.name = "score"
        output_score_meta.description = "The scores of the detected boxes."
        output_score_meta.content = _metadata_fb.ContentT()
        output_score_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.FeatureProperties)
        output_score_meta.content.contentProperties = (
            _metadata_fb.FeaturePropertiesT())
        output_score_meta.content.range = _metadata_fb.ValueRangeT()
        output_score_meta.content.range.min = 2
        output_score_meta.content.range.max = 2

        output_number_meta = _metadata_fb.TensorMetadataT()
        output_number_meta.name = "number of detections"
        output_number_meta.description = "The number of the detected boxes."
        output_number_meta.content = _metadata_fb.ContentT()
        output_number_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.FeatureProperties)
        output_number_meta.content.contentProperties = (
            _metadata_fb.FeaturePropertiesT())

        # Creates subgraph info.
        group = _metadata_fb.TensorGroupT()
        group.name = "detection result"
        group.tensorNames = [
            output_location_meta.name, output_class_meta.name,
            output_score_meta.name
        ]
        subgraph = _metadata_fb.SubGraphMetadataT()
        subgraph.inputTensorMetadata = [input_meta]
        subgraph.outputTensorMetadata = [
            output_location_meta, output_class_meta, output_score_meta,
            output_number_meta
        ]
        subgraph.outputTensorGroups = [group]
        model_meta.subgraphMetadata = [subgraph]

        b = flatbuffers.Builder(0)
        b.Finish(model_meta.Pack(b),
                 _metadata.MetadataPopulator.METADATA_FILE_IDENTIFIER)
        self.metadata_buf = b.Output()
コード例 #3
0
input_normalization.options.std = [127.5]
input_meta.processUnits = [input_normalization]
input_stats = _metadata_fb.StatsT()
input_stats.max = [255]
input_stats.min = [0]
input_meta.stats = input_stats

# Creates outputs info.
output_location_meta = _metadata_fb.TensorMetadataT()
output_location_meta.name = "location"
output_location_meta.description = "The locations of the detected boxes."
output_location_meta.content = _metadata_fb.ContentT()
output_location_meta.content.contentPropertiesType = (
    _metadata_fb.ContentProperties.BoundingBoxProperties)
output_location_meta.content.contentProperties = (
    _metadata_fb.BoundingBoxPropertiesT())
output_location_meta.content.contentProperties.index = [1, 0, 3, 2]
output_location_meta.content.contentProperties.type = (
    _metadata_fb.BoundingBoxType.BOUNDARIES)
output_location_meta.content.contentProperties.coordinateType = (
    _metadata_fb.CoordinateType.RATIO)
output_location_meta.content.range = _metadata_fb.ValueRangeT()
output_location_meta.content.range.min = 2
output_location_meta.content.range.max = 2
output_class_meta = _metadata_fb.TensorMetadataT()
output_class_meta.name = "category"
output_class_meta.description = "The categories of the detected boxes."
output_class_meta.content = _metadata_fb.ContentT()
output_class_meta.content.contentPropertiesType = (
    _metadata_fb.ContentProperties.FeatureProperties)
output_class_meta.content.contentProperties = (
コード例 #4
0
input_stats.max = [255]
input_stats.min = [0]
input_meta.stats = input_stats

labelmap_file = "F:/Android/object_detection/android/app/src/main/assets/labelmap.txt"
exported_model_path = "F:/Android/object_detection/android/app/src/main/assets/model_fpnlite640.tflite"

output_tensorgroups = _metadata_fb.TensorGroupT()
output_tensorgroups.name = "detection result"
output_tensorgroups.tensorNames = ["location", "category", "score"]

location = _metadata_fb.TensorMetadataT()
location.name = "location"
location.description = "The location of the detected boxes. "
location.content = _metadata_fb.ContentT()
location.content.contentProperties = (_metadata_fb.BoundingBoxPropertiesT())
location.content.contentProperties.index = [1,0,3,2]
location.content.contentProperties.type = (_metadata_fb.BoundingBoxType.BOUNDARIES)
location.content.contentProperties.coordinateType = (_metadata_fb.CoordinateType.RATIO)
location.content.contentPropertiesType = (_metadata_fb.ContentProperties.BoundingBoxProperties)
location.content.range = _metadata_fb.ValueRangeT()
location.content.range.min = 2
location.content.range.max = 2

category = _metadata_fb.TensorMetadataT()
category.name = "category"
category.description = "The categories of the detected boxes. "
category.content = _metadata_fb.ContentT()
category.content.contentPropertiesType = (_metadata_fb.ContentProperties.FeatureProperties)
category.content.contentProperties = (_metadata_fb.FeaturePropertiesT())
category.content.range = _metadata_fb.ValueRangeT()
コード例 #5
0
    def _create_metadata(self):
        """Creates the metadata for an image classifier."""

        # Creates model info.
        model_meta = _metadata_fb.ModelMetadataT()
        model_meta.name = self.model_info.name
        model_meta.description = ("Equipment.")
        model_meta.version = self.model_info.version
        model_meta.author = "TensorFlow"
        model_meta.license = ("Apache License. Version 2.0 "
                              "http://www.apache.org/licenses/LICENSE-2.0.")

        # Creates input info.
        input_meta = _metadata_fb.TensorMetadataT()
        input_meta.name = "image"
        input_meta.description = (
            "The expected image is 300 x 300, with three channels "
            "(re, blue, and green) per pixel. Each value in the tensor is between"
            " 0 and 1.")
        input_meta.content = _metadata_fb.ContentT()
        input_meta.content.contentProperties = _metadata_fb.ImagePropertiesT()
        input_meta.content.contentProperties.colorSpace = (
            _metadata_fb.ColorSpaceType.RGB)
        input_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.ImageProperties)
        input_normalization = _metadata_fb.ProcessUnitT()
        input_normalization.optionsType = (
            _metadata_fb.ProcessUnitOptions.NormalizationOptions)
        input_normalization.options = _metadata_fb.NormalizationOptionsT()
        input_normalization.options.mean = self.model_info.mean
        input_normalization.options.std = self.model_info.std
        input_meta.processUnits = [input_normalization]
        input_stats = _metadata_fb.StatsT()
        input_stats.max = [self.model_info.image_max]
        input_stats.min = [self.model_info.image_min]
        input_meta.stats = input_stats

        # Creates output info.
        output_location_meta = _metadata_fb.TensorMetadataT()
        output_location_meta.name = "location"
        output_location_meta.description = "The locations of the detected boxes."
        output_location_meta.content = _metadata_fb.ContentT()
        output_location_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.BoundingBoxProperties)
        output_location_meta.content.contentProperties = (
            _metadata_fb.BoundingBoxPropertiesT())
        output_location_meta.content.contentProperties.index = [1, 0, 3, 2]
        output_location_meta.content.contentProperties.type = (
            _metadata_fb.BoundingBoxType.BOUNDARIES)
        output_location_meta.content.contentProperties.coordinateType = (
            _metadata_fb.CoordinateType.RATIO)
        output_location_meta.content.range = _metadata_fb.ValueRangeT()
        output_location_meta.content.range.min = 2
        output_location_meta.content.range.max = 2

        output_class_meta = _metadata_fb.TensorMetadataT()
        output_class_meta.name = "category"
        output_class_meta.description = "The categories of the detected boxes."
        output_class_meta.content = _metadata_fb.ContentT()
        output_class_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.FeatureProperties)
        output_class_meta.content.contentProperties = (
            _metadata_fb.FeaturePropertiesT())
        output_class_meta.content.range = _metadata_fb.ValueRangeT()
        output_class_meta.content.range.min = 2
        output_class_meta.content.range.max = 2
        label_file = _metadata_fb.AssociatedFileT()
        label_file.name = os.path.basename(self.label_file_path)
        label_file.description = "Label of objects that this model can recognize."
        label_file.type = _metadata_fb.AssociatedFileType.TENSOR_VALUE_LABELS
        output_class_meta.associatedFiles = [label_file]

        output_score_meta = _metadata_fb.TensorMetadataT()
        output_score_meta.name = "score"
        output_score_meta.description = "The scores of the detected boxes."
        output_score_meta.content = _metadata_fb.ContentT()
        output_score_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.FeatureProperties)
        output_score_meta.content.contentProperties = (
            _metadata_fb.FeaturePropertiesT())
        output_score_meta.content.range = _metadata_fb.ValueRangeT()
        output_score_meta.content.range.min = 2
        output_score_meta.content.range.max = 2

        output_number_meta = _metadata_fb.TensorMetadataT()
        output_number_meta.name = "number of detections"
        output_number_meta.description = "The number of the detected boxes."
        output_number_meta.content = _metadata_fb.ContentT()
        output_number_meta.content.contentPropertiesType = (
            _metadata_fb.ContentProperties.FeatureProperties)
        output_number_meta.content.contentProperties = (
            _metadata_fb.FeaturePropertiesT())

        # Creates subgraph info.
        group = _metadata_fb.TensorGroupT()
        group.name = "detection result"
        group.tensorNames = [
            output_location_meta.name, output_class_meta.name,
            output_score_meta.name
        ]
        subgraph = _metadata_fb.SubGraphMetadataT()
        subgraph.inputTensorMetadata = [input_meta]
        subgraph.outputTensorMetadata = [
            output_location_meta, output_class_meta, output_score_meta,
            output_number_meta
        ]
        subgraph.outputTensorGroups = [group]
        model_meta.subgraphMetadata = [subgraph]

        b = flatbuffers.Builder(0)
        b.Finish(model_meta.Pack(b),
                 _metadata.MetadataPopulator.METADATA_FILE_IDENTIFIER)
        self.metadata_buf = b.Output()