原文:https://www.cnblogs.com/nowornever-L/p/6991295.html

1. TensorFlow  生成的  .ckpt 和  .pb 都有什么用?

The .ckpt is the model given by tensorflow which includes all the
weights/parameters in the model. The .pb file stores the computational
graph. To make tensorflow work we need both the graph and the
parameters. There are two ways to get the graph:
(1) use the python program that builds it in the first place (tensorflowNetworkFunctions.py).
(2) Use a .pb file (which would have to be generated by tensorflowNetworkFunctions.py). .ckpt file is were all the intelligence is.

2. TensorFlow saving into/loading a graph from a file

正好看到 StackOverflow 上有位仁兄问过相关的问题,整理的不错

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

From what I've gathered so far, there are several different ways of dumping a TensorFlow graph
into a file and then loading it into another program, but I haven't been able to find clear examples/information on how they work. What I already know is this:

  1. Save the model's variables into a checkpoint file (.ckpt) using a tf.train.Saver() and restore them later (source)
  2. Save a model into a .pb file and load it back in using tf.import_graph_def() (source)
  3. Load in a model from a .pb file, retrain it, and dump it into a new .pb file using Bazel (source)
  4. Freeze the graph to save the graph and weights together (source)
  5. Use as_graph_def() to save the model, and for weights/variables, map them into constants (source)

However, I haven't been able to clear up several questions regarding these different methods:

  1. Regarding checkpoint files, do they only save the trained weights of a model? Could checkpoint files be loaded into a new program, and be used to run the model, or do they simply serve as ways to save the weights in a model at a certain time/stage?
  2. Regarding Regarding
    Bazel, can it only save into/load from .pb files for retraining? Is
    there a simple Bazel command just to dump a graph into a .pb?
  3. Regarding freezing, can a frozen graph be loaded in using The
    Android demo for TensorFlow loads in Google's Inception model from a
    .pb file. If I wanted to substitute my own .pb file, how would I go
    about doing that? Would I need to change
    any native code/methods?
  4. In general, what exactly is the difference between all these methods? Or more broadly, what is the difference between 
    In short, what I'm looking for is a method to save both a graph (as in,
    the various operations and such) and its weights/variables into a file,
    which can then be used to load the graph and weights into another
    program, for use (not necessarily continuing/retraining).

    Documentation about this topic isn't very straightforward, so any answers/information would be greatly appreciated.

 


There are many ways to approach the problem of saving a model in TensorFlow, which can make it a bit confusing. The documentation on this topic is taking shape, but doesn't cover all of the details in your question. Taking each of your sub-questions in turn:

  1. The checkpoint files (produced e.g. by calling saver.save() on a tf.train.Saver object) contain only the weights, and any other variables defined in the same program. To use them in another program, you must re-create the associated graph structure (e.g. by running code to build it again, or calling saver.save() also produces a file containing athe
    tutorial
     for more details.


  2. tf.train.write_graph() only writes the graph structure; not the weights.

  3. Bazel is unrelated to reading or writing TensorFlow graphs. (Perhaps I misunderstand your question: feel free to clarify it in a comment.)

  4. A frozen graph can be loaded using


    The main change would be to update the names of the tensor(s) that are
    fed into the model, and the names of the tensor(s) that are fetched from
    the model. In the TensorFlow
    Android demo, this would correspond to the outputName strings
    that are passed to 


    The GraphDef is
    the program structure, which typically does not change through the
    training process. The checkpoint is a snapshot of the state of a
    training process, which typically changes at every step of the training
    process. As a result, TensorFlow uses different storage
    formats for these types of data, and the low-level API provides
    different ways to save and load them. Higher-level libraries, such as
    the 
    Keras,
    and skflow build on these mechanisms to provide
    more convenient ways to save and restore an entire model.


answered Aug 15 at 6:07
mrry

28.6k35999
 
   
Does this mean that the C++ API documentation lies, when it says that you can load the graph saved withtf.train.write_graph() and then execute it? – mnicky yesterday 
   
The C++ API documentation does not lie, but it is missing a few details. The most important detail is that, in addition to the GraphDef saved by mrry yesterday

TensorFlow 生成 .ckpt 和 .pb的更多相关文章

  1. tensorflow模型ckpt转pb以及其遇到的问题

    使用tensorflow训练模型,ckpt作为tensorflow训练生成的模型,可以在tensorflow内部使用.但是如果想要永久保存,最好将其导出成pb的形式. tensorflow已经准备好c ...

  2. tensorflow学习笔记——模型持久化的原理,将CKPT转为pb文件,使用pb模型预测

    由题目就可以看出,本节内容分为三部分,第一部分就是如何将训练好的模型持久化,并学习模型持久化的原理,第二部分就是如何将CKPT转化为pb文件,第三部分就是如何使用pb模型进行预测. 一,模型持久化 为 ...

  3. tensorflow实战笔记(19)----使用freeze_graph.py将ckpt转为pb文件

    一.作用: https://blog.csdn.net/yjl9122/article/details/78341689 这节是关于tensorflow的Freezing,字面意思是冷冻,可理解为整合 ...

  4. tensorflow 模型前向传播 保存ckpt tensorbard查看 ckpt转pb pb 转snpe dlc 实例

    参考: TensorFlow 自定义模型导出:将 .ckpt 格式转化为 .pb 格式 TensorFlow 模型保存与恢复 snpe tensorflow 模型前向传播 保存ckpt  tensor ...

  5. Tensorflow生成唐诗和歌词(下)

    整个工程使用的是Windows版pyCharm和tensorflow. 源码地址:https://github.com/Irvinglove/tensorflow_poems/tree/master ...

  6. Tensorflow生成唐诗和歌词(上)

    整个工程使用的是Windows版pyCharm和tensorflow. 源码地址:https://github.com/Irvinglove/tensorflow_poems/tree/master ...

  7. 3. Tensorflow生成TFRecord

    1. Tensorflow高效流水线Pipeline 2. Tensorflow的数据处理中的Dataset和Iterator 3. Tensorflow生成TFRecord 4. Tensorflo ...

  8. tensorflow模型的保存与恢复,以及ckpt到pb的转化

    转自 https://www.cnblogs.com/zerotoinfinity/p/10242849.html 一.模型的保存 使用tensorflow训练模型的过程中,需要适时对模型进行保存,以 ...

  9. tensorflow 三种模型:ckpt、pb、pb-savemodel

    1.CKPT 目录结构 checkpoint: model.ckpt-1000.index model.ckpt-1000.data-00000-of-00001 model.ckpt-1000.me ...

随机推荐

  1. model.addattribute()的作用

    1.往前台传数据,可以传对象,可以传List,通过el表达式 ${}可以获取到, 类似于request.setAttribute("sts",sts)效果一样. 2.@ModelA ...

  2. 如何使用js判断当前页面是pc还是移动端打开的

    1.利用了正则表达式和三目运算符,含义就是如果是移动端打开的话那就跳转到 "https:www.baidu.com/" ,如果不是就跳转到"http://new.baid ...

  3. C++ 执行 cmd 命令 删除文件 删除注册表项

    #include <Windows.h> WinExec("cmd /C \"del C:\\Windows\\secretWin.ini\"",S ...

  4. Mod制作第一个物品

    在通过Mod制作第一个物品时需要 一下几个步骤: 创建一个物品 通常在创建这个物品类的时候会继承Item或者是Block父类(因为Mod中的物品都是这个两个类的子类),在给类中使用了this.setU ...

  5. ueditor上传图片配置成功,但是如何删除无用的图片

    我使用ueditor作为富文本编辑器,配置已经好了,上传功能也好了.现在的问题是当使用ueditor上传图片的时候,选择了图片就立刻上传到指定的文件夹里,而后续即使没有保存该篇文章内容,即取消操作,图 ...

  6. jQuery筛选--first()和last()

       first() 概述 获取匹配的第一个元素    last() 概述 获取匹配的最后个元素 <!DOCTYPE html> <html> <head> < ...

  7. pymysql 数据库操控

    模块安装 pip install pymysql 执行sql语句 import pymysql #添加数据 conn = pymysql.connect(host='127.0.0.1', port= ...

  8. kali长时间未使用导致数字签名过期无法更新源解决办法

    kali长时间未使用,数字签名会过期,从而导致无法更新源. apt-get update:从源(Source)服务器那里下载最新的软件包列: apt-get upgrade:对已经安装的软件包本身进行 ...

  9. nodejs核心技术

    一.知识结构: http模块:配置简单 的web服务,npm/cnpm工具 express框架:express中间件进行服务配置:路由:请求处理: DB服务:学习使用mysql关系型数据库: web接 ...

  10. json.dumps(),json.loads(),json.dump(),json.load()方法的区别

    1. json.dumps() json.dump()是将字典类型转化成字符串类型. import json dic = {'a':'1111','b':'2222','c':'3333','d':' ...