当前位置:网站首页>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)
边栏推荐
- Flitter gets the height of the top status bar
- 使用Navicat对比多环境数据库数据差异和结构差异,以及自动DML和DDL脚本
- Voiceprint Technology (I): the past and present life of voiceprint Technology
- Voiceprint Technology (I): the past and present life of voiceprint Technology
- 可穿戴设备或将会泄露个人隐私
- Where are the hotel enterprises that have been under pressure since the industry has warmed up in spring?
- Encoding format for x86
- Matplotlib simple logistic regression visualization
- Applet cloud development joint table data query and application in cloud function
- Voiceprint Technology (III): voiceprint recognition technology
猜你喜欢

Atguigu---17-life cycle

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

Simple waterfall effect

Online notes on Mathematics for postgraduate entrance examination (9): a series of courses on probability theory and mathematical statistics

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

Cassava tree disease recognition based on vgg16 image classification

Data-driven anomaly detection and early warning of 21 May Day C

Analysis on the bottom calling process of micro service calling component ribbon

Neo4jdesktop (neo4j desktop version) configures auto start (boot auto start)

Chitubox micromake l3+ slicing software configuration correspondence
随机推荐
Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.
SQL高级
CYCA 2022少儿形体礼仪初级师资班 深圳总部站圆满结束
处理图片类库
Matplotlib plt grid()
8. Intelligent transportation project (1)
How much money have I made by sticking to fixed investment for 3 years?
[Ruby on rails full stack course] course directory
[buuctf.reverse] 121-125
22 mathematical modeling contest 22 contest C
测试开发工程师
Neo4jdesktop (neo4j desktop version) configures auto start (boot auto start)
Use Navicat to compare data differences and structure differences of multi environment databases, and automatic DML and DDL scripts
使用Navicat对比多环境数据库数据差异和结构差异,以及自动DML和DDL脚本
【mysql学习笔记21】存储引擎
Question B of the East China Cup: how to establish a population immune barrier against novel coronavirus?
[MySQL learning notes 22] index
2022 meisai question a idea sharing
汇付国际为跨境电商赋能:做合规的跨境支付平台!
富时A50开户什么地方安全