diff --git a/mediapipe/util/sequence/media_sequence.cc b/mediapipe/util/sequence/media_sequence.cc index 62bfa19b4..f76c53295 100644 --- a/mediapipe/util/sequence/media_sequence.cc +++ b/mediapipe/util/sequence/media_sequence.cc @@ -160,6 +160,10 @@ absl::Status ReconcileMetadataFeatureFloats( const std::string& key = key_value.first; if (absl::StrContains(key, kFeatureFloatsKey)) { const auto prefix = key.substr(0, key.find(kFeatureFloatsKey) - 1); + if (GetFeatureFloatsSize(prefix, *sequence) < 1) { + // Unable to determine the feature dimensions as no data is provided. + continue; + } int number_of_elements = GetFeatureFloatsAt(prefix, *sequence, 0).size(); if (HasFeatureDimensions(prefix, *sequence) && !GetFeatureDimensions(prefix, *sequence).empty()) { diff --git a/mediapipe/util/sequence/media_sequence_test.cc b/mediapipe/util/sequence/media_sequence_test.cc index 42b0e3889..0797ed472 100644 --- a/mediapipe/util/sequence/media_sequence_test.cc +++ b/mediapipe/util/sequence/media_sequence_test.cc @@ -23,6 +23,7 @@ #include "mediapipe/framework/port/opencv_imgcodecs_inc.h" #include "mediapipe/framework/port/status_matchers.h" #include "tensorflow/core/example/example.pb.h" +#include "tensorflow/core/example/feature.pb.h" namespace mediapipe { namespace mediasequence { @@ -867,6 +868,8 @@ TEST(MediaSequenceTest, ReconcileMetadataFloats) { AddFeatureFloats(feature_name, vf, &sequence); AddFeatureTimestamp(feature_name, 1000000, &sequence); AddFeatureTimestamp(feature_name, 2000000, &sequence); + sequence.mutable_feature_lists()->mutable_feature_list()->insert( + {"EMPTY/feature/floats", tensorflow::FeatureList()}); MP_ASSERT_OK(ReconcileMetadata(true, false, &sequence)); ASSERT_EQ(GetFeatureDimensions(feature_name, sequence).size(), 1);