DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Data
  4. Posting Images With Apache NiFi 1.7 and a Custom Processor

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.

Tim Spann user avatar by
Tim Spann
CORE ·
Oct. 15, 18 · Tutorial
Like (3)
Save
Tweet
Share
5.80K Views

Join the DZone community and get the full member experience.

Join For Free

Posting 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

Apache NiFi

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Using QuestDB to Collect Infrastructure Metrics
  • Public Cloud-to-Cloud Repatriation Trend
  • Last Chance To Take the DZone 2023 DevOps Survey and Win $250! [Closes on 1/25 at 8 AM]
  • The Role of Data Governance in Data Strategy: Part II

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: