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 ...
随机推荐
- 使用 AutoGPTQ 和 transformers 让大语言模型更轻量化
大语言模型在理解和生成人类水平的文字方面所展现出的非凡能力,正在许多领域带来应用上的革新.然而,在消费级硬件上训练和部署大语言模型的需求也变得越来越难以满足. Hugging Face 的核心使命是 ...
- AI绘画:Stable Diffusion 终极炼丹宝典:从入门到精通
本文收集于教程合集:AIGC从入门到精通教程汇总 我是小梦,以浅显易懂的方式,与大家分享那些实实在在可行之宝藏. 历经耗时数十个小时,总算将这份Stable Diffusion的使用教程整理妥当. 从 ...
- 深入探讨API调用性能优化与错误处理
随着互联网技术的不断发展,API(应用程序接口)已经成为软件系统中重要的组成部分.而优化API调用的性能以及处理错误和异常情况则是保障系统稳定性和可靠性的关键.本文将从以下几个方面来探讨如何进行性 ...
- 5 分钟理解 Next.js SSG (Static Site Generation / Static Export)
5 分钟理解 Next.js SSG (Static Site Generation / Static Export) 在本篇文章中,我们将介绍 Next.js 中的 SSG(静态网站生成)功能,以及 ...
- 最快速搭建个人服务器图床siuuuuu
@ 目录 1.服务器准备 2.docker 安装 (1)通过命令行的方式 (2)宝塔面板上安装 3.开启端口访问 什么是docker 4.docker安装minio 什么是minio 5.配置mini ...
- xftp 7必须更新最新版本怎么解决
下载可以查看16进制的软件: Sublime Text 运行XFTP7 双击打开是:这样的 解决方案 用Sublime Text进行打开nslicense.dll, 打开之后查找"0f88 ...
- 有关library导入的个人总结和反思
本来帮助朋友找寻一下android的一些特效的demo,结果找到了一个,朋友试验可以,自己却是在导入项目需要的library的时候总是出问题,真的很是丢人,反省反省. 也许专业人士看来这是非常可笑的问 ...
- SonarQube系列-通过配置扫描分析范围,聚焦关键问题
在许多情况下,你可能不希望分析项目中每个源文件的各个方面.例如,项目可能包含生成的代码.库中的源代码或有意复制的代码.在这种情况下,跳过这些文件分析的部分或全部方面是有意义的,从而消除干扰并将焦点缩小 ...
- CF1352D
题目简化和分析: 这题可以直接按照题意进行模拟,当然有些细节需要注意. 翻译的不足:这里的回合指任意一个人吃掉都算,而不是双方一个回合,最后一个人即使不满足也算一个回合. 我们可以采用两个指针模拟两个 ...
- kubernetes发布周期
前言 页面介绍了版本发布的一些时间点和PR的要求,通过了解k8s的发布周期来规划自己的版本选择. 合并PR的要求 如果你希望将你的代码合并到官方代码仓库中,不同的开发阶段需要有不同的标签和里程碑.也是 ...