forked from dmlc/dgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_dataset.py
60 lines (50 loc) · 1.63 KB
/
load_dataset.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
""" load dataset from ogb """
import argparse
import time
from ogb.linkproppred import DglLinkPropPredDataset
def load_from_ogbl_with_name(name):
choices = ["ogbl-collab", "ogbl-ddi", "ogbl-ppa", "ogbl-citation"]
assert name in choices, "name must be selected from " + str(choices)
dataset = DglLinkPropPredDataset(name)
return dataset[0]
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--name",
type=str,
choices=["ogbl-collab", "ogbl-ddi", "ogbl-ppa", "ogbl-citation"],
default="ogbl-collab",
help="name of datasets by ogb",
)
args = parser.parse_args()
print("loading graph... it might take some time")
name = args.name
g = load_from_ogbl_with_name(name=name)
try:
w = g.edata["edge_weight"]
weighted = True
except:
weighted = False
edge_num = g.edges()[0].shape[0]
src = list(g.edges()[0])
tgt = list(g.edges()[1])
if weighted:
weight = list(g.edata["edge_weight"])
print("writing...")
start_time = time.time()
with open(name + "-net.txt", "w") as f:
for i in range(edge_num):
if weighted:
f.write(
str(src[i].item())
+ " "
+ str(tgt[i].item())
+ " "
+ str(weight[i].item())
+ "\n"
)
else:
f.write(
str(src[i].item()) + " " + str(tgt[i].item()) + " " + "1\n"
)
print("writing used time: %d s" % int(time.time() - start_time))