python - 如何在 Pytorch Geometric 中使用 RemoveIsolatedNodes 变换?
问题描述
我正在尝试在 pytorch-geometric 中运行图形分类问题,我看到我的一些图形包含孤立的节点(这可能会导致问题)。例如,我的数据集是 pytorch 数据对象的列表:
dataset = [graph1, graph2, graph3...]
其中 graph1 是一个 pytorch 几何数据对象,包含图的结构、节点特征和标签。我看到 pytorch 几何已经对这个任务进行了转换,但是它没有说明如何应用它,因为它是一个不需要输入的类。
解决方案
为此,您可以使用库中的remove_isolated_nodes
方法torch_geometric.utils
。代码可能如下所示:
for graph in dataset:
graph['edge_index'] = remove_isolated_nodes(graph['edge_index'])[0]
推荐阅读
- postgresql - Gitlab ci,symfony + postgres 错误连接被拒绝
- google-apps-script - 如何通过 GoggleScript 下载我的电子邮件
- spring-boot - Spring Boot - 跨域请求被阻止(原因:CORS 标头“Access-Control-Allow-Origin”缺失)
- php - 如何在桌子上有粘性的头饰
- flutter - 如何在颤动中动态设置文本部分的样式?
- java - 如何使用正则表达式从字符串中提取参数和值
- django - 如何使用 HTML 属性只读而不是禁用使 Django 表单字段只读
- php - 单击添加到购物车后重定向到同一页面
- c++ - 重现 cppreference 的 as-if 规则中显示的示例代码
- reactjs - 未定义属性的问题(无法读取未定义的属性“查找”)