コード例 #1
0
  def create_metadata(self) -> _metadata_fb.TensorMetadataT:
    """Creates the input tensor metadata based on the information.

    Returns:
      A Flatbuffers Python object of the input metadata.
    """
    tensor_metadata = _metadata_fb.TensorMetadataT()
    tensor_metadata.name = self.name
    tensor_metadata.description = self.description

    # Create min and max values
    stats = _metadata_fb.StatsT()
    stats.max = self.max_values
    stats.min = self.min_values
    tensor_metadata.stats = stats

    # Create content properties
    content = _metadata_fb.ContentT()
    if self.content_type is _metadata_fb.ContentProperties.FeatureProperties:
      content.contentProperties = _metadata_fb.FeaturePropertiesT()
    elif self.content_type is _metadata_fb.ContentProperties.ImageProperties:
      content.contentProperties = _metadata_fb.ImagePropertiesT()
    elif self.content_type is (
        _metadata_fb.ContentProperties.BoundingBoxProperties):
      content.contentProperties = _metadata_fb.BoundingBoxPropertiesT()
    content.contentPropertiesType = self.content_type
    tensor_metadata.content = content

    # Create associated files
    if self.associated_files:
      tensor_metadata.associatedFiles = [
          file.create_metadata() for file in self.associated_files
      ]
    return tensor_metadata
コード例 #2
0
def _create_location_metadata(
        location_md: metadata_info.TensorMd) -> _metadata_fb.TensorMetadataT:
    """Creates the metadata for the location tensor."""
    location_metadata = location_md.create_metadata()
    content = _metadata_fb.ContentT()
    content.contentPropertiesType = (
        _metadata_fb.ContentProperties.BoundingBoxProperties)
    properties = _metadata_fb.BoundingBoxPropertiesT()
    properties.index = list(_BOUNDING_BOX_INDEX)
    properties.type = _metadata_fb.BoundingBoxType.BOUNDARIES
    properties.coordinateType = _metadata_fb.CoordinateType.RATIO
    content.contentProperties = properties
    content.range = _create_1d_value_range(_CONTENT_VALUE_DIM)
    location_metadata.content = content
    return location_metadata
コード例 #3
0
def _create_segmentation_masks_metadata(
        masks_md: metadata_info.TensorMd) -> _metadata_fb.TensorMetadataT:
    """Creates the metadata for the segmentation masks tensor."""
    masks_metadata = masks_md.create_metadata()

    # Create tensor content information.
    content = _metadata_fb.ContentT()
    content.contentProperties = _metadata_fb.ImagePropertiesT()
    content.contentProperties.colorSpace = _metadata_fb.ColorSpaceType.GRAYSCALE
    content.contentPropertiesType = _metadata_fb.ContentProperties.ImageProperties
    # Add the content range. See
    # https://github.com/tensorflow/tflite-support/blob/ace5d3f3ce44c5f77c70284fa9c5a4e3f2f92abb/tensorflow_lite_support/metadata/metadata_schema.fbs#L285-L347
    dim_range = _metadata_fb.ValueRangeT()
    dim_range.min = _CONTENT_DIM_MIN
    dim_range.max = _CONTENT_DIM_MAX
    content.range = dim_range
    masks_metadata.content = content

    return masks_metadata