当前位置: 首页 > news >正文

TensorFlow 生成 .ckpt 和 .pb

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.

1 Answer

active oldest votes

up vote
down voteaccepted

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 a the 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.

share improve this answer
 
  
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

转载于:https://www.cnblogs.com/nowornever-L/p/6991295.html

相关文章:

  • salesforce 简单的PDF报价单打印
  • 1.8 Oracle 登陆时报错信息:无监听程序 我的程序猿之路:第八章
  • [BZOJ 2142]礼物(扩展Lucas定理)
  • iOS UISlider的使用
  • CSS 各种形状
  • 用php 生成 excel 表格
  • .Net 路由处理厉害了
  • mybatis中批量插入以及更新
  • robots.txt的语法和写法详解
  • STL 标准模板库
  • Servlet 详解
  • I/O流
  • 菜鸟学习Redis(二)——Redis集群
  • 行为模式--代理Proxy模式(Java)
  • python 类的特殊成员
  • Docker下部署自己的LNMP工作环境
  • emacs初体验
  • GitUp, 你不可错过的秀外慧中的git工具
  • Netty 4.1 源代码学习:线程模型
  • Octave 入门
  • passportjs 源码分析
  • php中curl和soap方式请求服务超时问题
  • Python打包系统简单入门
  • Python连接Oracle
  • spring + angular 实现导出excel
  • 测试如何在敏捷团队中工作?
  • 工作中总结前端开发流程--vue项目
  • 试着探索高并发下的系统架构面貌
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • 小程序开发中的那些坑
  • 一些关于Rust在2019年的思考
  • 赢得Docker挑战最佳实践
  • (2021|NIPS,扩散,无条件分数估计,条件分数估计)无分类器引导扩散
  • (4)事件处理——(2)在页面加载的时候执行任务(Performing tasks on page load)...
  • (6)STL算法之转换
  • (cos^2 X)的定积分,求积分 ∫sin^2(x) dx
  • (done) 两个矩阵 “相似” 是什么意思?
  • (安全基本功)磁盘MBR,分区表,活动分区,引导扇区。。。详解与区别
  • (附程序)AD采集中的10种经典软件滤波程序优缺点分析
  • (四)【Jmeter】 JMeter的界面布局与组件概述
  • (算法)Game
  • (原創) 如何刪除Windows Live Writer留在本機的文章? (Web) (Windows Live Writer)
  • (转)IIS6 ASP 0251超过响应缓冲区限制错误的解决方法
  • (转)Java socket中关闭IO流后,发生什么事?(以关闭输出流为例) .
  • (转)Oracle存储过程编写经验和优化措施
  • (转)菜鸟学数据库(三)——存储过程
  • (转载)Google Chrome调试JS
  • .jks文件(JAVA KeyStore)
  • .NET 程序如何获取图片的宽高(框架自带多种方法的不同性能)
  • .net 验证控件和javaScript的冲突问题
  • .NET 应用架构指导 V2 学习笔记(一) 软件架构的关键原则
  • .net用HTML开发怎么调试,如何使用ASP.NET MVC在调试中查看控制器生成的html?
  • :中兴通讯为何成功
  • @configuration注解_2w字长文给你讲透了配置类为什么要添加 @Configuration注解
  • @kafkalistener消费不到消息_消息队列对战之RabbitMq 大战 kafka