Posting Images With Apache NiFi 1.7 and a Custom Processor
In this article, we go over how to post images to an Apache MXNet model server in order to work with deep learning classification.
Join the DZone community and get the full member experience.
Join For FreePosting Images With Apache NiFi 1.7 and a Custom Processor
I have been using a shell script for this since Apache NiFi did not have a good way to natively post an image to HTTP servers, such as the model server for Apache MXNet.
So I wrote a quick and dirty processor that posts an image there and gathers the headers, result body, status text, and status code and returns them to you as attributes.
In this example, I am downloading images from the picsum.photos free photo service.
To use this new processor, download it to your lib directory and restart Apache NiFi, then you can add the PostImageProcessor.
Eclipse for Building My Processor
Configure the Post Image Processor With Your URL, fieldname, imagename, and imagetype.
MXNet Model Server Results
The Attribute Results From the Data
Results
Example Results
post.header
{Server=[Werkzeug/0.14.1 Python/3.6.6], Access-Control-Allow-Origin=[*],
Content-Length=[396], Date=[Fri, 05 Oct 2018 17:47:22 GMT],
Content-Type=[application/json]}
post.results
{"prediction":[[{"probability":0.24173378944396973,
"class":"n02281406 sulphur butterfly, sulfur butterfly"},
{"probability":0.19173663854599,"class":"n02190166 fly"},
{"probability":0.052654966711997986,
"class":"n02280649 cabbage butterfly"},
{"probability":0.05147545784711838,
"class":"n03485794 handkerchief, hankie, hanky, hankey"},
{"probability":0.048753462731838226,"class":"n02834397 bib"}]]} post.status OK post.statuscode 200
Results from HTTP Posting an Image to MXNet Model Server
[INFO 2018-10-05 13:47:22,217 PID:88561 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mms/serving_frontend.py:predict_callback:467] Request input: data should be image with jpeg format. [INFO 2018-10-05 13:47:22,218 PID:88561 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mms/request_handler/flask_handler.py:get_file_data:137] Getting file data from request. [INFO 2018-10-05 13:47:22,262 PID:88561 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mms/serving_frontend.py:predict_callback:510] Response is text. [INFO 2018-10-05 13:47:22,262 PID:88561 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mms/request_handler/flask_handler.py:jsonify:159] Jsonifying the response: {'prediction': [[{'probability': 0.24173378944396973, 'class': 'n02281406 sulphur butterfly, sulfur butterfly'}, {'probability': 0.19173663854599, 'class': 'n02190166 fly'}, {'probability': 0.052654966711997986, 'class': 'n02280649 cabbage butterfly'}, {'probability': 0.05147545784711838, 'class': 'n03485794 handkerchief, hankie, hanky, hankey'}, {'probability': 0.048753462731838226, 'class': 'n02834397 bib'}]]} [INFO 2018-10-05 13:47:22,263 PID:88561 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/_internal.py:_log:88] 127.0.0.1 - - [05/Oct/2018 13:47:22] "POST /squeezenet/predict HTTP/1.1" 200 -
Example HTTP Server
https://github.com/awslabs/mxnet-model-server
Source Code For Processor
https://github.com/tspannhw/nifi-postimage-processor
Pre-Built NAR To Install
https://github.com/tspannhw/nifi-postimage-processor/releases/tag/1.0
Opinions expressed by DZone contributors are their own.
Trending
-
What Is Istio Service Mesh?
-
Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
-
Auditing Tools for Kubernetes
-
Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
Comments