Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load PB file saved by Keras model ? #500

Open
thefillture opened this issue Mar 30, 2022 · 1 comment
Open

How to load PB file saved by Keras model ? #500

thefillture opened this issue Mar 30, 2022 · 1 comment

Comments

@thefillture
Copy link

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.

@lexylein
Copy link

lexylein commented Dec 15, 2023

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}");
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants