TensorFlowSharp
TensorFlowSharp copied to clipboard
How to load PB file saved by Keras model ?
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.
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}");
}
}