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…..但是也很有趣.
TypeError: Can not convert a float32 into a Tensor or Operation.相关推荐
- tensorflow的错误之Can not convert a float32 into a Tensor or Operation
_,train_loss,acc=self.sess.run([train_op,total_losses,acc],feed_dict=feed_dict)TypeError: Fetch argu ...
- TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to
问题描述: Traceback (most recent call last):File "D:\rotation-yolov5-master\detect.py", line 1 ...
- Pycharm中运行yolov5-pytorch出现错误“TypeError: can‘t convert cuda:0 device type tensor to numpy....“
具体错误如下: TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the te ...
- 2021-07-26 TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the
can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. 意思是:如果 ...
- 【python】【h5py】TypeError: Can‘t convert element to hsize_t
错误如下: 在使用h5py时创建h5文件时,遇到TypeError: Can't convert element to hsize_t 我这里的原因是,因为在指定shape的时候,输入了字符串数字. ...
- cloud foundry部署报错TypeError: can't convert Hash into String
报错:TypeError: can't convert Hash into String The first thing I notice is you are running Ruby 1.8 on ...
- TypeError: can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory
项目场景: 运行程序,出现报错信息 TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor ...
- can‘t convert cuda:0 device type tensor to numpy
can't convert cuda:0 device type tensor to numpy x是list,list内容是tensor cuda 代码: x = np.array(x) 则会报错: ...
- {TypeError}clamp(): argument 'min' must be Number, not Tensor
{TypeError}clamp(): argument 'min' must be Number, not Tensor x1是二维数组, xx1 = x1[order[1:]].clamp(min ...
最新文章
- IOS代码添加控件,控件移动,放大,缩小,旋转
- 036_PageHeader页头
- visio如何扩大画布的大小. 鼠标移到画布的边界按住Ctrl,就可以拉大
- php+mysql留言板小案例
- Angular jasmine TestBed.configureTestingModule的工作原理
- Handler、Message的简单使用
- 【读书笔记】.Net并行编程高级教程--Parallel
- 第一章 架构 1.4 编译 amp; 1.5总结
- DE28 Matrix Methods for Inhomogeneous Systems
- 2021年Qt路线图
- 数字电视标准大全DVB/ATSC/ISDB/CMMB/DMBTH/DAB
- mysql drop column_MySQL DROP COLUMN
- 板载天线设计相关资料
- [Tips]Ubuntu20.04域名解析失败或网速很慢
- C语言入门 函数调用 main函数 int main 是什么
- SpringMVC 学谈 (第二章)
- 这个非遗大师有点“潮”!他在网上招徒弟!
- 随机梯度下降与梯度下降的区别?
- 异贝,通过移动互联网技术,为中小微实体企业联盟、线上链接、线上线下自定义营销方案推送。案例53
- 少年碎碎念:《WHOLENESS》