当前位置:网站首页>Pytorch_ Geometric (pyg) uses dataloader to report an error runtimeerror: sizes of tenants must match except in dimension 0
Pytorch_ Geometric (pyg) uses dataloader to report an error runtimeerror: sizes of tenants must match except in dimension 0
2022-06-25 09:41:00 【Deno_ V】
Use Pytorch_Geometric(PyG) Time to build DataLoader, from DataLoader Take samples Batch Times wrong :RuntimeError: Sizes of tensors must match except in dimension 0.
The error is caused by data alignment error ,1 individual batch Is a collection of multiple samples , An error occurred when the samples were spliced into a set , The law is as follows :
- Use pytorch-geometric Of dataloader when ,batch Merge rules for each sample of
- attribute edge_index Special rules , Each sample edge_index by 2 × e i 2\times e_i 2×ei, Then merge n Samples form a batch After that batch.edge_index The size is 2 × ( ∑ i = 1 n e i ) 2\times(\sum_{i=1}^n e_i) 2×(∑i=1nei)
- If all other attributes are tensor, Expand according to the first dimension , For example, for attributes x x x, The first sample size is d 1 × d 2 d_1\times d_2 d1×d2, The second sample size is d 3 × d 2 d_3\times d_2 d3×d2, If there is one batch These two samples are included ,batch.x The size of will be ( d 3 + d 1 ) × d 2 (d_3+d_1)\times d_2 (d3+d1)×d2. Here is a huge pit , It requires that in addition to the first dimension , All other dimensions must be the same size !! Otherwise, an error will be reported
RuntimeError: Sizes of tensors must match except in dimension 0. - Other properties if not tensor, It will return normally according to the list ,batch.x=[ sample 1 Of x, sample 2 Of x, sample 3 Of x]
How to solve :
- If using torch tensor Caused by the , Think of ways to align other than the first dimension , Width of other dimensions .
- If there is no way to align , Use non tensor Data type substitution , For example, a list of .
- The last choice , Appoint batch_size=1 To avoid .
dataloader=DataLoader(MyData,batch_size=1)
边栏推荐
- Is the client that gets the scanning code wechat or Alipay
- 瑞萨RA系列-开发环境搭建
- On the underlying index principle of MySQL
- x86电脑上下载debian的arm64的包
- Question B of the East China Cup: how to establish a population immune barrier against novel coronavirus?
- Applet cloud development joint table data query and application in cloud function
- SQL高级
- Online notes on Mathematics for postgraduate entrance examination (8): Kego equations, eigenvalues and eigenvectors, similarity matrix, quadratic series courses
- 处理图片类库
- 测试开发工程师
猜你喜欢

22 mathematical modeling contest 22 contest C

Prediction of pumpkin price based on BP neural network

The meshgrid() function in numpy

Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial

x86电脑上下载debian的arm64的包

How to delete a blank page that cannot be deleted in word

Notes on writing questions in C language -- monkeys eat peaches

Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code

《JVM》对象内存分配的TLAB机制与G1中的TLAB流程
![[competition -kab micro entrepreneurship competition] KAB National College Students' micro entrepreneurship action participation experience sharing (including the idea of writing the application form)](/img/f3/a8414635ad39ad405864f5fcf66d6d.jpg)
[competition -kab micro entrepreneurship competition] KAB National College Students' micro entrepreneurship action participation experience sharing (including the idea of writing the application form)
随机推荐
浅谈Mysql底层索引原理
What should be paid attention to in PMP examination?
瑞吉外卖项目(二)
在指南针上面开户好不好,安不安全?
CSV parameterization in JMeter
manhattan_slam环境配置
PMP考试多少分算通过?
Socket programming -- poll model
Wallys/MULTI-FUNCTION IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL
51 SCM time stamp correlation function
Cassava tree disease recognition based on vgg16 image classification
Online notes on Mathematics for postgraduate entrance examination (8): Kego equations, eigenvalues and eigenvectors, similarity matrix, quadratic series courses
如何自制一个安装程序,将程序打包生成安装程序的办法
Specific usage of sklearn polynomialfeatures
在指南针上面开股票账户好不好,安不安全?
Lvs-dr mode single network segment case
Online notes on Mathematics for postgraduate entrance examination (9): a series of courses on probability theory and mathematical statistics
Vscode attempted to write the procedure to a pipeline that does not exist
Data-driven anomaly detection and early warning of 21 May Day C
[competition -kab micro entrepreneurship competition] KAB National College Students' micro entrepreneurship action participation experience sharing (including the idea of writing the application form)