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

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

Did you know that 50- 80% of your enterprise business processes can be automated with AssistEdge?  Identify processes, deploy bots and scale effortlessly with AssistEdge.

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] 127.0.0.1 - - [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] 127.0.0.1 - - [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

/opt/demo/curl.sh
curl -X POST http://127.0.0.1:9998/SSD/predict -F "data=@$1" 2>/dev/null

/opt/demo/curl2.sh
curl -X POST http://127.0.0.1:9999/squeezenet/predict -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.

Consuming AI in byte sized applications is the best way to transform digitally. #BuiltOnAI, EdgeVerve’s business application, provides you with everything you need to plug & play AI into your enterprise.  Learn more.

Topics:
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 }}