错误

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.相关推荐

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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. 意思是:如果 ...

  5. 【python】【h5py】TypeError: Can‘t convert element to hsize_t

    错误如下: 在使用h5py时创建h5文件时,遇到TypeError: Can't convert element to hsize_t 我这里的原因是,因为在指定shape的时候,输入了字符串数字. ...

  6. 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 ...

  7. 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 ...

  8. 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) 则会报错: ...

  9. {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 ...

最新文章

  1. IOS代码添加控件,控件移动,放大,缩小,旋转
  2. 036_PageHeader页头
  3. visio如何扩大画布的大小. 鼠标移到画布的边界按住Ctrl,就可以拉大
  4. php+mysql留言板小案例
  5. Angular jasmine TestBed.configureTestingModule的工作原理
  6. Handler、Message的简单使用
  7. 【读书笔记】.Net并行编程高级教程--Parallel
  8. 第一章 架构 1.4 编译 amp; 1.5总结
  9. DE28 Matrix Methods for Inhomogeneous Systems
  10. 2021年Qt路线图
  11. 数字电视标准大全DVB/ATSC/ISDB/CMMB/DMBTH/DAB
  12. mysql drop column_MySQL DROP COLUMN
  13. 板载天线设计相关资料
  14. [Tips]Ubuntu20.04域名解析失败或网速很慢
  15. C语言入门 函数调用 main函数 int main 是什么
  16. SpringMVC 学谈 (第二章)
  17. 这个非遗大师有点“潮”!他在网上招徒弟!
  18. 随机梯度下降与梯度下降的区别?
  19. 异贝,通过移动互联网技术,为中小微实体企业联盟、线上链接、线上线下自定义营销方案推送。案例53
  20. 少年碎碎念:《WHOLENESS》

热门文章

  1. os.path.join
  2. 刚学编程的程序员必备这5大编程网站,你知道几个?
  3. 祝愿大家都是健康的!
  4. valgrind基础
  5. 对比云备份:企业做出最佳选择
  6. couldn't connect to server 127.0.0.1:27017 src/mongo/
  7. 45岁的 SQL 语言要被淘汰了?
  8. Java中的享元设计模式,涨姿势了!
  9. 首次公开:京东数科强一致、高性能分布式事务中间件 JDTX
  10. 微服务化的基石——持续集成