LegacyTUDataset
- class dgl.data.LegacyTUDataset(name, use_pandas=False, hidden_size=10, max_allow_node=None, raw_dir=None, force_reload=False, verbose=False, transform=None)[source]
Bases:
DGLBuiltinDataset
LegacyTUDataset 包含许多用于图分类的图核数据集。
- Parameters:
name (str) – 数据集名称,例如
ENZYMES
,DD
,COLLAB
,MUTAG
,可以是 https://chrsmrrs.github.io/datasets/docs/datasets/ 上的数据集名称。use_pandas (bool) – 当文件较大时,Numpy的文件读取函数存在性能问题,使用pandas可能会更快。 默认值:False
hidden_size (int) – 某些数据集不包含特征。 使用常量节点特征初始化代替,隐藏大小为
hidden_size
。 默认值:10max_allow_node (int) – 移除包含超过
max_allow_node
节点的图。 默认值:无transform (callable, optional) – A transform that takes in a
DGLGraph
object and returns a transformed version. TheDGLGraph
object will be transformed before every access.
- num_labels
(已弃用,请使用 num_classes 代替)类别数量
- Type:
numpy.int64
注释
LegacyTUDataset 默认使用提供的节点特征。如果没有提供特征,则使用独热编码的节点标签代替。 如果也没有提供标签,则使用常量作为节点特征。
数据集根据标签对图表进行排序。 在手动进行训练/验证分割之前,建议先进行洗牌。
示例
>>> data = LegacyTUDataset('DD')
数据集实例是可迭代的
>>> len(data) 1178 >>> g, label = data[1024] >>> g Graph(num_nodes=88, num_edges=410, ndata_schemes={'feat': Scheme(shape=(89,), dtype=torch.float32), '_ID': Scheme(shape=(), dtype=torch.int64)} edata_schemes={'_ID': Scheme(shape=(), dtype=torch.int64)}) >>> label tensor(1)
将图和标签分批用于小批量训练
>>> 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=9539, num_edges=47382, ndata_schemes={'feat': Scheme(shape=(89,), dtype=torch.float32), '_ID': Scheme(shape=(), dtype=torch.int64)} edata_schemes={'_ID': Scheme(shape=(), dtype=torch.int64)})
- __getitem__(idx)[source]
获取第 idx 个样本。
- Parameters:
idx (int) – 样本索引。
- Returns:
图中节点的特征存储在
feat
字段中,节点的标签存储在node_label
字段中(如果存在)。 以及它的标签。- Return type:
(
dgl.DGLGraph
, 张量)