PyG 自定义数据集报错 IndexError: Dimension out of range (expected to be in range of [-1, 0], but got -2)
·
使用Pytorch-Geometric框架自定义数据集时,报错
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got -2)
原因: 我这边的情况是N个节点,每个节点只有一个特征,Data(x, y, edge_index)中的 x 为 一维张量 时会报错。
解决方法: 改为二维张量。
x = torch.from_numpy(features[i])
# x: tensor([ 0.7407, -0.1673, 0.1678, 0.1453, -0.2432, -0.7662, 0.1561])
# x.size(): torch.Size([7])
# 此时训练会报错 IndexError: 阿巴阿巴 but got -2
x = torch.from_numpy(features[i].reshape(-1, 1))
# x: tensor([[ 0.7407],
# [-0.1673],
# [ 0.1678],
# [ 0.1453],
# [-0.2432],
# [-0.7662],
# [ 0.1561]])
# x.size(): torch.Size([7,1])
# 正常训练
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)