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的更多相关文章

  1. python报错 TypeError: a() got multiple values for argument 'name'

    [问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError:  got multiple values for argument 只是很简单的调用 from tsu2Ru ...

  2. mvc EF 数据保存时,报错:”对一个或多个实体的验证失败……“之解决

    在EF5.0添加实体数据到数据库的时候,出现“对一个或多个实体的验证失败.有关详细信息,请参见“EntityValidationErrors”属性这个错误 解决: SaveChanges前先关闭验证实 ...

  3. 使用webpack命令打包时,报错TypeError: Cannot read property 'presetToOptions' of undefined的解决办法

    我只安装了webpack,没有安装webpack-cli,第一次输入webpack打包时,提示 One CLI for webpack must be installed. These are rec ...

  4. 【转】解决编译安装NGINX时make报错

    编译参数:--[root@localhostnginx-1.4.6]#./configure--user=nginx--group=nginx--prefix=/usr/local/nginx--wi ...

  5. 解决pip安装时出现报错TypeError unsupported operand type(s) for -= 'Retry' and 'int'

    1.参考 https://stackoverflow.com/questions/42610545/typeerror-unsupported-operand-types-for-retry-and- ...

  6. Django 生成数据库表时的报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    原因及解决办法: https://www.cnblogs.com/phyger/p/8035253.html

  7. 【PostgreSQL】PostgreSQL添加新服务器连接时,报错“Server doesn't listen ”,已解决。

    PostgreSQL添加新的服务器连接时,报错:

  8. 安装vue-cli时-4058报错的解决方法

    一.报错信息 安装vue-cli时-4058报错 二.解决办法 1.安装淘宝镜像 npm --registry https://registry.npm.taobao.org info undersc ...

  9. 抓取https网页时,报错sun.security.validator.ValidatorException: PKIX path building failed 解决办法

    抓取https网页时,报错sun.security.validator.ValidatorException: PKIX path building failed 解决办法 原因是https证书问题, ...

随机推荐

  1. Cookieless.js —— 无需 Cookie 实现访客跟踪

    直击现场 https://github.com/Colex/node-cookieless Cookieless.js 是一个轻量级的使用 Etag 进行访客跟踪的 Node.js 扩展库.使用该库无 ...

  2. c# html网页源代码浏览器显示

    //环境VS2008,WIN7SP1 //背景:人人网自动登陆,需要把读取到的html源代码显示出来, //test.txt 为html源代码 private void Form1_Load(obje ...

  3. Spring Boot:整合Shiro权限框架

    综合概述 Shiro是Apache旗下的一个开源项目,它是一个非常易用的安全框架,提供了包括认证.授权.加密.会话管理等功能,与Spring Security一样属基于权限的安全框架,但是与Sprin ...

  4. KNN算法——分类部分

    1.核心思想 如果一个样本在特征空间中的k个最相邻的样本中的大多数属于某一个类别,则该样本也属于这个类别,并具有这个类别上样本的特性.也就是说找出一个样本的k个最近邻居,将这些邻居的属性的平均值赋给该 ...

  5. maven中引入oracle驱动报错Missing artifact com.oracle:ojdbc14:jar

    maven中央库中查找ojdbc14 ,复制依赖,maven项目中引入ojdbc14 来回折腾,加仓库镜像,各种修改setting.xml 文件 就是不行,后来看到一位网友博客,MMP Oracle ...

  6. 如何两个月刷400道leetcode

    前言随着互联网寒潮的到来, 越来越多的互联网公司提高了面试的难度,其中之一就是加大了面试当中手撕算法题的比例.这里说的算法题不是深度学习,机器学习这类的算法,而是排序,广度优先,动态规划这类既考核数据 ...

  7. string类总结第一部分函数介绍

    在前面几章,看了整个String类的源码,给每个方法都行写了注释,但是太过凌乱,今天我就把String类的方法整理归纳,然后再讲一下String类比较难以理解的部分 特此声明:本文篇幅较大,涵盖知识点 ...

  8. Java字符串String类操作方法详细整理

    关于String类的基本操作,可分为以下几类: 1.基本操作方法 2.字符串比较 3.字符串与其他数据类型之间的转换 4.字符与字符串的查找 5.字符串的截取与拆分 6.字符串的替换与修改 我觉得在整 ...

  9. Python笔记【1】_字符串学习

    #!/usr/bin/env/python #-*-coding:utf-8-*- #Author:LingChongShi #查看源码Ctrl+左键 #字符串:通常有单引号“'”.双引号“" ...

  10. Wannafly挑战赛1:Treepath(DFS统计)

    题目链接 题意 给出一棵树,问长度为偶数的路径数有多少. 思路 记录路径长度为奇数的数目和为偶数的数目,然后 n * (n-1) / 2 求和即可. #include <bits/stdc++. ...