Monday, 16 January 2017

How to extract images that are generated by Azure Machine Learning Studio

Motivation for this post

Azure Machine Learning Studio from Microsoft can be used to easily build your data science solutions component by component. One of the major benefits is that in each component you can easily add in some visualizations. When you are satisfied with your data solution you can build a web service from this solution. In this blog post I will show you how you also can extract the visualizations from this web service so that you don't lose the visualizations when you are automating your data science solution.

Building the ML Experiment

We will build a simple experiment in Azure ML that imports a data file. Next, the input is connected to an R Module. The main goal of this R module is to draw a graph with a bar chart.

To see this graph chart you can right click on the right dot of the module and select visualize.

In the resulting window under the title Graphics you see the image that you want to extract under the graphics title. This will be an example graph that we want to extract in an automated way.

Building the Web service

Next, we will build the web service that corresponds to this experiment. For this web service we need an input and an output. With the input we can read in a blob storage file and the output we are going to connect with the right dot from the R module. This is the one that you also used to generate the visualization. By making this the output we are going to save the content of the window that we visualized in the previous paragraph in a blob storage file. 

So the major two tasks that are still left for us are to execute the web service to generate the output blob and next to parse this output blob storage file. The web service will be generated in a way similar to the way that you you normally generate a web service from Azure ML. We will describe these steps further in an upcoming blog post. 

Executing the Web service

We will execute the web service in the same way that we normally execute a web service generated from Azure ML. The major difference will now be on how we will parse the output file. We will only be focussing on the latter part. First we read in this file and print it's contents to the console to have a better idea of what the file looks like.

We see that this file starts with R Output JSON, we recognize some JSON formatting and we also see a larger part of text written in random letters and numbers following each other. This part is actually the image represented in PNG encoding in this JSON file.

Based on this analysis we know that we need to perform the following tasks to extract this picture. 

1. Find the location of the first "{
2. Extract the JSON text from the file
3. Parse the result as a JSON object
3. Loop over the sections in the JSON object and locate the section that has graphic as title
4. Decode the resulting values for the image as a PNG and write to a file
5. Open the file that you have saved and admire your work.

The code that you need for this you can find in the picture below.

Resulting graph

Below you can find the extracted images from the web service. If you want to use this image directly in html you actually don't need to execute this extra step. 


In this post I explained how you can extract images that are generated in Azure Machine Learning Studio. This is a step that might help you out in speeding up your data science prototypes. 


  1. Thanks for helping us understand this topic. You have written it in a way that makes it very simple to understand. Thank you so much.

    BIM documentation in USA

  2. Project Management
    I am impressed with your work and skill.Fabulous outfit.Thank you so much.Good job. Keep posting

  3. Excellent Blog. I really want to admire the quality of this post. I like the way of your presentation of ideas, views and valuable content. No doubt you are doing great work. I’ll be waiting for your next post. Thanks .Keep it up!
    Kindly visit us @
    Luxury Boxes
    Premium Packaging
    Luxury Candles Box
    Earphone Packaging Box
    Wireless Headphone Box
    Innovative Packaging Boxes
    Wedding gift box
    Leather Bag Packaging Box
    Cosmetics Packaging Box
    Luxury Chocolate Boxes

  4. Hello Admin!

    Thanks for the post. It was very interesting and meaningful. I really appreciate it! Keep updating stuffs like this. If you are looking for the Advertising Agency in Chennai | Printing in Chennai , Visit Inoventic Creative Agency Today..

  5. Hey!

    DigiPeek is the best SEO & Link Building Service Provider In The World. I have 7+ Years Experience To Build SEO, Backlinks & Improve Website Ranking.

    If you need Profile Backlinks, Forum Backlinks, Dofollow Backlinks, Manual Backlinks, Trusted SEO Backlinks, Increase Domain Rating Then You Will Contact Me.

    I am glad to help You!

    Let's TRY!