本文介绍了Tensorflow:.ckpt 文件和 .ckpt.meta 和 .ckpt.index 和 .pb 文件的关系是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用saver=tf.train.Saver()来保存我训练的模型,我得到了三种文件,命名为:

I used saver=tf.train.Saver() to save the model that I trained, and I get three kinds of files named:

  • .ckpt.meta
  • .ckpt.index
  • .ckpt.data

还有一个名为:

  • 检查站

.ckpt 文件有什么联系?

我看到有人保存的模型只有 .ckpt 文件,我不知道如何制作.如何将模型保存为 .pb 文件?

I saw someone saved model with only .ckpt file, I don't know how to make it. How can I save model as a .pb file?

推荐答案

  • .ckpt 文件是 saver.save(sess) 的旧版本输出,相当于你的 .ckpt-data(见下文)

    • the .ckpt file is the old version output of saver.save(sess), which is the equivalent of your .ckpt-data (see below)

      checkpoint"文件只是为了告诉一些TF函数哪个是最新的checkpoint文件.

      the "checkpoint" file is only here to tell some TF functions which is the latest checkpoint file.

      .ckpt-meta 包含元图,即计算图的结构,没有变量的值(基本上是你可以在张量板/图中看到的).

      .ckpt-meta contains the metagraph, i.e. the structure of your computation graph, without the values of the variables (basically what you can see in tensorboard/graph).

      .ckpt-data 包含所有变量的值,没有结构.要在 python 中恢复模型,您通常会使用元文件和数据文件(但您也可以使用 .pb 文件):

      .ckpt-data contains the values for all the variables, without the structure. To restore a model in python, you'll usually use the meta and data files with (but you can also use the .pb file):

      saver = tf.train.import_meta_graph(path_to_ckpt_meta)
      saver.restore(sess, path_to_ckpt_data)
      

    • 我不确切知道 .ckpt-index,我猜它是内部需要的某种索引来正确映射前两个文件.无论如何它通常不是真的需要,您可以仅使用.ckpt-meta.ckpt-data来恢复模型.

    • I don't know exactly for .ckpt-index, I guess it's some kind of index needed internally to map the two previous files correctly. Anyway it's not really necessary usually, you can restore a model with only .ckpt-meta and .ckpt-data.

      .pb 文件可以保存您的整个图形(元 + 数据).要在 C++ 中加载和使用(但不训练)图形,您通常会使用它,使用 freeze_graph,它根据元数据和数据创建 .pb 文件.请注意,(至少在以前的 TF 版本和某些人中)freeze_graph 提供的 py 函数无法正常工作,因此您必须使用脚本版本.Tensorflow 还提供了一个 tf.train.Saver.to_proto() 方法,但我不知道它到底是做什么的.

      the .pb file can save your whole graph (meta + data). To load and use (but not train) a graph in c++ you'll usually use it, created with freeze_graph, which creates the .pb file from the meta and data. Be careful, (at least in previous TF versions and for some people) the py function provided by freeze_graph did not work properly, so you'd have to use the script version. Tensorflow also provides a tf.train.Saver.to_proto() method, but I don't know what it does exactly.

      这里有很多关于如何保存和恢复图表的问题.例如,请参阅此处的答案,但请注意,所引用的两个教程虽然确实很有帮助,但远非完美,并且很多人似乎仍然难以在 C++ 中导入模型.

      There are a lot of questions here about how to save and restore a graph. See the answer here for instance, but be careful that the two cited tutorials, though really helpful, are far from perfect, and a lot of people still seem to struggle to import a model in c++.

      编辑:它看起来像你现在也可以在 c++ 中使用 .ckpt 文件, 所以我猜你不一定需要 .不再需要 pb 文件了.

      EDIT:it looks like you can also use the .ckpt files in c++ now, so I guess you don't necessarily need the .pb file any more.

      这篇关于Tensorflow:.ckpt 文件和 .ckpt.meta 和 .ckpt.index 和 .pb 文件的关系是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 21:24