Over a million developers have joined DZone.

Integrating Apache MXNet Model Server With Apache NiFi: Updated

DZone's Guide to

Integrating Apache MXNet Model Server With Apache NiFi: Updated

Let's take a look at this tutorial that uses Apache MXNet Model Server with Apache NiFi.

· AI Zone ·
Free Resource

Insight for I&O leaders on deploying AIOps platforms to enhance performance monitoring today. Read the Guide.

There have been upgrades to MXNet Model Server, Apache MXNet, as well as to Apache NiFi, so I have upgraded my original demo to support this. Apache MXNet is now in version 1.2.1, while Apache NiFi is in versoin 1.7.1. I am capturing images from PicSum.com, which offers free images, which is awesome. We read that REST API with Apache NiFi and send that file to two different algorithms hosted by MXNet Model Server. One is SqueezeNet 1.1, which is used for Object Classification such as identifying hotdogs, cats, dogs, and muffins. These are important things! SSD is Single Shot Detector, this will find a number of things in your picture. As mentioned in other of my articles you will want to checkout Gluon and ONNX for more options.

Capture images from picsum.com free images and store them in the file system.

Process all the images via TensorFlow Processor, SSD Predict via MMS and SqueezeNet v1.1 via MMS. Three for the price of one, thanks NiFi. With my custom TensorFlow processor, you can add that to any flow that has an image in the FlowFile.

Apache Zeppelin SQL against tblsqueeze11

Example output from Squeeze v1.1

Storing generic data in HDFS via schema

Example SSD data JSON

High level flow from server

Apache NiFi server flows to store

Convert to Apache ORC

Extract attributes

Convert JSON arrays to other

Example data derived from TensorFlow processor

Schemas in schema registry

Create table in Zeppelin

Query table in Zeppelin

Python libraries

git clone https://github.com/awslabs/mxnet-model-server.git

pip install opencv-python  -U
pip install scikit-learn -U
pip install easydict -U
pip install scikit-image -U
pip install numpy -U
pip install mxnet -U

pip3.6 install opencv-python -U
pip3.6 install scikit-learn -U
pip3.6 install easydict -U
pip3.6 install scikit-image -U
pip3.6 install numpy -U
pip3.6 install mxnet -U

Example runs — Squeeze v1.1

mxnet-model-server --models squeezenet=squeezenet_v1.1.model --service mms/model_service/mxnet_vision_service.py --port 9999

[INFO 2018-07-10 16:50:26,840 PID:7730 /usr/local/lib/python3.6/site-packages/mms/request_handler/flask_handler.py:jsonify:159] Jsonifying the response: {'prediction': [[{'probability': 0.3365139067173004, 'class': 'n03710193 mailbox, letter box'}, {'probability': 0.1522996574640274, 'class': 'n03764736 milk can'}, {'probability': 0.08760709315538406, 'class': 'n03000134 chainlink fence'}, {'probability': 0.08103135228157043, 'class': 'n02747177 ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin'}, {'probability': 0.04956872761249542, 'class': 'n02795169 barrel, cask'}]]}
[INFO 2018-07-10 16:50:26,842 PID:7730 /usr/local/lib/python3.6/site-packages/werkzeug/_internal.py:_log:88] - - [10/Jul/2018 16:50:26] "POST /squeezenet/predict HTTP/1.1" 200 -
[INFO 2018-07-10 16:50:46,904 PID:7730 /usr/local/lib/python3.6/site-packages/mms/serving_frontend.py:predict_callback:467] Request input: data should be image with jpeg format.
[INFO 2018-07-10 16:50:46,960 PID:7730 /usr/local/lib/python3.6/site-packages/mms/request_handler/flask_handler.py:get_file_data:137] Getting file data from request.
[INFO 2018-07-10 16:50:47,020 PID:7730 /usr/local/lib/python3.6/site-packages/mms/serving_frontend.py:predict_callback:510] Response is text.
[INFO 2018-07-10 16:50:47,020 PID:7730 /usr/local/lib/python3.6/site-packages/mms/request_handler/flask_handler.py:jsonify:159] Jsonifying the response: {'prediction': [[{'probability': 0.1060439869761467, 'class': 'n02536864 coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch'}, {'probability': 0.06582894921302795, 'class': 'n01930112 nematode, nematode worm, roundworm'}, {'probability': 0.05008145794272423, 'class': 'n01751748 sea snake'}, {'probability': 0.03847070038318634, 'class': 'n01737021 water snake'}, {'probability': 0.03614763543009758, 'class': 'n09229709 bubble'}]]}
[INFO 2018-07-10 16:50:47,021 PID:7730 /usr/local/lib/python3.6/site-packages/werkzeug/_internal.py:_log:88] - - [10/Jul/2018 16:50:47] "POST /squeezenet/predict HTTP/1.1" 200 -

mxnet-model-server --models SSD=resnet50_ssd_model.model --service ssd_service.py --port 9998

Apache MXNet model server Model Zoo

Model Zoo

Connect to MMS

curl -X POST -F "data=@$1" 2>/dev/null

curl -X POST -F "data=@$1" 2>/dev/null

We store all our resulting data in Hive tables and can query them in Zeppelin for creating tables, charts and graphs. We can also connect to these Hive tables via ODBC and JDBC to use other reporting tools or display them with things like Spring Boot.

TrueSight is an AIOps platform, powered by machine learning and analytics, that elevates IT operations to address multi-cloud complexity and the speed of digital transformation.

hortonworks ,hadoop ,apache nifi ,apache mxnet ,deep learning ,mms ,artificial intelligence ,tutorial

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}