Skip to content

Commit

Permalink
Add Audio tensor metadata
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 364377123
  • Loading branch information
lu-wang-g authored and tflite-support-robot committed Mar 22, 2021
1 parent 8ca2c65 commit da5a9f0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
19 changes: 19 additions & 0 deletions tensorflow_lite_support/metadata/cc/metadata_version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum class SchemaMembers {
kSubGraphMetadataInputTensorGroups = 5,
kSubGraphMetadataOutputTensorGroups = 6,
kProcessUnitOptionsRegexTokenizerOptions = 7,
kContentPropertiesAudioProperties = 8,
};

// Helper class to compare semantic versions in terms of three integers, major,
Expand Down Expand Up @@ -107,6 +108,8 @@ 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);
default:
// Should never happen.
TFLITE_LOG(FATAL) << "Unsupported schema member: "
Expand Down Expand Up @@ -176,6 +179,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) {
Expand All @@ -188,6 +204,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 <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class MetadataParser {
* The version of the metadata parser that this metadata extractor library is depending on. The
* value should match the value of "Schema Semantic version" in metadata_schema.fbs.
*/
public static final String VERSION = "1.2.1";
public static final String VERSION = "1.3.0";

private MetadataParser() {}
}
19 changes: 18 additions & 1 deletion tensorflow_lite_support/metadata/metadata_schema.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace tflite;
// for which they were added.
//
// LINT.IfChange
// Schema Semantic version: 1.2.1
// Schema Semantic version: 1.3.0
// LINT.ThenChange(//tensorflow_lite_support/\
// metadata/java/src/java/org/tensorflow/lite/support/metadata/\
// MetadataParser.java)
Expand All @@ -69,6 +69,7 @@ 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.

// File extension of any written files.
file_extension "tflitemeta";
Expand Down Expand Up @@ -232,6 +233,20 @@ 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;

// The minimum required number of samples in order to run inference properly.
// Optional for fixed-size audio tensors.
min_required_samples:uint;
}

enum CoordinateType : byte {
// The coordinates are float values from 0 to 1.
RATIO = 0,
Expand Down Expand Up @@ -267,6 +282,8 @@ union ContentProperties {
FeatureProperties,
ImageProperties,
BoundingBoxProperties,
// Added in: 1.3.0
AudioProperties,
}

table ValueRange {
Expand Down

0 comments on commit da5a9f0

Please sign in to comment.