tensorFlow 三种启动图的用法
tf.Session(),tf.InteractivesSession(),tf.train.Supervisor().managed_session() 用法的区别:
- tf.Session()
构造阶段完成后, 才能启动图. 启动图的第一步是创建一个 Session 对象, 如果无任何创建参数, 会话构造器将启动默认图.
import tensorflow as tf
matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
preduct = tf.matmul(matrix1, matrix2)
#使用 "with" 代码块来自动完成关闭动作
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print sess.run(preduct)
- tf.InteractivesSession()
为便于使用 IPython之类的 Python 交互环境, 可以使用InteractiveSession 代替 Session 类, 使用 Tensor.eval()和 Operation.run()方法代替Session.run(),这样可以避免使用一个变量来持有会话。
import tensorflow as tf matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.], [2.]])
preduct = tf.matmul(matrix1, matrix2) sess_ = tf.InteractiveSession()
tf.global_variables_initializer().run()
print preduct.eval()
sess_.close()
- tf.train.Supervisor().managed_session()
与上面两种启动图相比较来说,Supervisor() 帮助我们处理一些事情:
(a) 自动去 checkpoint 加载数据或者初始化数据
(b) 自动有一个 Saver ,可以用来保存 checkpoint,eg: sv.saver.save(sess, save_path)
(c) 有一个 summary_computed 用来保存 Summary
因此我们可以省略了以下内容:
(a)手动初始化或者从 checkpoint 中加载数据
(b)不需要创建 Saver 类, 使用 sv 内部的就可以
(c)不需要创建 Summary_Writer()
import tensorflow as tf matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.], [2.]]) preduct = tf.matmul(matrix1, matrix2) sv = tf.train.Supervisor(logdir=None, init_op=tf.global_variables_initializer()) with sv.managed_session() as sess:
print sess.run(preduct)
import tensorflow as tf a = tf.Variable(1)
b = tf.Variable(2)
c = tf.add(a, b) update = tf.assign(a, c) init = tf.global_variables_initializer() sv = tf.train.Supervisor(logdir="./tmp/", init_op=init)
saver = sv.saver
with sv.managed_session() as sess:
for i in range(1000):
update_ = sess.run(update)
#print("11111", update)
if i % 100 == 0:
sv.saver.save(sess, "./tmp/", global_step=i)
tensorFlow 三种启动图的用法的更多相关文章
- spring-boot的三种启动方式[z]
https://blog.csdn.net/u011425751/article/details/79507386 有段时间没有写博客了,也在努力的从传统单机开发向分布式系统过度,所以再次做一些笔记, ...
- spring-boot的三种启动方式
spring-boot的启动方式主要有三种: 1. 运行带有main方法类 2. 通过命令行 java -jar 的方式 3. 通过spring-boot-plugin的方式 一.执行带有main方法 ...
- 【转】STM32三种启动模式
@2018-12-16 [小记] STM32 启动区域 STM32三种启动模式 借助上述文章理解官方文档<一种从用户代码调用系统存储器中 Bootloader 的方法 >
- spring boot快速入门 1 :创建项目、 三种启动项目方式
准备工作: (转载)IDEA新建项目时,没有Spring Initializr选项 最近开始使用IDEA作为开发工具,然后也是打算开始学习使用spring boot. 看着博客来进行操作上手sprin ...
- STM32三种启动模式 boot0 boot1
STM32三种启动模式对应的存储介质均是芯片内置的,它们是: 1)用户闪存=芯片内置的Flash.2)SRAM=芯片内置的RAM区,就是内存啦.3)系统存储器=芯片内部一块特定的区域,芯片出厂时在这个 ...
- Tornado—三种启动tornado的方式
第一种启动方式:单进程 import tornado.web # web服务 import tornado.ioloop # I/O 时间循环 class Mainhandler(tornado.we ...
- tomcat三种启动不同的启动方式
Linux下tomcat服务的启动.关闭与错误跟踪,通常通过以下几种方式启动关闭tomcat服务: 切换到tomcat主目录下的bin目录 1. 启动tomcat服务 方式一:直接启动 ./start ...
- tensorflow 三种模型:ckpt、pb、pb-savemodel
1.CKPT 目录结构 checkpoint: model.ckpt-1000.index model.ckpt-1000.data-00000-of-00001 model.ckpt-1000.me ...
- Redis的三种启动方式
转载:http://www.tuicool.com/articles/aQbQ3u Part I. 直接启动 下载 官网下载 安装 tar zxvf redis-2.8.9.tar.gz cd red ...
随机推荐
- xmtech-3516默认环境变量
xmtech # print bootcmd=setenv setargs setenv bootargs ${bootargs};run setargs;sf probe ;sf read ;squ ...
- node api 之:stream - 流
stream 模块可以通过以下方式使用: const stream = require('stream'); 流可以是可读的.可写的.或者可读可写的. 所有的流都是 EventEmitter 的实例. ...
- hdfs1.0和2.0复习
1.Namenode元数据两种映射:(1)文件名 -> block数据块的映射(2)block数据块 -> datanode节点地址的映射细节:(1)是持久化到NN的磁盘的(fsimage ...
- SoapUI 5.2.1 调试工具
SoapUI 5.2.1 调试工具 1.打开soapUI. 2.新建一个项目,实例如下: 点击ok后在soapUI界面左侧会显示出此项目,如图: 2.创建测试用例: a.新建用例组,选择此项目右键,新 ...
- Azure ARM (15) 根据现有VHD文件,创建ARM VM
<Windows Azure Platform 系列文章目录> 在很多时候,我们需要根据现有VHD文件,创建ARM VM.在这里笔者简单介绍一下相关的Azure PowerShell 这里 ...
- Azure SQL 数据库仓库Data Warehouse (3) DWU
<Windows Azure Platform 系列文章目录> 在笔者的上一篇文章中:Azure SQL 数据库仓库Data Warehouse (2) 架构 介绍了SQL DW的工作节点 ...
- sql Find_IN_SET 用法
字段以 1,2,3,4 格式存储的SELECT * from test where FIND_IN_SET('15',btype) GROUP_CONCAT + group_by
- ALGO-146_蓝桥杯_算法训练_4-2找公倍数
AC代码: #include <stdio.h> int main(void) { int i; ; i <= ; i ++) { == && i% == ) { p ...
- Android adb logcat输出日志显示不全解决方案
在终端中使用adb logcat打印服务器json数据,如果返回数据过大超过4000字节(4K)即会截断不显示 原因:logcat在对于message的内存分配大概是4k左右.所以超过的内容都直接被丢 ...
- 开启Unity3D之旅
圣典知识目录http://game.ceeger.com/Manual/ NGUI http://www.taikr.com/course/34泰课课程 http://tieba.baidu.com/ ...