TensorFlow 0.12模型文件 [英] TensorFlow 0.12 Model Files

查看:98
本文介绍了TensorFlow 0.12模型文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我训练模型并使用:

saver = tf.train.Saver()
saver.save(session, './my_model_name')

除了 checkpoint 文件(该文件仅包含指向模型的最新检查点的指针)之外,这还会在当前路径中创建以下3个文件:

Besides the checkpoint file, which simply contains pointers to the most recent checkpoints of the model, this creates the following 3 files in the current path:

  1. my_model_name.meta
  2. my_model_name.index
  3. my_model_name.data-00000-of-00001
  1. my_model_name.meta
  2. my_model_name.index
  3. my_model_name.data-00000-of-00001

我想知道每个文件都包含什么.

I wonder what each of these files contains.

我想在C ++中加载此模型并运行推理. label_image 示例从单个加载模型.bp 文件,使用ReadBinaryProto().我想知道如何从这3个文件中加载它.下面的C ++等效项是什么?

I'd like to load this model in C++ and run the inference. The label_image example loads the model from a single .bp file using ReadBinaryProto(). I wonder how I can load it from these 3 files. What is the C++ equivalent of the following?

new_saver = tf.train.import_meta_graph('./my_model_name.meta')
new_saver.restore(session, './my_model_name')

推荐答案

我目前正在为此苦苦挣扎,我发现目前做起来不是很简单.关于该主题的两个最常引用的教程是: https://medium .com/jim-fleming/loading-a-tensorflow-graph-with-the-c-api-4caaff88463f#.goxwm1e5j https://medium.com/@hamedmp/exporting-trained-tensorflow-models-c-the-right-way-cf24b609d183#.g1gak956i

I'm currently struggling with this myself, I've found it's not very straightforward to do currently. The two most commonly cited tutorials on the subject are: https://medium.com/jim-fleming/loading-a-tensorflow-graph-with-the-c-api-4caaff88463f#.goxwm1e5j and https://medium.com/@hamedmp/exporting-trained-tensorflow-models-to-c-the-right-way-cf24b609d183#.g1gak956i

相当于

new_saver = tf.train.import_meta_graph('./my_model_name.meta')
new_saver.restore(session, './my_model_name')

就是

Status load_graph_status = LoadGraph(graph_path, &session);

假设您已经冻结了图形"(使用了一个脚本,将图形文件与检查点值结合在一起). 另外,请参见此处的讨论: Tensorflow不同的导出方式并在C ++中运行图

Assuming you've "frozen the graph" (Used a script with combines the graph file with the checkpoint values). Also, see the discussion here: Tensorflow Different ways to Export and Run graph in C++

这篇关于TensorFlow 0.12模型文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆