Skip to content

Instantly share code, notes, and snippets.

@nkalra0123
Created January 11, 2020 16:30
Show Gist options
  • Save nkalra0123/2d8a7f6874eaff66a469df4c3b20ca6f to your computer and use it in GitHub Desktop.
Save nkalra0123/2d8a7f6874eaff66a469df4c3b20ca6f to your computer and use it in GitHub Desktop.
Collect the relevant label information in a map
// After written to GCS, analyze the image.
AnnotateImageResponse response = analyzeImage(bucket + "/" + filename);
Map<String, Float> imageLabels =
response.getLabelAnnotationsList()
.stream()
.collect(
Collectors.toMap(
EntityAnnotation::getDescription,
EntityAnnotation::getScore,
(u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
},
LinkedHashMap::new));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment