aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfban <fban@google.com>2022-07-12 23:21:56 +0000
committerPresubmit Automerger Backend <android-build-presubmit-automerger-backend@system.gserviceaccount.com>2022-07-12 23:21:56 +0000
commit76360ffa8485312339d54c268f41e6d80209ae62 (patch)
treefae7df79289df388cb3855f1c18139520d8d0f78
parent532f6fe9797b7ab0da7fcbbe6641ec9cb5b2fee4 (diff)
parentf5a5d1ca8a4b1455a969ac19776341f0b3638870 (diff)
downloadtflite-support-76360ffa8485312339d54c268f41e6d80209ae62.tar.gz
[automerge] Updates metadata schema and version in AOSP. 2p: f5a5d1ca8a
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/tflite-support/+/19271429 Bug: 236080613 Change-Id: Ia720b755a26b51733409705d2f33faf9f3d31ab6
-rw-r--r--tensorflow_lite_support/metadata/cc/metadata_version.cc37
-rw-r--r--tensorflow_lite_support/metadata/metadata_schema.fbs53
2 files changed, 84 insertions, 6 deletions
diff --git a/tensorflow_lite_support/metadata/cc/metadata_version.cc b/tensorflow_lite_support/metadata/cc/metadata_version.cc
index 7679f6c4..baceca91 100644
--- a/tensorflow_lite_support/metadata/cc/metadata_version.cc
+++ b/tensorflow_lite_support/metadata/cc/metadata_version.cc
@@ -45,6 +45,9 @@ enum class SchemaMembers {
kSubGraphMetadataInputTensorGroups = 5,
kSubGraphMetadataOutputTensorGroups = 6,
kProcessUnitOptionsRegexTokenizerOptions = 7,
+ kContentPropertiesAudioProperties = 8,
+ kAssociatedFileTypeScannIndexFile = 9,
+ kAssociatedFileVersion = 10,
};
// Helper class to compare semantic versions in terms of three integers, major,
@@ -107,6 +110,12 @@ Version GetMemberVersion(SchemaMembers member) {
return Version(1, 2, 0);
case SchemaMembers::kProcessUnitOptionsRegexTokenizerOptions:
return Version(1, 2, 1);
+ case SchemaMembers::kContentPropertiesAudioProperties:
+ return Version(1, 3, 0);
+ case SchemaMembers::kAssociatedFileTypeScannIndexFile:
+ return Version(1, 4, 0);
+ case SchemaMembers::kAssociatedFileVersion:
+ return Version(1, 4, 1);
default:
// Should never happen.
TFLITE_LOG(FATAL) << "Unsupported schema member: "
@@ -148,6 +157,18 @@ void UpdateMinimumVersionForTable<tflite::AssociatedFile>(
GetMemberVersion(SchemaMembers::kAssociatedFileTypeVocabulary),
min_version);
}
+
+ if (table->type() == AssociatedFileType_SCANN_INDEX_FILE) {
+ UpdateMinimumVersion(
+ GetMemberVersion(SchemaMembers::kAssociatedFileTypeScannIndexFile),
+ min_version);
+ }
+
+ if (table->version() != nullptr) {
+ UpdateMinimumVersion(
+ GetMemberVersion(SchemaMembers::kAssociatedFileVersion),
+ min_version);
+ }
}
template <>
@@ -177,6 +198,19 @@ void UpdateMinimumVersionForTable<tflite::ProcessUnit>(
}
template <>
+void UpdateMinimumVersionForTable<tflite::Content>(const tflite::Content* table,
+ Version* min_version) {
+ if (table == nullptr) return;
+
+ // Checks the ContenProperties field.
+ if (table->content_properties_type() == ContentProperties_AudioProperties) {
+ UpdateMinimumVersion(
+ GetMemberVersion(SchemaMembers::kContentPropertiesAudioProperties),
+ min_version);
+ }
+}
+
+template <>
void UpdateMinimumVersionForTable<tflite::TensorMetadata>(
const tflite::TensorMetadata* table, Version* min_version) {
if (table == nullptr) return;
@@ -188,6 +222,9 @@ void UpdateMinimumVersionForTable<tflite::TensorMetadata>(
// Checks the process_units field.
UpdateMinimumVersionForArray<tflite::ProcessUnit>(table->process_units(),
min_version);
+
+ // Check the content field.
+ UpdateMinimumVersionForTable<tflite::Content>(table->content(), min_version);
}
template <>
diff --git a/tensorflow_lite_support/metadata/metadata_schema.fbs b/tensorflow_lite_support/metadata/metadata_schema.fbs
index 6ce94525..35b3bd94 100644
--- a/tensorflow_lite_support/metadata/metadata_schema.fbs
+++ b/tensorflow_lite_support/metadata/metadata_schema.fbs
@@ -50,7 +50,7 @@ namespace tflite;
// for which they were added.
//
// LINT.IfChange
-// Schema Semantic version: 1.2.1
+// Schema Semantic version: 1.4.1
// LINT.ThenChange(//tensorflow_lite_support/\
// metadata/java/src/java/org/tensorflow/lite/support/metadata/\
// MetadataParser.java)
@@ -69,6 +69,9 @@ file_identifier "M001";
// 1.2.0 - Added input_tensor_group to SubGraphMetadata.
// Added output_tensor_group to SubGraphMetadata.
// 1.2.1 - Added RegexTokenizerOptions to ProcessUnitOptions.
+// 1.3.0 - Added AudioProperties to ContentProperties.
+// 1.4.0 - Added SCANN_INDEX_FILE type to AssociatedFileType.
+// 1.4.1 - Added version to AssociatedFile.
// File extension of any written files.
file_extension "tflitemeta";
@@ -80,10 +83,12 @@ enum AssociatedFileType : byte {
// Files such as readme.txt.
DESCRIPTIONS = 1,
- // Contains labels that annotate certain axis of the tensor. For example,
+ // Contains a list of labels (characters separated by "\n" or in lines) that
+ // annotate certain axis of the tensor. For example,
// the label file in image classification. Those labels annotate the
// the output tensor, such that each value in the output tensor is the
- // probability of that corresponding category specified by the label.
+ // probability of that corresponding category specified by the label. See the
+ // example label file used in image classification [1].
//
// <Codegen usage>:
// If an output tensor has an associated file as TENSOR_AXIS_LABELS, return
@@ -92,12 +97,16 @@ enum AssociatedFileType : byte {
// If multiple files of the same type are present, the first one is used by
// default; additional ones are to be distinguished from one another by their
// specified locale.
+ //
+ // [1]: https://github.com/tensorflow/tflite-support/blob/master/tensorflow_lite_support/metadata/python/tests/testdata/image_classifier/labels.txt
TENSOR_AXIS_LABELS = 2,
- // Contains labels that tensor values correspond to. For example, in
+ // Contains a list of labels (characters separated by "\n" or in lines) that
+ // tensor values correspond to. For example, in
// the object detection model, one of the output tensors is the detected
// classes. And each value in the tensor refers to the index of label in the
- // category label file.
+ // category label file. See the example label file used in object detection
+ // [1].
//
// <Codegen usage>:
// If an output tensor has an associated file as TENSOR_VALUE_LABELS, convert
@@ -105,25 +114,41 @@ enum AssociatedFileType : byte {
// If multiple files of the same type are present, the first one is used by
// default; additional ones are to be distinguished from one another by their
// specified locale.
+ //
+ // [1]: https://github.com/tensorflow/tflite-support/blob/master/tensorflow_lite_support/metadata/python/tests/testdata/object_detector/labelmap.txt
TENSOR_VALUE_LABELS = 3,
// Contains sigmoid-based score calibration parameters, formatted as CSV.
// Lines contain for each index of an output tensor the scale, slope, offset
// and (optional) min_score parameters to be used for sigmoid fitting (in this
- // order and in `strtof`-compatible [1] format).
+ // order and in `strtof`-compatible [1] format). Scale should be a
+ // non-negative value.
// A line may be left empty to default calibrated scores for this index to
// default_score.
// In summary, each line should thus contain 0, 3 or 4 comma-separated values.
//
+ // See the example score calibration file used in image classification [2].
+ //
// See documentation for ScoreCalibrationOptions for details.
//
// [1]: https://en.cppreference.com/w/c/string/byte/strtof
+ // [2]: https://github.com/tensorflow/tflite-support/blob/master/tensorflow_lite_support/metadata/python/tests/testdata/image_classifier/score_calibration.txt
TENSOR_AXIS_SCORE_CALIBRATION = 4,
// Contains a list of unique words (characters separated by "\n" or in lines)
// that help to convert natural language words to embedding vectors.
+ //
+ // See the example vocab file used in text classification [1].
+ //
+ // [1]: https://github.com/tensorflow/tflite-support/blob/master/tensorflow_lite_support/metadata/python/tests/testdata/nl_classifier/vocab.txt
// Added in: 1.0.1
VOCABULARY = 5,
+
+ // TODO(b/222351186): introduce the ScaNN index file with links once the code
+ // is released.
+ // Contains on-devide ScaNN index file with LevelDB format.
+ // Added in: 1.4.0
+ SCANN_INDEX_FILE = 6,
}
table AssociatedFile {
@@ -154,6 +179,7 @@ table AssociatedFile {
locale:string;
// Version of the file specified by model creators.
+ // Added in: 1.4.1
version:string;
}
@@ -235,6 +261,16 @@ enum BoundingBoxType : byte {
}
+// The properties for audio tensors.
+// Added in: 1.3.0
+table AudioProperties {
+ // The sample rate in Hz when the audio was captured.
+ sample_rate:uint;
+
+ // The channel count of the audio.
+ channels:uint;
+}
+
enum CoordinateType : byte {
// The coordinates are float values from 0 to 1.
RATIO = 0,
@@ -270,6 +306,8 @@ union ContentProperties {
FeatureProperties,
ImageProperties,
BoundingBoxProperties,
+ // Added in: 1.3.0
+ AudioProperties,
}
table ValueRange {
@@ -415,6 +453,9 @@ enum ScoreTransformationType : byte {
// An AssociatedFile with type TANSOR_AXIS_SCORE_CALIBRATION specifying the
// index-specific parameters must be associated with the corresponding
// TensorMetadata for score calibration be applied.
+//
+// See the example score calibration file used in image classification [1].
+// [1]: https://github.com/tensorflow/tflite-support/blob/master/tensorflow_lite_support/metadata/python/tests/testdata/image_classifier/score_calibration.txt
table ScoreCalibrationOptions {
// The function to use for transforming the uncalibrated score before
// applying score calibration.