-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
73 lines (65 loc) · 1.92 KB
/
data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import torch
import torch_geometric.transforms as T
from torch_geometric.datasets import (
Actor,
HeterophilousGraphDataset,
Planetoid,
WebKB,
WikipediaNetwork,
)
from torch_geometric.utils import remove_self_loops
DATASET_TO_CLS = {
"cornell": WebKB,
"texas": WebKB,
"wisconsin": WebKB,
"chameleon": WikipediaNetwork,
"squirrel": WikipediaNetwork,
"cora": Planetoid,
"citeseer": Planetoid,
"pubmed": Planetoid,
"actor": Actor,
"roman-empire": HeterophilousGraphDataset,
"amazon-ratings": HeterophilousGraphDataset,
"minesweeper": HeterophilousGraphDataset,
"tolokers": HeterophilousGraphDataset,
"questions": HeterophilousGraphDataset,
}
DATASET_TO_METRIC = {
"cornell": "acc",
"texas": "acc",
"wisconsin": "acc",
"chameleon": "acc",
"squirrel": "acc",
"cora": "acc",
"citeseer": "acc",
"pubmed": "acc",
"actor": "acc",
"roman-empire": "acc",
"amazon-ratings": "acc",
"minesweeper": "auc",
"tolokers": "auc",
"questions": "auc",
}
def get_dataset(
name, root_path="./data/", device="cpu", undirected=True, one_hot=False, **kwargs
):
name = name.lower()
transforms = [T.ToDevice(device)]
if undirected:
transforms.extend([T.ToUndirected()])
constructor = DATASET_TO_CLS[name]
if constructor != HeterophilousGraphDataset:
transforms.extend([T.NormalizeFeatures()])
transform = T.Compose(transforms)
args = dict(root=root_path, transform=transform, **kwargs)
if constructor == Planetoid:
args["split"] = "full"
if "name" in constructor.__init__.__annotations__:
args["name"] = name
dataset = constructor(**args)
if one_hot:
dataset._data.x = torch.eye(dataset._data.x.shape[0])
dataset._data.edge_index, dataset._data.edge_attr = remove_self_loops(
dataset._data.edge_index, dataset._data.edge_attr
)
return dataset