使用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]) # 正常训练