起因:将CCNet的十字交叉注意力模块移植到YOLOv5中。

经过:在注意力模块中,会有较多的矩阵运算,在训练时出现了cuda和cup类型的冲突(另一篇我写的文章);而在验证时出现了上述错误。

出错的代码如下:

        # [b1*w1, c1, h1] -> [b1, w1, c1, h1] -> [b1, c1, h1, w1]out_H = torch.bmm(value_H, att_H.permute(0, 2, 1)).view(b1, w1, -1, h1).permute(0, 2, 3, 1)# [b1 * h1, c1, w1] -> [b1, h1, c1, w1] -> [b1, c1, h1, w1]out_W = torch.bmm(value_W, att_W.permute(0, 2, 1)).view(b1, h1, -1, w1).permute(0, 2, 1, 3)

出错的位置在torch.bmm()处,在这里进行了一次矩阵乘法运算。由于两个数据的类型不同,因此发生冲突。

解决方案:仍然是用to()方法,修改数据类型为另一个数据的类型。

        # [b1*w1, c1, h1] -> [b1, w1, c1, h1] -> [b1, c1, h1, w1]out_H = torch.bmm(value_H, att_H.permute(0, 2, 1).to(value_H.dtype)).view(b1, w1, -1, h1).permute(0, 2, 3, 1)# [b1 * h1, c1, w1] -> [b1, h1, c1, w1] -> [b1, c1, h1, w1]out_W = torch.bmm(value_W, att_W.permute(0, 2, 1).to(value_W.dtype)).view(b1, h1, -1, w1).permute(0, 2, 1, 3)

RuntimeError: expected scalar type Half but found Float相关推荐

  1. 常见报错:RuntimeError: expected scalar type Long but found Float

    RuntimeError: expected scalar type Long but found Float 这是一个非常常见的报错,我已经遇到过这个报错很多次了,但是之前没有仔细研究过,今天好好好 ...

  2. [报错]RuntimeError: expected scalar type Double but found Float(torch)

    RuntimeError: expected scalar type Double but found Float 在使用torch训练模型的时候,发现该问题.根据提示,是双精度和float之间的冲突 ...

  3. RuntimeError: expected scalar type Double but found Float

    最近在使用 sequitur库 快速搭建自编码器时遇到 RuntimeError: expected scalar type Double but found Float 涉及代码 import to ...

  4. output = input.matmul(weight.t()) RuntimeError: expected scalar type Long but found Float 错误解决

    在使用pytorch的nn.Linear时出现错误 RuntimeError: expected scalar type Long but found Float 这里报错的原因是我的输入是Longt ...

  5. 报错:RuntimeError: expected scalar type Double but found Float

    这个问题是深度学习,用pytorch跑的时候出现的 解决办法:这个是格式问题,希望的格式是double,但得到的是float.字面意思是这个,但是并不是非要把格式改成double,这个时候应该在出错的 ...

  6. 解决pytorch当中RuntimeError: expected scalar type Double but found Float的问题

    出现这个问题的原因可能是因为tensor的数据类型不对,有可能是反向传播中输入x的类型不对,也有可能是训练和测试过程中的data类型不对,如果是反向传播过程的话,那就要看是哪一层神经网络出现问题,就在 ...

  7. 解决pytorch RuntimeError: expected scalar type XXXX but found XXXX

    比如报错为:RuntimeError: expected scalar type Long but found Float,就是希望输入为torch.Long,结果得到一个torch.Float 解决 ...

  8. expected scalar type Double but found Float

    RuntimeError: expected scalar type Double but found Float 原因:tensor的数据类型不正确 解决: 将数据类型转为float32 并不是因为 ...

  9. RuntimeError: expected scalar type Long but found Int

    这个错误首先定位是Label错误 也就是Loss计算出错! 每个代码的loss都不一样,找到我们代码的Loss那里,将label的属性变化一下 添加红框内容,根据实际情况进行调整即可

最新文章

  1. 7-4 BCD解密(C语言)
  2. 面试 Google, 我失败了!
  3. BestCoder-Round#38
  4. LeetCode 1802. 有界数组中指定下标处的最大值(思维题)
  5. java 不能用 random,关于Java中Random的一些使用细节
  6. oracle 中WITH AS,oracle的with as用法
  7. lamp一键安装包不安装mysql_LAMP一键安装包-CentOS 5/6下自动编译安装Apache、MySQL、PHP...
  8. 计算机桌面文字重影,电脑桌面字有重影怎么办
  9. 原来CSS可以添加多个阴影
  10. adb连接手机工具_adb命令——连接手机
  11. android 本地图片模糊,Android端图片模糊的实现原理及方案
  12. 【转】跨终端实践-天猫试戴的解决方案
  13. Ubuntu操作系统安装
  14. Java大端字节和小端字节
  15. 大暴雷,“山寨版拼多多”宣告破产!曾一年收割 1.3 亿用户,如今自救失败负债 16 亿...
  16. 程序设计与算法三~C++面向对象程序设计~北大郭炜MOOC学习笔记~第三章:类和对象进阶(新标准C++程序设计)
  17. 线性回归模型评估:R-square(确定系数)、均方根、均方差
  18. 四、ESP32单片机wifi的AP与STA模式使用
  19. SAPnbsp;PAnbsp;共享nbsp;免费下载
  20. matlab/simulink石良臣,《MATLAB/Simulink系统仿真超级学习手册》——2.6 MATLAB的图形绘制...

热门文章

  1. node.js安装及环境配置超详细教程【Windows系统安装包方式】
  2. 常用的英语口语(个人收藏)
  3. java个人小管家代码,基于jsp的个人生活小管家系统-JavaEE实现个人生活小管家系统 - java项目源码...
  4. C++ 实现cab文件的安装
  5. phaser.js前端游戏引擎
  6. 连接手表_一图看懂小米手表/Color连接iPhone/安卓手机的功能差别
  7. signal和sigaction
  8. 管理者必备管理工具:PDCA循环PPT完整版可编辑
  9. 借款人还不起按揭贷款会有什么后果?
  10. 【无标题】尤破金11.26黄金原油晚间多空行情策略分析及美原油实时操作建议指导