Combining DJL.AI With Apache NiFi for Deep Learning Workflows
In this article, see how to use deep learning in Apache NiFi with a tutorial of how to build your own custom processor for deep learning.
Join the DZone community and get the full member experience.Join For Free
NiFi + DJL.AI = A Merry Deep Learning Christmas
Happy Mmm...FLaNK Day!
I have been experimenting with the awesome new Apache 2.0 licensed Java Deep Learning Library, DJL. In NiFi, I was trying to figure out a quick use case and demo. So I used my Web Camera processor to grab a still shot from my Powerbook webcam and send it to the processor. The results are sent to slack.
Since it's the holidays, I think of my favorite holiday movies: The Matrix and Blade Runner. So I thought a Voight-Kampf test would be fun. Since I don't have a deep learning QA piece built yet, let's start by seeing if you look human. We'll call them 'person'. I am testing to see if I am a replicant. Sometimes it's hard to tell. Let's see if DJL thinks I am human.
Okay, so at least it thinks I am a person. The classification of a Christmas tree is vaguely accurate. So we can see how easy and powerful Deep Learning is in Java, adding it to NiFi makes it even easier.
It did not identify my giant french bread.
You might also be interested in: Using Apache Spark and Apache NiFi to Run TensorFlow
Building a New Custom Processor for Deep Learning
The hardest part was a good NiFi Integration test. The DJL team provides some great examples, and it's really easy to plug into their models.
ZooModel<BufferedImage, DetectedObjects> model =
MxModelZoo.SSD.loadModel(criteria, new ProgressBar())
Predictor<BufferedImage, DetectedObjects> predictor = model.newPredictor()
DetectedObjects detection = predictor.predict(img);
All the sources are on GitHub and reference the below DJL sites and repos.
Using a New Custom Processor as Part of a Real-time Holiday Flow
We first add the DeepLearningProcessor to our canvas.
An example flow:
- GetWebCameraProcessor: grab an image from an attached webcamera
- UpdateAttribute: Add media type for image
- DeepLearningProcessor: Run our DJL deep learning model from a zoo
- PutSlack: Put DJL results in a text window in slack
- PostSlack: Send our DJL altered image to slack
- Funnel: Send all failures to Valhalla
If we example the provenance, we can see how long it took to run and some other interesting attributes.
We place the results of our image analysis in attributes while we return a new image that has a bounding box on the found object(s).
We now a full classification workflow for real-time deep learning analysis on images, could be used for Santa watching, Security, Memes and other important business purposes.
The initial release is available here: https://github.com/tspannhw/nifi-djl-processor/releases/tag/v1.0
Using library and example code from the Deep Java Library (https://djl.ai/).
Source Code: https://github.com/tspannhw/nifi-djl-processor/
Exploring Apache NiFi 1.10: Parameters and Stateless Engine
Opinions expressed by DZone contributors are their own.
MLOps: Definition, Importance, and Implementation
Tomorrow’s Cloud Today: Unpacking the Future of Cloud Computing
Integrating AWS With Salesforce Using Terraform