x = tf.placeholder(tf.float32)
y = tf.placeholder(tf.float32) w = tf.Variable(tf.zeros([1, 1], dtype=tf.float32))
b = tf.Variable(tf.ones([1, 1], dtype=tf.float32))
y_hat = tf.add(b, tf.matmul(x, w)) ...more setup for optimization and what not... saver = tf.train.Saver() # defaults to saving all variables - in this case w and b with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
if FLAGS.train:
for i in xrange(FLAGS.training_steps):
...training loop...
if (i + 1) % FLAGS.checkpoint_steps == 0:
saver.save(sess, FLAGS.checkpoint_dir + 'model.ckpt',
global_step=i+1)
else:
# Here's where you're restoring the variables w and b.
# Note that the graph is exactly as it was when the variables were
# saved in a prior training run.
ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir)
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
else:
...no checkpoint found... # Now you can run the model to get predictions
batch_x = ...load some data...
predictions = sess.run(y_hat, feed_dict={x: batch_x})

由浅入深之Tensorflow(4)----Saver&restore的更多相关文章

  1. 解决tensorflow Saver.restore()无效的问题

    解决tensorflow 的 Saver.restore()无法从本地读取变量的问题 最近做tensorflow 手写数字识别的时候遇到了一个问题,Saver的restore()方法无法从本地恢复变量 ...

  2. Tensorflow系列——Saver的用法

    摘抄自:https://blog.csdn.net/u011500062/article/details/51728830/ 1.实例 import tensorflow as tf import n ...

  3. 莫烦tensorflow(9)-Save&Restore

    import tensorflow as tfimport numpy as np ##save to file#rember to define the same dtype and shape w ...

  4. 深度学习原理与框架-CNN在文本分类的应用 1.tf.nn.embedding_lookup(根据索引数据从数据中取出数据) 2.saver.restore(加载sess参数)

    1. tf.nn.embedding_lookup(W, X) W的维度为[len(vocabulary_list), 128], X的维度为[?, 8],组合后的维度为[?, 8, 128] 代码说 ...

  5. 深度学习原理与框架-猫狗图像识别-卷积神经网络(代码) 1.cv2.resize(图片压缩) 2..get_shape()[1:4].num_elements(获得最后三维度之和) 3.saver.save(训练参数的保存) 4.tf.train.import_meta_graph(加载模型结构) 5.saver.restore(训练参数载入)

    1.cv2.resize(image, (image_size, image_size), 0, 0, cv2.INTER_LINEAR) 参数说明:image表示输入图片,image_size表示变 ...

  6. 1、Tensorflow 之 saver与checkpoint

    1.Tensorflow 模型文件 checkpoint model.ckpt-200.data-00000-of-00001 model.ckpt-200.index model.ckpt-200. ...

  7. saver.restore()遇到的错误

    运行python程序执行  saver.restore(sess,"E:/pythonFile/untitled/deepLearning/model/model.ckpt")   ...

  8. 由浅入深之Tensorflow(3)----数据读取之TFRecords

    转载自http://blog.csdn.net/u012759136/article/details/52232266 原文作者github地址 概述 关于Tensorflow读取数据,官网给出了三种 ...

  9. 由浅入深之Tensorflow(2)----logic_regression实现

    import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_dat ...

随机推荐

  1. 下载Qt安装包

    http://download.qt.io/archive/qt/ 找到下载页面,选择View All Downloads,找你需要的版本

  2. box-sizing在什么情况下会失效

    众所周知,box-sizing是将w3c盒模型与IE盒模型相互转换的利器,但是有时候也会失效,那么在什么情况下回失效呢,MD在没设置高度的时候回失效的透透的,所以一定记得需要转换的时候设置个高度!!!

  3. centos6安装系统时选包

    date: 2018-06-05   11:44:06 1,系统:minimal   2,包组:     Base System :  Base.Compatibility libraries.Deb ...

  4. centos-iptables-scripts

    author:headsen chen date:2018-06-04  11:20:38 notice:This  article is created by headsen chen himsel ...

  5. 《从零开始学Swift》学习笔记(Day 71)——Swift与C/C++混合编程之数据类型映射

    原创文章,欢迎转载.转载请注明:关东升的博客 如果引入必要的头文件,在Objective-C语言中可以使用C数据类型.而在Swift语言中是不能直接使用C数据类型,苹果公司为Swift语言提供与C语言 ...

  6. 01.ZooKeeper安装和介绍

    1.ZooKeeper安装和启动 1.下载解压ZooKeeper ZooKeeper官方地址:http://zookeeper.apache.org/ 下载当前稳定版本:zookeeper-3.4.6 ...

  7. msvcp71.dll 怎么丢失的?如何修复

    解决方法:另一台电脑上下载这个dll,再用优盘拷回来,复制到c:\windows\system32\下. 个人遇到的情况:迅雷下载东西时,或者在操作迅雷时出现的. win7 64位下 点击下载

  8. sssssss

    1dispatcherServlet—拦截到spring mvc的请求 2dispatchServlet调用HandlerMapping( DefaultAnnoationHandlerMapping ...

  9. Storm-源码分析-Stats (backtype.storm.stats)

    会发现, 现在storm里面有两套metrics系统, metrics framework和stats framework 并且在所有地方都是同时注册两套, 貌似准备用metrics来替代stats, ...

  10. flask中current_app._get_current_object()与current_app有什么区别?

    https://segmentfault.com/q/1010000005865632/a-1020000005865704