Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Integrating Apache NiFi with YOLOv3

DZone's Guide to

Integrating Apache NiFi with YOLOv3

Read on in order to learn how to use Apache NiFi to interact with a live webcam and run YOLOv3 original Darknet implementation.

· Integration Zone ·
Free Resource

The State of API Integration 2018: Get Cloud Elements’ report for the most comprehensive breakdown of the API integration industry’s past, present, and future.

Integrating Darknet YOLOv3 Into Apache NiFi Workflows

Darknet has released a new version of YOLO, version 3. This one is faster and perhaps more accurate. It's new and shiny, and I had to try it. I am liking the results.

Flow to Execute Script

We call the shell script, then I route out the empty results. I use SplitText to split into individual lines. I use ExtractText with ([^:]+):(.*) to split into our name, value pairs.

We also want to process the images produced by YOLOv3.

We grab the newest ones from the output directory. I also add metadata extraction and Tensorflow analysis. This data is stored in attributes and can be saved independently via using AttributesToJSON to build a new flow file that we save off separate probably converting into Apache ORC and storing in HDFS for Apache Hive querying. We can store the image file in the cloud, another file system, send to a front end, save in HDFS, or even email it to someone.

The parsed YOLOv3 results in Apache NiFi Attributes. As you can see, we would grab labelvalue.1 and labelvalue.2 to do our processing. We may want to send this to JMS, MQTT, or Apache Kafka for further display in an application or dashboard.

This is an example of the result of our Extract Text:

This is the output that we parse with Apache NiFi:

YOLOv3 also generates an image with rectangles and labels:

YOLOv3 does some great classification on multiple items in a picture. I use Python to capture an image from my webcam via OpenCV2. I wrap my call in a shell script that captures the image and sends it to Darknet's build of YOLOv3 and sends errors to /dev/null.

If you have a good GPU, you can compile with CUDA and OpenCV to do real-time off a webcam.

Example Output:

/Volumes/seagate/models/darknet-master/images/yolo_image_img_20180514183707.jpg: Predicted in 26.351510 seconds.
cell phone: 72%
chair: 78%
chair: 72%
chair: 59%
person: 100%
chair: 83%

Example Run:

./darknet detect cfg/yolov3.cfg cfg/yolov3.weights kafka.jpg

Source: https://github.com/tspannhw/nifi-yolo3

https://pjreddie.com/media/files/papers/YOLOv3.pdf

Your API is not enough. Learn why (and how) leading SaaS providers are turning their products into platforms with API integration in the ebook, Build Platforms, Not Products from Cloud Elements.

Topics:
deep learning ,python ,yolov3 ,apache nifi ,hortonworks ,integration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}