当前位置:网站首页>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)
边栏推荐
- Cassava tree disease recognition based on vgg16 image classification
- 203 postgraduate entrance examination Japanese self-study postgraduate entrance examination experience post; Can I learn Japanese by myself?
- Opencv中的GrabCut图像分割
- Title B of the certification cup of the pistar cluster in the Ibagu catalog
- Question B of the East China Cup: how to establish a population immune barrier against novel coronavirus?
- Make a skylearn high-dimensional dataset_ Circles and make_ moons
- Socket programming -- poll model
- [buuctf.reverse] 117-120
- 微服务调用组件Ribbon底层调用流程分析
- The first techo day Tencent technology open day, 628 waiting for you!
猜你喜欢
![[learn C from me and master the key to programming] insertion sort of eight sorts](/img/2c/22e065390464ed5cd1056346d46573.jpg)
[learn C from me and master the key to programming] insertion sort of eight sorts

neo4jDesktop(neo4j桌面版)配置自动启动(开机自启)

可穿戴设备或将会泄露个人隐私

Where are the hotel enterprises that have been under pressure since the industry has warmed up in spring?

Summarize two methods of configuring pytorch GPU environment

Creo makes a mobius belt in the simplest way

2022 postgraduate entrance examination experience post -- Alibaba Business School of Hangzhou Normal University -- management science and Engineering (including the recommendation of books and course
![[MySQL learning notes 21] storage engine](/img/3a/a3cd573281efc689cafdb7d7562ce0.png)
[MySQL learning notes 21] storage engine

CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕

Matplotlib axvline() and axhline() functions in Matplotlib
随机推荐
Japanese online notes for postgraduate entrance examination (9): composition template
Is it harder to find a job in 2020? Do a good job in these four aspects and find a good job with high salary
How to download the school logo, school name and corporate logo on a transparent background without matting
[shared farm] smart agriculture applet, customized development and secondary development of Kaiyuan source code, which is more appropriate?
2022 postgraduate entrance examination experience post -- Alibaba Business School of Hangzhou Normal University -- management science and Engineering (including the recommendation of books and course
Matplotlib plt grid()
[IOU] intersection over union
PHP obtains the IP address, and the apache2 server runs without error
华泰证券在上面开户安全吗?靠谱吗?
Is it safe to open a stock account on the compass?
股票在线开户安全吗?找谁可以办理?
Applet cloud development joint table data query and application in cloud function
Specific usage of sklearn polynomialfeatures
How do dating applets make millions a year? What is the profit model?
Creating a binary tree (binary linked list) from a generalized table
[buuctf.reverse] 117-120
How much money have I made by sticking to fixed investment for 3 years?
22 mathematical modeling contest 22 contest C
x86电脑上下载debian的arm64的包
Reasons for Meiye to choose membership system