TensorFlowSharp icon indicating copy to clipboard operation
TensorFlowSharp copied to clipboard

How to load PB file saved by Keras model ?

Open thefillture opened this issue 3 years ago • 1 comments

Hi , I had recently trained a model using Keras. I was able to save the model using model.save(location). The generated files are assets, variables, keras.metadata.pb , saved_model.pb . How do I load these model data into tensorflowsharp?

Thanks.

thefillture avatar Mar 30 '22 04:03 thefillture

string imgModelPath = System.IO.Path.Combine(assemblyDirectory, "models\\img\\" + "saved_model.pb");

// Load Image AI
await Task.Run(() => ImgAI.StartAI(imgModelPath));
private static TFGraph graph;

public static async Task StartAI(string modelPath)
{
    try
    {
        // Load the pre-trained model
        graph = new TFGraph();
        graph.Import(File.ReadAllBytes(modelPath));
    }
    catch (Exception ex)
    {
        // Handle the exception (log, display a message, etc.)
        MessageBox.Show($"Exception: {ex.Message}");
    }
}

lexyleinchen avatar Dec 15 '23 11:12 lexyleinchen