TensorFlow 2.0 C++ - 加载预训练模型

pra*_*777 7 c++ python load keras tensorflow2.0

有人可以给我一个关于如何使用 tensorflow 2.0 的 C++ API 加载模型、使用 keras 在 python 中训练和导出的提示吗?

我找不到相关信息,只有 tensorflow 版本 < 2。

亲切的问候

pra*_*777 5

好吧,我找到了解决其他问题的方法:

在 Python 中,你必须使用以下命令导出它:

tf.keras.models.save_model(model, 'model')
Run Code Online (Sandbox Code Playgroud)

在 C++ 中,您必须使用以下命令加载它:

tensorflow::SavedModelBundle model;
tensorflow::Status status = tensorflow::LoadSavedModel(
  tensorflow::SessionOptions(), 
  tensorflow::RunOptions(), 
  "path/to/model/folder", 
  {tensorflow::kSavedModelTagServe}, 
  &model);
Run Code Online (Sandbox Code Playgroud)

基于这篇文章:Using Tensorflow checkpoint to Restore model in C++

如果我现在尝试设置输入和输出,则会抛出错误:“无法找到名称为“outputlayer”的节点”和“无效参数:张量输入:0,在 feed_devices 或 fetch_devices 中指定的不在图表中”。

有人知道这里出了什么问题吗?