1、问题
模型训练完后进行测试,报错

RuntimeError: Tensor for 'out' is on CPU, Tensor for argument #1 'self' is on CPU, but expected them to be on GPU (while checking arguments for addmm)

2、原因
将模型送入GPU之后才加载之前训练好的模型,导致模型加载到了GPU,然而你的网络权重还在CPU中,此时会报错如下,报错部分代码:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
net.to(device)
net.load_state_dict(torch.load('./results/bestmodel30.pth'),False)

3、解决
换下位置即可


net.load_state_dict(torch.load('./results/bestmodel30.pth'),False)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
net.to(device)

原文链接:https://blog.csdn.net/weixin_43760844/article/details/116047427

Tensor for ‘out‘ is on CPU, Tensor for argument #1 ‘self‘ is on CPU相关推荐

  1. PyTorch 笔记(03)— Tensor 数据类型分类(默认数据类型、CPU tensor、GPU tensor、CPU 和 GPU 之间的转换、数据类型之间转换)

    1. Tensor 数据类型 Tensor 有不同的数据类型,如下表所示,每种类型都有 CPU 和 GPU 版本(HalfTensor)除外,默认的 tensor 是数据类型是 FloatTensor ...

  2. 06_2_Pytorch的基础数据类型、CPU tensor类型和GPU tensor类型、判断数据类型、CPU或GPU张量之间的转换、数据类型转换、1-4维向量、Tensor张量、Variable等

    1.6.2.Pytorch的基础数据类型 1.6.2.1.Torch定义了的七种CPU tensor类型和八种GPU tensor类型 1.6.2.2.基础数据类型 1.6.2.3.Pytorch数据 ...

  3. tensor判断是否相等_PyTorch的Tensor(中)

    背景 在PyTorch的Tensor系列上一篇文章中: Gemfield:PyTorch的Tensor(上)​zhuanlan.zhihu.com Gemfield介绍了一个Tensor的创建过程,特 ...

  4. IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python

    报错原因分析: train_loss += loss.data[0] 是旧版本的Pytorch版本代码,在Pytorch0.4-0.5中会出现警告,不会报错, 在Pytorch0.5版本以上会报错 I ...

  5. pytorch tensor 初始化_PyTorch简明笔记[1]-Tensor的初始化和基本操作

    听麻麻说,偷偷收藏而不感谢是不礼貌的,至少应该点个赞~我觉得麻麻说的对! 不断地被人安利PyTorch,终于忍不住诱惑决定入坑了. 当初学习TensorFlow的时候,没有系统性地学习.之前TF的英文 ...

  6. 解决IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Pyth

    解决IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Pyth ...

  7. invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a python number

    提示 Use tensor.item() to convert a 0-dim tensor to a Python number 原语句:running_loss+=loss.data[0]修改后: ...

  8. 从CPU与GPU利用率,到GPU与CPU差别的思考

    注:本版关于GPU的内容均是是经过实测数据提供,具有版权所有 简介: GPU与CPU貌似差别不大的两个东西,然而,从逻辑结构,到原理,到性能,到功能,再到在物理设备中扮演的角色来讲,压根就不是同一个东 ...

  9. 关于对cpu的理解和kvm虚拟机到物理cpu的绑定

    这段时间一直在想,云计算除了虚拟化之外,还应该有其它的东西,那就是优化.因为我们虚拟出来资源之后怎么用,怎么划分,是并行也好,是租给用户使用也好,都要实现资源调度和使用的最优化.嗯,这是这段时间关于云 ...

最新文章

  1. 2019.3.18 异常处理和日志相关
  2. [置顶] 2014年八大最热门IT技能
  3. 2019 年 8 月编程语言排行榜,Java涨幅不行!
  4. Nginx反向代理的使用
  5. 完美粉红噪声及各种声波测试软件,粉红噪声的测试原理
  6. 在ubuntu下怎么安装和使用Github
  7. Oracle下载账户
  8. ubuntu安装Arial.ttf字体
  9. opencv 绿色通道提取
  10. holder 插件Android,Android神器级插件
  11. AV终结者新变种(随机7位字母病毒)的分析
  12. 最小二乘法的对偶形式(CVX)
  13. win10下卜卦占星工具
  14. 品牌数字化转型|借势营销节点,3 招解锁品牌营销力
  15. VR系列--资料汇总
  16. halcon C++编程 第22讲 图像镜像 tcy
  17. 免费自学编程的12个网站,不用再花钱啦
  18. 修改安卓系统应用,将自己的app变成系统应用(需要root)
  19. 基于51单片机的AD转换
  20. CTF-Web入门-get_post

热门文章

  1. VS编译duilib项目时候的错误解决方法整理
  2. 编译时遇到如下错误error C2061: syntax error : identifier 'THIS_FILE'
  3. 守护进程的创建方法和步骤
  4. Python学习之score
  5. CentOS7下搭建Nextcloud13.0.5
  6. 大数据教父Micheal Stonebraker告诉你大数据的秘密
  7. java 计划日视图,GitHub - sddysz/calendarSchedule: 日程表,仿滴答清单,包含日视图、三日视图、周视图、月视图、列表视图、同步手机系统日程、添加日程...
  8. VSCODE常见问题(设置为4个空格)
  9. mysql select 所有表_怎样用SQL语句查询一个数据库中的所有表
  10. c语言判断文件是否建立成功,C语言编程之怎样判断某一文件是否存在