解决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 as tf
import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '' def myregression():
with tf.variable_scope("data"):
x = tf.random_normal([100, 1], mean=1.75, stddev=0.5)
y_true = tf.matmul(x, [[0.7]]) + 0.8
with tf.variable_scope("model"):
# 权重 trainable 指定权重是否随着session改变
weight = tf.Variable(tf.random_normal([int(x.shape[1]), 1], mean=0, stddev=1), name="w")
# 偏置项
bias = tf.Variable(0.0, name='b')
# 构造y函数
y_predict = tf.matmul(x, weight) + bias
with tf.variable_scope("loss"):
# 定义损失函数
loss = tf.reduce_mean(tf.square(y_true - y_predict))
with tf.variable_scope("optimizer"):
# 使用梯度下降进行求解
train_op = tf.train.GradientDescentOptimizer(0.1).minimize((loss))
# 1.收集tensor
tf.summary.scalar("losses", loss)
tf.summary.histogram("weights", weight)
# 2.定义合并tensor的op
merged = tf.summary.merge_all()
# 定义一个保存模型的op
saver = tf.train.Saver()
with tf.Session() as sess:
tf.global_variables_initializer().run()
# import matplotlib.pyplot as plt
# plt.scatter(x.eval(), y_true.eval())
# plt.show()
print("初始化的权重:%f,偏置项:%f" % (weight.eval(), bias.eval()))
# 建立事件文件
filewriter = tf.summary.FileWriter('./tmp/summary/test/', graph=sess.graph)
n = 0
while loss.eval() > 1e-6:
n += 1
sess.run(train_op)
summary = sess.run(merged)
filewriter.add_summary(summary, n)
print("第%d次权重:%f,偏置项:%f" % (n, weight.eval(), bias.eval()))
saver.save(sess, "tmp/ckpt/model")
return weight, bias weight, bias = myregression()
# x_min,x_max = np.min(x.eval()),np.max(x.eval())
# tx = np.arange(x_min,x_max,100)
在github有讨论这个问题,其中一个叫mrevow网友给出了它的答案:
I ran into the same issue. I don't think it is directly an issue with tf see In my case I had not changed anything in
tf but installed some other packages which reinstalled amongst other things numpy. The following fixed the issue for me
pip uninstall numpy # Keep repeating till all version of numpy are uninstalled
pip install numpy
就是先卸载numpy,在重新安装,但过程中有几个细节需要注意:
首先用管理员的权限打开cmd:
输入:
pip uninstall numpy
pip install numpy
(加入上一步报错)pip install -U numpy
解决tensorflow模型保存时Saver报错:TypeError: TF_SessionRun_wrapper: expected all values in input dict to be ndarray的更多相关文章
- python报错 TypeError: a() got multiple values for argument 'name'
[问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError: got multiple values for argument 只是很简单的调用 from tsu2Ru ...
- mvc EF 数据保存时,报错:”对一个或多个实体的验证失败……“之解决
在EF5.0添加实体数据到数据库的时候,出现“对一个或多个实体的验证失败.有关详细信息,请参见“EntityValidationErrors”属性这个错误 解决: SaveChanges前先关闭验证实 ...
- 使用webpack命令打包时,报错TypeError: Cannot read property 'presetToOptions' of undefined的解决办法
我只安装了webpack,没有安装webpack-cli,第一次输入webpack打包时,提示 One CLI for webpack must be installed. These are rec ...
- 【转】解决编译安装NGINX时make报错
编译参数:--[root@localhostnginx-1.4.6]#./configure--user=nginx--group=nginx--prefix=/usr/local/nginx--wi ...
- 解决pip安装时出现报错TypeError unsupported operand type(s) for -= 'Retry' and 'int'
1.参考 https://stackoverflow.com/questions/42610545/typeerror-unsupported-operand-types-for-retry-and- ...
- Django 生成数据库表时的报错TypeError: __init__() missing 1 required positional argument: 'on_delete'
原因及解决办法: https://www.cnblogs.com/phyger/p/8035253.html
- 【PostgreSQL】PostgreSQL添加新服务器连接时,报错“Server doesn't listen ”,已解决。
PostgreSQL添加新的服务器连接时,报错:
- 安装vue-cli时-4058报错的解决方法
一.报错信息 安装vue-cli时-4058报错 二.解决办法 1.安装淘宝镜像 npm --registry https://registry.npm.taobao.org info undersc ...
- 抓取https网页时,报错sun.security.validator.ValidatorException: PKIX path building failed 解决办法
抓取https网页时,报错sun.security.validator.ValidatorException: PKIX path building failed 解决办法 原因是https证书问题, ...
随机推荐
- zynqmp(zcu102rev1.0)系列---1---安装 xsdk
Xilinx 的zynq7020在设备上面已经使用上,并量产,关于zynq7020使用总结将在近期同步进行. 该系列主要记录Xilinx zynqmp系列 的使用以及在遇到的问题.目前手上有一块dem ...
- .NET错误:The tag 'BusyIndicator' ('CallMethodAction')does not exist in XML namespace
将一个项目由VS2010升级为VS2012后,在确保代码无误的情况下编译程序出现以下错误提示: 解决方法:将4.0.0.0的程序集Microsoft.Expression.Interactions.及 ...
- SYN5301型 时间检定装置
SYN5301型 时间检定装置 夹具概述 我们的夹具可以水平放置测秒表,也可以垂直测秒表,而其他厂家的夹具只能水平放置测,如果想垂直测的话得依靠在墙上或者是其他的物体上来测,这样的检测出来的数据 ...
- 源码解读·RT-Thread小内存管理算法分析
这篇文章最初发布在RT-Thread官方论坛中,最近准备整理放到博客中来让更多人一起探讨学习. 2012年9月28日星期五 前言: 母语能力有限 概述: 这篇文字和大家分享一下今晚对RT-Thread ...
- ChannelPipeline----贯穿io事件处理的大动脉
ChannelPipeline贯穿io事件处理的大动脉 上一篇,我们分析了NioEventLoop及其相关类的主干逻辑代码,我们知道netty采用线程封闭的方式来避免多线程之间的资源竞争,最大限度地减 ...
- 原创-使用pywinauto进行dotnet的winform程序控制(一)
pywinauto自动化控制win32的ui的程序,网上有好多的教程.但是操作dotnet写的winform教程,就少之又少.今天我就来分享我的pywinauto操作dotnet的winform的研究 ...
- 「玩转树莓派」树莓派 3B+ 配置无线WiFi
前言 网线不方便还花钱,有自带的无线 WiFi 模块为啥不用. 网络模式 这里我们先介绍两种网络模式,WPA-Personal 与 WPA-Enterprise. WPA-Personal 大多数家庭 ...
- JavaScript学习笔记(2)
常用对象 Boolean Number String Array 数组 Date 日期 Math 数字 RegExp 正则 Global 全局 函数 var m = function(){} 事件 o ...
- 大流量下的 ElasticSearch 搜索演进
这是泥瓦匠(bysocket.com)的第27篇精华分享 ES (ElasticSearch)是分布式搜索引擎.引擎太晦涩,其实类似一个 MySQL ,一个存储.方便提供下面功能: 近实时搜索 全文检 ...
- JavaScript 事件(捕获和冒泡 兼容性写法)
事件 浏览器客户端上客户触发的行为都称为事件 所有的事件都是天生自带的 不需要人为绑定 只需要我们去触发通过obj.事件名=function(){} 我们给元素的事件绑定了一个方法 事件名:on ...