Community Articles

Find and share helpful community-sourced technical articles.
Announcements
Celebrating as our community reaches 100,000 members! Thank you!
Labels (1)
avatar
Master Guru

Integrating Darknet YOLOv3 Into Apache NiFi Workflows

Darknet has released a new version of YOLO, version 3. This one is a 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

72828-yolov3flow1.png

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

We also want to process the images produced by YOLOv3.

72829-yoloflow2.png

We grab the newest ones from the output directory. I also add meta data 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. The image file we can store in the cloud, another file system, send to a front end or 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 or MQTT or Apache Kafka for further display in an application or dashboard.

72831-parsedyolo.png

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

This is the output that we parse with Apache NiFi

72832-yolooutput.png

YOLOv3 also generates an image with rectangles and labels.

72833-predictions20180514150625.png

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 sends it to Darknet's build of YOLOv3 and send 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 /Volumes/seagate/StrataNYC2018/kafka.jpg


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

Reference:

See: https://github.com/pjreddie/darknet See: https://pjreddie.com/darknet/yolo/

Download the training weights and data (https://pjreddie.com/media/files/yolov3.weights)

See: https://pjreddie.com/media/files/papers/YOLOv3.pd

@article{yolov3, title={YOLOv3: An Incremental Improvement}, author={Redmon, Joseph and Farhadi, Ali}, journal = {arXiv}, year={2018} }

2,537 Views