can someone give me a hint on how I can load a model, trained and exported in python with keras, with the C++ API of tensorflow 2.0?
I can't find information about that, only with tensorflow version < 2.
Kind regards
Using pre-trained TensorFlow Lite models lets you add machine learning functionality to your mobile and edge device application quickly, without having to build and train a model. This guide helps you find and decide on trained models for use with TensorFlow Lite.
Simply put, a pre-trained model is a model created by some one else to solve a similar problem. Instead of building a model from scratch to solve a similar problem, you use the model trained on other problem as a starting point. For example, if you want to build a self learning car.
Using pre-trained TensorFlow Lite models lets you add machine learning functionality to your mobile and edge device application quickly, without having to build and train a model. This guide helps you find and decide on trained models for use with TensorFlow Lite.
There are a variety of already trained, open source models you can use immediately with TensorFlow Lite to accomplish many machine learning tasks. Using pre-trained TensorFlow Lite models lets you add machine learning functionality to your mobile and edge device application quickly, without having to build and train a model.
Build the simplest model using Python & Tensorflow and export it to tf model that can be read by C API Build a simple C code and compile it with gccand run it like a normal executable file. So here we go, 1. Getting the Tensorflow C API As far as I know, there are 2 ways to get the C API header.
There are different ways to save TensorFlow models depending on the API you're using. This guide uses tf.keras, a high-level API to build and train models in TensorFlow. For other approaches see the TensorFlow Save and Restore guide or Saving in eager. To demonstrate how to save and load weights, you'll use the MNIST dataset.
Ok I found a solution nut with other problems:
In Python you have to export it with:
tf.keras.models.save_model(model, 'model')
In C++ you have to load it with:
tensorflow::SavedModelBundle model;
tensorflow::Status status = tensorflow::LoadSavedModel(
tensorflow::SessionOptions(),
tensorflow::RunOptions(),
"path/to/model/folder",
{tensorflow::kSavedModelTagServe},
&model);
Based on this post: Using Tensorflow checkpoint to restore model in C++
If I now try to set inputs and outputs it throws an error: "Could not find node with name 'outputlayer'" and "Invalid argument: Tensor input:0, specified in either feed_devices or fetch_devices was not in the Graph".
Does anybody has an idea whats wrong here?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With