#StackBounty: #python #.net #tensorflow #nodes #ml.net Correct pb file to move Tensorflow model into ML.NET

Bounty: 100

I have a TensorFlow model that I built (a 1D CNN that I would now like to implement into .NET). In order to do so I need to know the Input and Output nodes. When I uploaded the model on Netron I get a different graph depending on my save method and the only one that looks correct comes from an h5 upload. Here is the model.summary():

enter image description here

If I save the model as an h5 model.save("Mn_pb_model.h5") and load that into the Netron to graph it, everything looks correct:

enter image description here

However, ML.NET will not accept h5 format so it needs to be saved as a pb. In looking through samples of adopting TensorFlow in ML.NET, this sample shows a TensorFlow model that is saved in a similar format to the SavedModel format – recommended by TensorFlow (and also recommended by ML.NET here "Download an unfrozen [SavedModel format] …"). However when saving and loading the pb file into Netron I get this:

enter image description here

And zoomed in a little further (on the far right side),

enter image description here

As you can see, it looks nothing like it should. Additionally the input nodes and output nodes are not correct so it will not work for ML.NET (and I think something is wrong). I am using the recommended way from TensorFlow to determine the Input / Output nodes:

enter image description here

When I try to obtain a frozen graph and load it into Netron, at first it looks correct, but I don’t think that it is:

enter image description here

There are four reasons I do not think this is correct. 1) it is very different from the graph when it was uploaded as an h5 (which looks correct to me). 2) as you can see from earlier, I am using 1D convolutions throughout and this is showing that it goes to 2D (and remains that way). 3) this file size is 128MB whereas the one in the TensorFlow to ML.NET example is only 252KB. Even the Inception model is only 56MB. 4) if I load the Inception model in TensorFlow and save it as an h5, it looks the same as from the ML.NET resource, yet when I save it as a frozen graph it looks different. If I take the same model and save it in the recommended SavedModel format, it shows up all messed up in Netron. Take any model you want and save it in the recommended SavedModel format and you will see for yourself (I’ve tried it on a lot of different models).

Additionally in looking at the model.summary() of Inception with it’s graph, it is similar to its graph in the same way my model.summary() is to the h5 graph. It seems like there should be an easier way (and a correct way) to save a TensorFlow model so it can be used in ML.NET.


Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.