当前位置:网站首页>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)
边栏推荐
- Opencv中的GrabCut图像分割
- 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
- Is the client that gets the scanning code wechat or Alipay
- x86的编码格式
- How to "transform" small and micro businesses (I)?
- Benefits and types of cloud network technology
- Question B of the East China Cup: how to establish a population immune barrier against novel coronavirus?
- Register the jar package as a service to realize automatic startup after startup
- 8、智慧交通项目(1)
- [wechat applet full stack development course] course directory (mpvue+koa2+mysql)
猜你喜欢
![[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate](/img/75/a06e20b4394579cbd9f6d3a075907a.jpg)
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate

Atguigu---17-life cycle

匯付國際為跨境電商賦能:做合規的跨境支付平臺!

Huipay international permet au commerce électronique transfrontalier de devenir une plate - forme de paiement transfrontalière conforme!

Reasons for Meiye to choose membership system

将jar包注册为服务,实现开机自动启动
![[competition - Rural Revitalization] experience sharing of Zhejiang Rural Revitalization creative competition](/img/b4/84c30ed112c4dffd8d51697b2f4a4f.jpg)
[competition - Rural Revitalization] experience sharing of Zhejiang Rural Revitalization creative competition

Solution to the problem of repeated startup of esp8266

3 big questions! Redis cache exceptions and handling scheme summary

Cassava tree disease recognition based on vgg16 image classification
随机推荐
2022 meisai question a idea sharing
Voiceprint Technology (VI): other applications of voiceprint Technology
股票在线开户安全吗?找谁可以办理?
C语言刷题随记 —— 猴子吃桃
【mysql学习笔记20】mysql体系结构
SQL高级
如何自制一个安装程序,将程序打包生成安装程序的办法
[shared farm] smart agriculture applet, customized development and secondary development of Kaiyuan source code, which is more appropriate?
Atguigu---18-component
[zufe school competition] difficulty classification and competition suggestions of common competitions in the school (taking Zhejiang University of Finance and economics as an example)
《JVM》对象内存分配的TLAB机制与G1中的TLAB流程
Prediction of pumpkin price based on BP neural network
puzzle(019.2)六边锁
What functions should smart agriculture applet system design have
Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial
汇付国际为跨境电商赋能:做合规的跨境支付平台!
Matplotlib decision boundary drawing function plot in Matplotlib_ decision_ Boundary and plt Detailed explanation of contour function
在指南针上面开股票账户好不好,安不安全?
manhattan_slam环境配置
Voiceprint Technology (V): voiceprint segmentation and clustering technology