dmlc--dgl
2db8ccb487
* [Feature] Add full graph training with dgl built-in dataset. * [Feature] Add full graph training with dgl built-in dataset. * [Feature] Add full graph training with dgl built-in dataset. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Bug] fix model to cuda. * [Feature] Add test loss and accuracy * [Feature] Add test loss and accuracy * [Feature] Add test loss and accuracy * [Feature] Add test loss and accuracy * [Feature] Add test loss and accuracy * [Feature] Add test loss and accuracy * [Fix] Add random * [Bug] Fix batch norm error * [Doc] Test with CN in Sphinx * [Doc] Test with CN in Sphinx * [Doc] Remove the test CN docs. * [Feature] Add input embedding layer * [Feature] Add input embedding layer * [Feature] Add input embedding layer * [Feature] Add input embedding layer * [Feature] Add input embedding layer * [Feature] Add input embedding layer * [Feature] Add input embedding layer * [Feature] Add input embedding layer * [Feature] Add input embedding layer * [Doc] fill readme with new performance results * [Doc] Add Chinese User Guide, graph and 1.5 * [Doc] Add Chinese User Guide, graph and 1.5 * Update README.md * [Fix] Temporary remove compgcn * [Doc] Add CN user guide chapter2 * [Test] Tunning format * [Test] Tunning format * [Test] Tunning format * [Test] Tunning format * [Test] Tunning format * [Test] Section headers * [Fix] Fix format errors * [Fix] Fix format errors * [Fix] Fix format errors * [Doc] Add CN-EN EN-CN links * [Doc] Add CN-EN EN-CN links * [Doc] Copyedit chapter2 * [Doc] Copyedit chapter2 * [Doc] Remove EN in 2.1 * [Doc] Remove EN in chapter 2 * [Doc] Copyedit first 2 sections * [Doc] Copyedit first 2 sections * [Doc] copyedited chapter 2 CN * [Doc] Add chapter 3 raw texts * [Doc] Add chapter 3 preface and 3.1 * [Doc] Add chapter 3.2 and 3.3 * [Doc] Add chapter 3.2 and 3.3 * [Doc] Add chapter 3.2 and 3.3 * [Doc] Remove EN parts * [Doc] Copyediting 3.1 * [Doc] Copyediting 3.2 and 3.3 * [Doc] Proofreading 3.1 and 3.2 * [Doc] Proofreading 3.2 and 3.3 * [Doc] Add chapter 4 CN raw text. * [Clean] Remove codes in other branches * [Doc] Start to copyedit chapter 4 preface * [Doc] copyedit CN section 4.1 * [Doc] Remove EN in User Guide Chapter 4 * [Doc] Copyedit chapter 4.1 * [Doc] copyedit cn chapter 4.2, 4.3, 4.4, and 4.5. * [Doc] Fix errors in EN user guide graph feature and heterograph * [Doc] 2nd round copyediting with Murph's comments * [Doc] 3rd round copyediting with Murph's comments * [Doc] 3rd round copyediting with Murph's comments * [Doc] 3rd round copyediting with Murph's comments * [Sync] syncronize with the dgl master * [Doc] edited after Minjie's comments, 1st round * update cub Co-authored-by: Minjie Wang <wmjlyjemaine@gmail.com>
77 行
2.6 KiB
ReStructuredText
77 行
2.6 KiB
ReStructuredText
.. _guide_cn-data-pipeline-loadogb:
|
|
|
|
4.5 使用ogb包导入OGB数据集
|
|
----------------------------------------------
|
|
|
|
:ref:`(English Version) <guide-data-pipeline-loadogb>`
|
|
|
|
`Open Graph Benchmark (OGB) <https://ogb.stanford.edu/docs/home/>`__ 是一个图深度学习的基准数据集。
|
|
官方的 `ogb <https://github.com/snap-stanford/ogb>`__ 包提供了用于下载和处理OGB数据集到
|
|
:class:`dgl.data.DGLGraph` 对象的API。本节会介绍它们的基本用法。
|
|
|
|
首先使用pip安装ogb包:
|
|
|
|
.. code::
|
|
|
|
pip install ogb
|
|
|
|
|
|
以下代码显示了如何为 *Graph Property Prediction* 任务加载数据集。
|
|
|
|
.. code::
|
|
|
|
# 载入OGB的Graph Property Prediction数据集
|
|
import dgl
|
|
import torch
|
|
from ogb.graphproppred import DglGraphPropPredDataset
|
|
from torch.utils.data import DataLoader
|
|
|
|
def _collate_fn(batch):
|
|
# 小批次是一个元组(graph, label)列表
|
|
graphs = [e[0] for e in batch]
|
|
g = dgl.batch(graphs)
|
|
labels = [e[1] for e in batch]
|
|
labels = torch.stack(labels, 0)
|
|
return g, labels
|
|
|
|
# 载入数据集
|
|
dataset = DglGraphPropPredDataset(name='ogbg-molhiv')
|
|
split_idx = dataset.get_idx_split()
|
|
# dataloader
|
|
train_loader = DataLoader(dataset[split_idx["train"]], batch_size=32, shuffle=True, collate_fn=_collate_fn)
|
|
valid_loader = DataLoader(dataset[split_idx["valid"]], batch_size=32, shuffle=False, collate_fn=_collate_fn)
|
|
test_loader = DataLoader(dataset[split_idx["test"]], batch_size=32, shuffle=False, collate_fn=_collate_fn)
|
|
|
|
加载 *Node Property Prediction* 数据集类似,但要注意的是这种数据集只有一个图对象。
|
|
|
|
.. code::
|
|
|
|
# 载入OGB的Node Property Prediction数据集
|
|
from ogb.nodeproppred import DglNodePropPredDataset
|
|
|
|
dataset = DglNodePropPredDataset(name='ogbn-proteins')
|
|
split_idx = dataset.get_idx_split()
|
|
|
|
# there is only one graph in Node Property Prediction datasets
|
|
# 在Node Property Prediction数据集里只有一个图
|
|
g, labels = dataset[0]
|
|
# 获取划分的标签
|
|
train_label = dataset.labels[split_idx['train']]
|
|
valid_label = dataset.labels[split_idx['valid']]
|
|
test_label = dataset.labels[split_idx['test']]
|
|
|
|
每个 *Link Property Prediction* 数据集也只包括一个图。
|
|
|
|
.. code::
|
|
|
|
# 载入OGB的Link Property Prediction数据集
|
|
from ogb.linkproppred import DglLinkPropPredDataset
|
|
|
|
dataset = DglLinkPropPredDataset(name='ogbl-ppa')
|
|
split_edge = dataset.get_edge_split()
|
|
|
|
graph = dataset[0]
|
|
print(split_edge['train'].keys())
|
|
print(split_edge['valid'].keys())
|
|
print(split_edge['test'].keys())
|