Type erroe in tensorflow
has invalid type<type 'numpy.ndarray'>, must be a string or Tensor
TypeError: Can not convert a float32 into a Tensor or Operation.
错误
TypeError: Can not convert a float32 into a Tensor or Operation.
# 类型错误:不能将一个浮动32转换为一个张量或操作。TypeError: Fetch argument 2.3025854 has invalid type <class 'numpy.float32'>, must be a string or Tensor. (Can not convert a float32 into a Tensor or Operation.)
如其意,类型错误:不能将一个浮动32转换为一个张量或操作。也就是在计算图实际运算的时候发生的错误,错误为数据类型错误,将应该是传入的张量或者操作的的地方传入了一个 float32 类型的数据.
分析
源码
for step in range(1000):batch_xs, batch_ys = mnist.train.next_batch(100)_, Train_Loss = sess.run([Train_Step,Train_Loss], feed_dict={X: batch_xs, Y_true: batch_ys})print('Train step :',step,'Train_Losss :',Train_Loss)
错误产生的时候我查了查代码,没明白什么意思,后来debug才发现,是变量在第二遍运行的时候数据类型发生了改变,
其改变是在第一遍的时候,仔细看源代码,输出的Train_Loss
与后面sess.run([Train_Step,Train_Loss], feed_dict={X: batch_xs, Y_true: batch_ys})
中的’Train_Loss’同名,显然第一遍运行之后,原本应该传入session的Train_Loss就从张量变成了 float32
解决方案
避免重名,使用不同的名字
如原来的
_, Train_Loss = sess.run([Train_Step,Train_Loss], feed_dict={X: batch_xs, Y_true: batch_ys})
改为
_, train_loss = sess.run([Train_Step,Train_Loss], feed_dict={X: batch_xs, Y_true: batch_ys})
BUG就消失了
这是一个很低级的BUG…..但是也很有趣.
Type erroe in tensorflow相关推荐
- Debug Tensorflow: Object was never used (type <class ‘tensorflow.python.ops.tensor_array_ops.TensorA
报错信息 环境 ubuntu tensorflow-gpu 解决 错误来自对TensorArray的使用上. 原代码: y.write(0,[[20,1,10]]) 修改为: y = y.write( ...
- FutureWarning: Passing (type, 1) or ‘1type‘ it will be understood as (type, (1,)) / ‘(1,)type‘
FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version ...
- tensorflow dataset_ops shuffle()方法 (随机重新排列此数据集的元素)
def shuffle(self, buffer_size, seed=None, reshuffle_each_iteration=None):"""Randomly ...
- tensorflow教程 学习笔记 之 Eager execution 急切执行
链接:https://tensorflow.juejin.im/get_started/ 学习它主要为了解决yunyang tensorflow-yolov-3GPU多线程调用的问题 文章目录 坑1 ...
- TensorFlow学习入门
学习了基本的神经网络知识后,要使用框架了,这样才能出来更加复杂的情况,更快的开发出模型. 首先安装后,按照官网写了一个例子,但是又好多不懂,但只是第一步, 看这段代码,其实给你提供了很多学习tf的线索 ...
- tensorflow.python.framework.tensor_shape.TensorShape 类
TensorShape 是tensorflow中关于张量shape的类(class). 使用示例如下: import tensorflow.compat.v1 as tf from tensorflo ...
- Tensorflow神经网络框架 小例子 三层神经网络 卷积神经网络 循环神经网络 神经网络可视化
Tensorflow神经网络框架 以前我们讲了神经网络基础,但是如果从头开始实现,那将是一个庞大且费时的工作,所以我们选择一条捷径---神经网络框架.我理解的神经网络框架就相当于一个工具包.就比如我们 ...
- Tensorflow中的各种梯度处理gradient
最近其实一直想自己手动创建op,这样的话好像得懂tensorflow自定义api/op的规则,设计前向与反向,注册命名,注意端口以及文件组织,最后可能还要需要重新编译才能使用.这一部分其实记得tens ...
- dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a
dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a ...
- 【神经网络与深度学习-TensorFlow实践】-中国大学MOOC课程(八)(TensorFlow基础))
[神经网络与深度学习-TensorFlow实践]-中国大学MOOC课程(八)(TensorFlow基础)) 8 TensorFlow基础 8.1 TensorFlow2.0特性 8.1.1 Tenso ...
最新文章
- TensorFow的基本使用
- linux安装nginx源码,CentOS7源码编译安装Nginx
- SQLite数据库Java驱动下载及连接示例(sqlite-jdbc-3.30.1.jar)
- 【对讲机的那点事】450MHz模拟无线列调的工作原理(连载五)
- Docker介绍及安装
- sql case when then else多个条件_SQL-多表查询
- webpack中如何使用vue
- 功能增强的进度条控件(源码)
- Golang中MYSQL驱动
- 最新传奇游戏公司网站模板源码+带手机端/易优CMS内核
- SOLIDWORKS在机械设计行业的优势所在
- html div自动换行代码,css自动换行_css
- 我做过的本职之外的事情
- 一、Sails基础操作
- drag方法——>拖拽
- 职场必备:Excel2016,官方推荐使用技巧
- 图片生成 php源码_php图像验证码生成代码
- Win10屏幕不自动关闭怎么设置
- 书桌台灯怎么选?分享儿童卧室灯品牌
- Android O 安卓启动时间优化分析