• 问题描述
  • 在使用pytorch训练经典的MNIST数据集时,运行时,出现了以下的问题:
Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
  • 问题原因:

    错误内容大概就是指输入类型是CPU(torch.FloatTensor),而参数类型是GPU(torch.cuda.FloatTensor)

    报错内容是:输入的是CPU类型的(torch.FloatTensor),然而输出的内容是GPU类型的,同时它提示,应该保持一直的数据类型
  • 解决错误:

    首先检查我们是不是正确的使用了CUDA:

1.下面是正确的使用CUDA的方法:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

2.而我之前在使用CUDA进行加速时,是这样写的:

 if torch.cuda.is_available():
model.cuda()

显然这样写是错误的,而应该采用第一种方法

  • 结果:

    在解决了上述的问题后,使用经典的MNIST数据集训练的模型进行预测的结果也就展示出来了

Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same(解决)的更多相关文章

  1. [报错]-RuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be the same

    RuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be ...

  2. torch.cuda.FloatTensor

    Pytorch中的tensor又包括CPU上的数据类型和GPU上的数据类型,一般GPU上的Tensor是CPU上的Tensor加cuda()函数得到. 一般系统默认是torch.FloatTensor ...

  3. one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [3, 1280, 28, 28]], which is output 0 of LeakyReluBackward1, is at version 2;

    RuntimeError: one of the variables needed for gradient computation has been modified by an inplace o ...

  4. Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2020-02-06'; nested exception is java.lang.IllegalArgumentException]解决

    今天做springbook项目前端输入日期传到数据库保存报了一下错误 Whitelabel Error Page This application has no explicit mapping fo ...

  5. The conversion of a varchar data type to a datetime data type resulted in an out-of-range value

    刚刚有在程序中,传递一个空值至MS SQL Server数据库,这个值的数据类型为DATETIME执行时,它却发生了如标题提示的异常:The conversion of a varchar data ...

  6. 【spring boot】spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [java.util.Date]

    spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [jav ...

  7. Failed to register: Error: fabric-ca request register failed with errors [[{"code":0,"message":"No identity type provided. Please provide identity type"}]]解决方案

    I try to run sample application as stated here : http://hyperledger-fabric.readthedocs.io/en/release ...

  8. 解决Type safety: The expression of type List needs

    解决Type safety: The expression of type List needs unchecked conversion to conform to 在方法前加上这句话就可以了@Su ...

  9. No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, org.springframework.boot.logging.LogLevel>]

    java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...

  10. 报错The "chunk" argument must be one of type string or Buffer. Received type object

    报错内容: TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or ...

随机推荐

  1. CTFshow misc1-10

    小提示:需要从图片上提取flag文字,可以通过截图翻译或者微信发送图片,这两个的ai图像识别挺好用的. misc1: 解压打开就能看见flag,提取出来就行 misc2: 记事本打开,看见 ng字符, ...

  2. 一款国产开源 Web 防火墙神器!

    随着开源 Web 框架和各种建站工具的兴起,搭建网站已经是一件成本非常低的事情,但是网站的安全性很少有人关注,以至于 WAF 这个品类也鲜为人知. 一.WAF 是什么? WAF 是 Web 应用防火墙 ...

  3. Teamcenter RAC 开发之《AbstractRendering》

    背景 关于Teamcenter RAC 客制化渲染表单,做一两个有时间做还是可以的,问题是大批量做的时候就会存在很多重复的代码 例如: 1.定义很多 TCProperty,JTextFiled,ite ...

  4. 基于三菱Q系列cc-Link的卧式自动燃煤蒸汽锅炉控制系统

    系统说明: 方案选用: 本系统最终采用三菱Q系列+FX3U系列方案 工艺流程: 触摸屏设计: 程序设计: 本文章为原创作品,未经允许,请勿转载,否则将会追究法律责任.

  5. pandas(进阶操作)-- 处理非数值型数据 -- 数据分析三剑客(核心)

    博客地址:https://www.cnblogs.com/zylyehuo/ 开发环境 anaconda 集成环境:集成好了数据分析和机器学习中所需要的全部环境 安装目录不可以有中文和特殊符号 jup ...

  6. 手把手教你写一个JSON在线解析的前端网站1

    前言 作为一名Android开发,经常要跟后端同事联调接口,那么总避免不了要格式化接口返回值,将其转换为清晰直观高亮的UI样式以及折叠部分内容,方便我们查看定位关键的信息. 一直以来都是打开Googl ...

  7. Go函数介绍与一等公民

    Go函数介绍与一等公民 函数对应的英文单词是 Function,Function 这个单词原本是功能.职责的意思.编程语言使用 Function 这个单词,表示将一个大问题分解后而形成的.若干具有特定 ...

  8. 创建vue项目并搭建JSONSERVER

    1.该前提是你已经搭建好vue-cli脚手架,开始创建一个新项目,输入 vue init webpack demo(demo是自定义项目名). 2.cd demo 进入项目安装依赖 3.在已经创建的项 ...

  9. JVM-JAVA基本类型

    1 package javap.fload; 2 3 import static jdk.nashorn.internal.objects.Global.Infinity; 4 5 public cl ...

  10. Python 既是解释型语言,也是编译型语言

    哈喽大家好,我是咸鱼 不知道有没有小伙伴跟我一样,刚开始学习 Python 的时候都听说过 Python 是一种解释型语言,因为它在运行的时候会逐行解释并执行,而 C++ 这种是编译型语言 不过我今天 ...