Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same(解决)
- 问题描述
- 在使用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(解决)的更多相关文章
- [报错]-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 ...
- torch.cuda.FloatTensor
Pytorch中的tensor又包括CPU上的数据类型和GPU上的数据类型,一般GPU上的Tensor是CPU上的Tensor加cuda()函数得到. 一般系统默认是torch.FloatTensor ...
- 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 ...
- 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 ...
- 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 ...
- 【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 ...
- 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 ...
- 解决Type safety: The expression of type List needs
解决Type safety: The expression of type List needs unchecked conversion to conform to 在方法前加上这句话就可以了@Su ...
- 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 ...
- 报错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 ...
随机推荐
- 简单了解PyCharm
简单了解PyCharm PyCharm的简单使用 修改主题 1 2 切换解释器 1 如何创建pythin文件 1 2 3 4 注释语法 行注释 这里是注释 块注释 '''这里是注释''' 常量和变量的 ...
- 如何将项目打包上传到NuGet服务器?
作者:西瓜程序猿 主页传送门:https://www.cnblogs.com/kimiliucn 前言 在我写[在.NET Framework中使用RocketMQ(阿里云版)]这篇博客的时候,因为封 ...
- 【反反爬】使用Jsoup爬取数据保存Excel
本文主要使用Jsoup爬取XXX房屋信息,抓取一些房屋信息,比如房屋楼盘.户型.价格.地址等信息,然后保存到Excel,便于对比和筛选,选出符合预期的好房. 注意,有些网站有防爬取机制,需要设置动 ...
- 支持JDK19虚拟线程的web框架,之四:看源码,了解quarkus如何支持虚拟线程
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本篇是<支持JDK19虚拟线程的web ...
- CocoaPods 在iOS开发中养活了这么多项目,它到底是个啥?
对于iOS开发者而言,CocoaPods并不陌生,通过pod相关的命令操作,就可以很方便的将项目中用到的三方依赖库资源集成到项目环境中,大大的提升了开发的效率.CocoaPods作为iOS项目的包管理 ...
- 将Python程序打包成Linux可执行文件
将Python程序打包成Linux可执行文件 安装环境 首先我们要安装pip,命令如下: sudo apt install python3-pip 使用的工具是pyinstaller,打开终端输入su ...
- destoon上做纯js实现html指定页面导出word
因为最近做了范文网站需要,所以要下载为word文档,如果php进行处理,很吃后台服务器,所以想用前端进行实现.查询github发现,确实有这方面的插件. js导出word文档所需要的两个插件: 1 2 ...
- 爬虫系列——requests
文章目录 一 介绍 二 基于GET请求 三 基于POST请求 四 响应Response 五 高级用法 一 介绍 介绍:使用requests可以模拟浏览器的请求,比起之前用到的urllib,reques ...
- OPPO主题组件开发 - 组件内容自适应
OPPO桌面有 3*5.3*6.4*5.4*6.5*5.5*6 等布局,随着布局不同,组件大小也会发生改变:不同型号手机分辨率不同,组件大小也不一致.这就要求组件内容做到自适应. 说明 OPPO主题组 ...
- 基于.Net 的 AvaloniUI 多媒体播放器方案汇总
基于.Net 的 AvaloniUI 多媒体播放器方案汇总 摘要 随着国产化的推进,相信.Net的桌面端的小伙伴的可能已经有感受到了. 为了让.Net的桌面框架能够跨桌面平台,首选的就是Avalona ...