[BEAM-10050][BEAM-10058][release-2.22.0] Fix VideoIntelligence Test flakes (#11892)
* [BEAM-10050] Change labels checked in VideoIntelligenceIT (#11775)
[BEAM-10050] Change labels checked in VideoIntelligenceIT to make the test more resistant to future ML model changes.
* Merge pull request #11795: [BEAM-10058] Provide less strict assertion to make the test more resistant against future changes in a model
Co-authored-by: Michal Walenia <32354134+mwalenia@users.noreply.github.com>
Co-authored-by: Kamil Wasilewski <kamil.wasilewski@polidea.com>
diff --git a/sdks/java/extensions/ml/src/test/java/org/apache/beam/sdk/extensions/ml/VideoIntelligenceIT.java b/sdks/java/extensions/ml/src/test/java/org/apache/beam/sdk/extensions/ml/VideoIntelligenceIT.java
index 6427225..20e9145 100644
--- a/sdks/java/extensions/ml/src/test/java/org/apache/beam/sdk/extensions/ml/VideoIntelligenceIT.java
+++ b/sdks/java/extensions/ml/src/test/java/org/apache/beam/sdk/extensions/ml/VideoIntelligenceIT.java
@@ -58,7 +58,7 @@
@Override
public Void apply(Iterable<List<VideoAnnotationResults>> input) {
List<Boolean> labelEvaluations = new ArrayList<>();
- input.forEach(findStringMatchesInVideoAnnotationResultList(labelEvaluations, "dinosaur"));
+ input.forEach(findStringMatchesInVideoAnnotationResultList(labelEvaluations, "bicycle"));
assertEquals(Boolean.TRUE, labelEvaluations.contains(Boolean.TRUE));
return null;
}
@@ -73,9 +73,9 @@
private boolean entityWithDescriptionFoundInSegmentLabels(
String toMatch, VideoAnnotationResults result) {
- return result.getSegmentLabelAnnotationsList().stream()
+ return result.getSegmentPresenceLabelAnnotationsList().stream()
.anyMatch(
- labelAnnotation -> labelAnnotation.getEntity().getDescription().equals(toMatch));
+ labelAnnotation -> labelAnnotation.getEntity().getDescription().contains(toMatch));
}
}
}
diff --git a/sdks/python/apache_beam/ml/gcp/videointelligenceml_test_it.py b/sdks/python/apache_beam/ml/gcp/videointelligenceml_test_it.py
index f411549..397256e 100644
--- a/sdks/python/apache_beam/ml/gcp/videointelligenceml_test_it.py
+++ b/sdks/python/apache_beam/ml/gcp/videointelligenceml_test_it.py
@@ -44,7 +44,7 @@
def extract_entities_descriptions(response):
for result in response.annotation_results:
- for segment in result.segment_label_annotations:
+ for segment in result.segment_presence_label_annotations:
yield segment.entity.description
@@ -69,7 +69,9 @@
| beam.ParDo(extract_entities_descriptions)
| beam.combiners.ToList())
- assert_that(output, matches_all([hc.has_items('bicycle', 'dinosaur')]))
+ # Search for at least one entity that contains 'bicycle'.
+ assert_that(
+ output, matches_all([hc.has_item(hc.contains_string('bicycle'))]))
if __name__ == '__main__':