解决tensorflow Saver.restore()无效的问题
解决tensorflow 的 Saver.restore()无法从本地读取变量的问题
最近做tensorflow 手写数字识别的时候遇到了一个问题,Saver的restore()方法无法从本地恢复变量,导致了每次都会重新训练。
原来代码
saver = tf.train.Saver(max_to_keep=5)
epoch = tf.Variable(0, name='epoch', trainable=False)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
ckpt_dir = "./model/"
if not os.path.exists(ckpt_dir):
os.makedirs(ckpt_dir)
ckpt = tf.train.latest_checkpoint(ckpt_dir)
if ckpt != None:
saver.restore(sess, ckpt)
else:
print('Train from scratch')
start = sess.run(epoch)
修改代码
epoch = tf.Variable(0, name='epoch', trainable=False)
saver = tf.train.Saver(max_to_keep=5)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
ckpt_dir = "./model/"
if not os.path.exists(ckpt_dir):
os.makedirs(ckpt_dir)
ckpt = tf.train.latest_checkpoint(ckpt_dir)
if ckpt != None:
saver.restore(sess, ckpt)
else:
print('Train from scratch')
start = sess.run(epoch)
其实主要改变的就是以下两行的顺序
epoch = tf.Variable(0, name='epoch', trainable=False)
saver = tf.train.Saver(max_to_keep=5)
解决tensorflow Saver.restore()无效的问题的更多相关文章
- 由浅入深之Tensorflow(4)----Saver&restore
x = tf.placeholder(tf.float32) y = tf.placeholder(tf.float32) w = tf.Variable(tf.zeros([1, 1], dtype ...
- 深度学习原理与框架-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] 代码说 ...
- 深度学习原理与框架-猫狗图像识别-卷积神经网络(代码) 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表示变 ...
- TensorFlow Saver的使用方法
我们经常在训练完一个模型之后希望保存训练的结果,这些结果指的是模型的参数,以便下次迭代的训练或者用作测试.Tensorflow针对这一需求提供了Saver类. Saver类提供了向checkpoint ...
- TensorFlow Saver 保存最佳模型 tf.train.Saver Save Best Model
TensorFlow Saver 保存最佳模型 tf.train.Saver Save Best Model Checkmate is designed to be a simple drop-i ...
- paip.解决access出现 -2147467259 无效的参数量
paip.解决access出现 -2147467259 无效的参数量 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http: ...
- saver.restore()遇到的错误
运行python程序执行 saver.restore(sess,"E:/pythonFile/untitled/deepLearning/model/model.ckpt") ...
- 解决tensorflow模型保存时Saver报错:TypeError: TF_SessionRun_wrapper: expected all values in input dict to be ndarray
TypeError: TF_SessionRun_wrapper: expected all values in input dict to be ndarray 对于下面的实际代码: import ...
- tensorflow saver简介+Demo with linear-model
tf.train.Saver提供Save和Restore Tensorflow变量的功能,常用于保存.还原模型训练结果,这在自己的训练和迁移学习中都很有用. 训练.保存脚本: import tenso ...
随机推荐
- opensuse安装pycharm
最近在学习python,所以查询了很多资料,大多都推荐pycharm进行pychon项目开发.于是查阅一些资料,整理出这个安装步骤.(仅供参考!!!仅供参考!!!仅供参考!!!) 仅供参考!!!仅供参 ...
- 【音乐欣赏】《Heart Made of Stone》 - The Tech Thieves
曲名:Heart Made of Stone 作者:The Tech Thieves Yeah It's been years now and I wonder Is it over? Do you ...
- LED Craft Light - How To Solve: Home Decoration Lighting
Home décor usually comes with a certain period of theme or a specific style of furniture, which will ...
- The number of set(位运算+状态dp)一道十分美妙的题目哦!!!!!!
Given you n sets.All positive integers in sets are not less than 1 and not greater than m.If use the ...
- <img src = "..."/>的一个图片上面怎么在放上字
转自:https://zhidao.baidu.com/question/1495805873400412779.html 例子1: html中可以用css相对定位让文字在图片的上面. 1.新建htm ...
- WPF MVVM 键盘按键事件绑定
<TextBox Text="{Binding LoginName}" Height="35" Canvas.Left="306" T ...
- 051_switch语句的使用 052_while循环详解 053_for循环详解_dowhile简介 054_嵌套循环_循环相关练习
051_switch语句的使用 package testmode2;/** * 测试switch语句 * 遇到多值判断的时候,使用switch.当然,switch完全可以使用ifelseifelse代 ...
- Yii2.0 高级版修改默认访问控制器
frontend->config->main-local.php $config = [ 'defaultRoute' => 'index/index',//修改默认访问控制器 'c ...
- ansible笔记(7):常用模块之包管理模块
1.yum_repository模块 用于远程管理远程主机上的yum仓库. 参数解析: name:必须参数,用于指定要操作的唯一的仓库ID,也就是.repo配置文件中每个仓库对应的“中括号”内的仓库I ...
- Redis非关系型缓存数据库集群部署、参数、命令工具
<关系型数据库与非关系型数据库> 关系数据库:mysql.oracle.DB2.SQL Server非关系数据库:Redis(缓存数据库).MongodDB(处理海量数据).Memcach ...