Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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