Skip to content

Instantly share code, notes, and snippets.

@confluentgist
Forked from kaiwaehner/rpc_call.java
Created October 29, 2019 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save confluentgist/c02f985272d1f75037d1a65ee24d9a6d to your computer and use it in GitHub Desktop.
Save confluentgist/c02f985272d1f75037d1a65ee24d9a6d to your computer and use it in GitHub Desktop.
KStream<String, Object> transformedMessage = imageInputLines.mapValues(value -> {
System.out.println("Image path: " + value);
imagePath = value;
TensorflowObjectRecogniser recogniser = new TensorflowObjectRecogniser(server, port);
System.out.println("Image = " + imagePath);
InputStream jpegStream;
try {
jpegStream = new FileInputStream(imagePath);
// Prediction of the TensorFlow Image Recognition model:
List<Map.Entry<String, Double>> list = recogniser.recognise(jpegStream);
String prediction = list.toString();
System.out.println("Prediction: " + prediction);
recogniser.close();
jpegStream.close();
return prediction;
} catch (Exception e) {
e.printStackTrace();
return Collections.emptyList().toString();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment