当前位置:网站首页>Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.
Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.
2022-06-25 09:32:00 【Deno_V】
使用Pytorch_Geometric(PyG)时构建DataLoader,从DataLoader获取样本Batch时报错:RuntimeError: Sizes of tensors must match except in dimension 0.
报错原因是数据对齐错误,1个batch是多个样本的集合,在样本拼接成集合时出现错误,其规律如下:
- 使用pytorch-geometric的dataloader时,batch的各个样本合并规则
- 属性edge_index规则特殊,每个样本edge_index为 2 × e i 2\times e_i 2×ei,则合并n个样本形成一个batch之后的batch.edge_index大小为 2 × ( ∑ i = 1 n e i ) 2\times(\sum_{i=1}^n e_i) 2×(∑i=1nei)
- 其他所有属性如果为tensor,则按照第一个维度扩展,例如对于属性 x x x,第一个样本大小为 d 1 × d 2 d_1\times d_2 d1×d2,第二个样本大小为 d 3 × d 2 d_3\times d_2 d3×d2,则如果有一个batch包含这两个样本,batch.x的大小会是 ( d 3 + d 1 ) × d 2 (d_3+d_1)\times d_2 (d3+d1)×d2。这里一个巨坑,要求除了第一个维度之外,其他维度大小都必须要相同!! 否则会报错
RuntimeError: Sizes of tensors must match except in dimension 0. - 其他属性如果不是tensor,就会正常按照列表返回,batch.x=[ 样本1的x,样本2的x,样本3的x]
如何解决:
- 如果是使用torch tensor引起的,可以考虑想办法对齐除了第一个维度外,其他维度的宽度。
- 如果没办法对齐,使用非tensor数据类型替换,例如列表。
- 最后的选择,指定batch_size=1以规避。
dataloader=DataLoader(MyData,batch_size=1)
边栏推荐
- 将jar包注册为服务,实现开机自动启动
- 5、 Project practice --- identifying man and horse
- Matplotlib plt Axis() usage
- Is it safe to open an account on the compass?
- Voiceprint Technology (I): the past and present life of voiceprint Technology
- Online notes on Mathematics for postgraduate entrance examination (8): Kego equations, eigenvalues and eigenvectors, similarity matrix, quadratic series courses
- Compile time annotations for custom annotations (retentionpolicy.class)
- 股票在线开户安全吗?找谁可以办理?
- CSV parameterization in JMeter
- STM32 receives data by using idle interrupt of serial port
猜你喜欢

Matplotlib simple logistic regression visualization

SQL advanced

JMeter interface test, associated interface implementation steps (token)

matplotlib matplotlib中plt.axis()用法

Remove the mosaic, there's a way, attached with the running tutorial

5、 Project practice --- identifying man and horse

2022 postgraduate entrance examination experience post -- Alibaba Business School of Hangzhou Normal University -- management science and Engineering (including the recommendation of books and course

将jar包注册为服务,实现开机自动启动

Why should the terminal retail industry choose the member management system

Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial
随机推荐
Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code
[opencv] - input and output XML and yaml files
C语言刷题随记 —— 猴子吃桃
微服务调用组件Ribbon底层调用流程分析
compiling stm32f4xx_ it. c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
Solution to the problem of repeated startup of esp8266
Lvs-dr mode single network segment case
Is it safe to open a stock account through the account opening QR code of the account manager?
2022 meisai question a idea sharing
51 SCM time stamp correlation function
1、 Construction of single neural network
sklearn 高维数据集制作make_circles 和 make_moons
Use Navicat to compare data differences and structure differences of multi environment databases, and automatic DML and DDL scripts
With the QQ group file storage function of super nice, you immediately have n cloud disks that are easy to download and never expire
Creo makes a mobius belt in the simplest way
使用Navicat对比多环境数据库数据差异和结构差异,以及自动DML和DDL脚本
[opencv] - Discrete Fourier transform
【mysql学习笔记20】mysql体系结构
Abbreviations of common English terms for IC R & D
8、智慧交通项目(1)