GINDataset
- class dgl.data.GINDataset(name, self_loop, degree_as_nlabel=False, raw_dir=None, force_reload=False, verbose=False, transform=None)[源码]
基类:
DGLBuiltinDataset
用于 How Powerful Are Graph Neural Networks? 的数据集类。
这改编自 https://github.com/weihua916/powerful-gnns/blob/master/dataset.zip。
该类提供了论文中使用的九个数据集的接口以及论文特定的设置。这些数据集包括
'MUTAG'
,'COLLAB'
,'IMDBBINARY'
,'IMDBMULTI'
,'NCI1'
,'PROTEINS'
,'PTC'
,'REDDITBINARY'
,'REDDITMULTI5K'
。如果
degree_as_nlabel
设置为False
,则ndata['label']
存储提供的节点标签,否则ndata['label']
存储节点的入度。对于具有节点属性的图,
ndata['attr']
存储节点属性。对于没有属性的图,ndata['attr']
存储ndata['label']
的相应 one-hot 编码。- 参数:
name (str) – 数据集名称,以下之一 (
'MUTAG'
,'COLLAB'
,'IMDBBINARY'
,'IMDBMULTI'
,'NCI1'
,'PROTEINS'
,'PTC'
,'REDDITBINARY'
,'REDDITMULTI5K'
)self_loop (bool) – 如果为 true,则添加自循环边
degree_as_nlabel (bool) – 如果为 true,则将节点度作为标签和特征
transform (callable, optional) – 一个转换函数,接受
DGLGraph
对象并返回转换后的版本。每次访问DGLGraph
对象之前都会对其进行转换。
示例
>>> data = GINDataset(name='MUTAG', self_loop=False)
数据集实例是可迭代的
>>> len(data) 188 >>> g, label = data[128] >>> g Graph(num_nodes=13, num_edges=26, ndata_schemes={'label': Scheme(shape=(), dtype=torch.int64), 'attr': Scheme(shape=(7,), dtype=torch.float32)} edata_schemes={}) >>> label tensor(1)
批量处理图和标签以进行 mini-batch 训练
>>> graphs, labels = zip(*[data[i] for i in range(16)]) >>> batched_graphs = dgl.batch(graphs) >>> batched_labels = torch.tensor(labels) >>> batched_graphs Graph(num_nodes=330, num_edges=748, ndata_schemes={'label': Scheme(shape=(), dtype=torch.int64), 'attr': Scheme(shape=(7,), dtype=torch.float32)} edata_schemes={})