TypeError: Can not convert a float32 into a Tensor or Operation.
来源:互联网 发布:ps3验证游戏数据 编辑:程序博客网 时间:2024/06/08 09:15
错误
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…..但是也很有趣.
阅读全文
2 0
- TypeError: Can not convert a float32 into a Tensor or Operation.
- SSD-Tensorflow:TypeError: Can not convert a tuple into a Tensor or Operation
- Cannot interpret feed_dict key as Tensor: Can not convert a method into a Tensor.
- How to convert a list of tensors into a tensor
- TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a'.
- TypeError: Cannot convert Type TensorType(float32, matrix).....
- Convert a console project into a Win32 GUI project or the other way around.
- How to convert an OpenCV cv::Mat into a float* that can be fed into Vlfeat vl_dsift_process ?
- (codes)a program convert a dec into a hex
- convert an int into a byte array
- gen already exists but is not a source folder. Convert to a source folder or
- /gen already exists but is not a source folder. Convert to a source folder or rename
- Uncaught TypeError: Super expression must either be null or a function, not undefine
- A. Friends or Not
- cloud foundry部署报错TypeError: can't convert Hash into String
- typeError: form.submit is not a function
- Uncaught TypeError: undefined is not a function
- Uncaught TypeError: string is not a function
- 渐进增强和优雅降级之间有什么不同?
- 如何用SpringBoot框架来接收multipart/form-data文件
- poj 3126 Prime Path bfs
- Oracle PL/SQL开发基础(第二十九弹:异常处理简介)
- 普通短信发送流程
- TypeError: Can not convert a float32 into a Tensor or Operation.
- 极光推送
- CUDA 8.0 + VS2013 + win10 x64开发环境搭建
- 网络编程作业 UDP (客户与咨询通话)
- Catalan数
- 第六天
- 线程基础1
- Swift_学习笔记_继承
- 矩阵取数问题