首页 > 解决方案 > 如何在 Pytorch Geometric 中使用 RemoveIsolatedNodes 变换?

问题描述

我正在尝试在 pytorch-geometric 中运行图形分类问题,我看到我的一些图形包含孤立的节点(这可能会导致问题)。例如,我的数据集是 pytorch 数据对象的列表:

dataset = [graph1, graph2, graph3...] 

其中 graph1 是一个 pytorch 几何数据对象,包含图的结构、节点特征和标签。我看到 pytorch 几何已经对这个任务进行了转换,但是它没有说明如何应用它,因为它是一个不需要输入的类。

标签: pythongraphdeep-learningneural-networkpytorch

解决方案


为此,您可以使用库中的remove_isolated_nodes方法torch_geometric.utils。代码可能如下所示:

for graph in dataset:
    graph['edge_index'] = remove_isolated_nodes(graph['edge_index'])[0]

推荐阅读