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

解决方法

转换类型即可,更多方法请参考:https://blog.csdn.net/weixin_35757704/article/details/118378709

import torchx = torch.FloatTensor([1, 2, 3, 4, 5, 6, 8])
x = x.type(torch.LongTensor)
print(x.type())  # torch.LongTensor

解决pytorch RuntimeError: expected scalar type XXXX but found XXXX相关推荐

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

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

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

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

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

  4. RuntimeError: expected scalar type Double but found Float

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

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

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

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

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

  7. RuntimeError: expected scalar type Long but found Int

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

  8. RuntimeError: expected scalar type Half but found Float

    起因:将CCNet的十字交叉注意力模块移植到YOLOv5中. 经过:在注意力模块中,会有较多的矩阵运算,在训练时出现了cuda和cup类型的冲突(另一篇我写的文章):而在验证时出现了上述错误. 出错的 ...

  9. expected scalar type Double but found Float

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

最新文章

  1. Alphabet wars - nuclear strike--5 kyu--Python解法
  2. table中head表头固定,body滚动
  3. 【筛素数】P1579 哥德巴赫猜想(升级版)
  4. C语言实现QR(正交三角)分解(附完整源码)
  5. 蚂蚁金服大规模分布式事务实践和开源历程
  6. jQuery笔记[1]——jqGrid中实现自定义链接弹出subgrid
  7. 用c语言实现0到59的数码管,跪求单片机0~99数码管显示用C语言编写的程序
  8. centos磁盘满了,查找大文件并清理
  9. python输出excel能够识别的utf-8格式csv文件
  10. Java知多少(31)static关键字以及Java静态变量和静态方法
  11. iOS xcode中生成和打包ipa文件的方法和步骤
  12. ntfs文件系统服务器版,详解NTFS文件系统+NTFS 文件系统解析
  13. c++ insert
  14. 【转载】【收藏】汽车电子expert成长之路公众号系列文章列表
  15. yaml 编码格式简述
  16. 用户使用移动支付的风险与防范策略
  17. Markdown内嵌图片的解决方法
  18. 博文视点名家讲坛之七经典对答回顾
  19. 人工智能教程第四课 yolo入门和案例
  20. 阿里云mysql创建用户_mysql创建用户-阿里云开发者社区

热门文章

  1. java 限流熔断_SpringCloud Alibaba微服务实战五 - 限流熔断
  2. 使用Nsight查找CE3的渲染bug
  3. UE3 性能、分析及优化
  4. cpp中vector动态数组(一种container)的简单用法
  5. 云计算迈向100%的虚拟化
  6. 杂记 - 进化成更好的人
  7. 2015第16周四自控力
  8. 浅谈网站内容应该做给谁看?
  9. 如何跨越线程调用窗体控件?(1)
  10. 未能找到服务器的主机名,未能找到服务器的主机名