当前位置:网站首页>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)
边栏推荐
- matplotlib matplotlib中axvline()和axhline()函数
- vscode试图过程写入管道不存在
- Mapping mode of cache
- 通过客户经理的开户二维码开股票账户安全吗?
- 微服务调用组件Ribbon底层调用流程分析
- When unity released webgl, jsonconvert Serializeobject() conversion failed
- 2022 meisai question a idea sharing
- 203 postgraduate entrance examination Japanese self-study postgraduate entrance examination experience post; Can I learn Japanese by myself?
- 请问在手机上开户股票,还是去证券公司开户安全?
- x86的编码格式
猜你喜欢

Question B of the East China Cup: how to establish a population immune barrier against novel coronavirus?

Nodejs using the express framework demo

Lvs-dr mode single network segment case

compiling stm32f4xx_ it. c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).

Summarize two methods of configuring pytorch GPU environment

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

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

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

Reza RA series - development environment construction

4、 Convolution neural networks
随机推荐
Is it safe to open an account online? Who can I ask?
I put a two-dimensional code with rainbow candy
[buuctf.reverse] 117-120
华泰证券在上面开户安全吗?靠谱吗?
Is it safe to open a stock account on the compass?
Data-driven anomaly detection and early warning of item C in the May 1st mathematical modeling competition in 2021
【mysql学习笔记20】mysql体系结构
Matplotlib decision boundary drawing function plot in Matplotlib_ decision_ Boundary and plt Detailed explanation of contour function
compiling stm32f4xx_ it. c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
PMP考试多少分算通过?
35 websites ICER must know
浅谈Mysql底层索引原理
请问在手机上开户股票,还是去证券公司开户安全?
Reasons for Meiye to choose membership system
Matplotlib plt grid()
[opencv] - Discrete Fourier transform
5、 Project practice --- identifying man and horse
Remove the mosaic, there's a way, attached with the running tutorial
SQL advanced
Compare and explain common i/o models