pytorch报错: scatter_cpu_(): Expected self.dtype to be equal to src.dtype
最近在初学pytorch,然后在运行代码的时候出现了这个错误:
import torch as t
a = t.arange(0,16).view(4,4)
index = t.LongTensor([[0,1,2,3],[3,2,1,0]]).t()
b = a.gather(1,index)
c = t.zeros(4,4)
c.scatter_(1,index,b)
print(c)
----------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-4-b907583c1f90> in <module>4 b = a.gather(1,index)5 c = t.zeros(4,4)
----> 6 c.scatter_(1,index,b)7 print(c)RuntimeError: scatter_cpu_(): Expected self.dtype to be equal to src.dtype
后来去了下pytorch forums(那里听说氛围不错,所以我就抱着尝试的心态发了个求助帖),经过指点发现,原来这个错误是指的scatter_()函数需要实参的dtype一致,而t.arange()方法生成的tensor是torch.int64的,t.LongTensor(),t.randn(),t.zeros()生成的tensor是torch.float32的。所以只需要在这一句末尾加上.float()就可以正常运行了。
pytorch报错: scatter_cpu_(): Expected self.dtype to be equal to src.dtype相关推荐
- 安装pytorch报错及解决
环境,win10,64位,Anaconda4.10.3,Cuda 9.2.148,cudnn应该为v7.4.2.24 其中在Anaconda中好像安装tensorflow-gpu 1.9 ,pytho ...
- pycharm安装pytorch报错 提示系列问题 torch 包找不到因为pip版本低,结果升级了pip从19.3到20.2 4又提示高版不支持torch安装
pycharm安装pytorch报错 提示系列问题 torch 包找不到因为pip版本低,结果升级了pip从19.3到20.2 4又提示高版不支持torch安装 DEPRECATION: The - ...
- pytorch报错Unable to get repr for
pytorch报错Unable to get repr for 标签出现了-1,2或者其他值,loss计算之后, 报错:CUDA error: device-side assert triggered ...
- react native报错:Expected a component class,got[object object]
正在写RN的视图部分,突然模拟器报错:Expected a component class,got[object object].找也找不到原因.后来才发现是自己粗心大意造成的. 错误代码: < ...
- 解决Vue项目报错:Expected indentation of 2 spaces but found 4. eslint(indent) [8, 1]的方法
解决Vue项目报错:Expected indentation of 2 spaces but found 4. eslint(indent) [8, 1]的方法 报错如下 问题分析 明显从图中可以以看 ...
- Pytorch | 报错The given NumPy array is not writeable,and PyTorch does not support non-writeable tensor
Pytorch | 报错 The given NumPy array is not writeable,and PyTorch does not support non-writeable tenso ...
- 读取导入csv csv报错iterable expected, not float
示例代码 import pandas as pd import re import csv data = pd.read_csv('nuojia.csv', encoding='utf-8') # p ...
- Python报错“IndentationError: expected an indented block“
问题描述: 一段python代码中使用了if name == 'main':,运行程序是报错"IndentationError: expected an indented block&quo ...
- DDP报错::RuntimeError: Expected all tensors to be on the same device, but found at least two devic
DDP报错 RuntimeError: Expected all tensors to be on the same device, but found at least two devices, c ...
最新文章
- javascript控件(二):一个好用的表格(分页实例)
- python画樱桃小丸子的程序_多任务---线程threading使用总结。
- J2EE下的常用设计模式
- 每日程序C语言10-欧几里德算法
- 目标检测之选择性搜索-Selective Search
- MAVEN [ERROR] 不再支持源选项 5。请使用 7 或更高版本。
- 如何在Java中使用Zxing和JFreeSVG创建QR Code SVG?
- php的转义字符quot;反斜杠quot;是,php如何去除转义字符中的反斜杠
- Centos7 把php5.4升级到php5.6
- STC12参考例程(附模块资料代码注释、学习经验总结)
- C/C++:个人收支系统实现
- Android - 制作聊天气泡.9格式
- 网站js劫持了怎么处理和预防、js劫持了怎么办
- 淘宝滑块的解决方法和api接口
- Soft NMS+Softer NMS+KL Loss
- JAVA版村庄哨塔种子_我的世界:5个奇特且罕见的种子,相邻的哨塔,循环的地形图...
- 精妙绝伦的设计模式:策略模式+模板模式+工厂模式
- cuda安装失败(cuda安装程序失败)
- 使用 DG Tweening
- C语言if-break,if-continue和if-return区别