MCPcopy
hub / github.com/THUDM/CogDL / process_json

Function process_json

examples/bgrl/data.py:35–66  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

33
34
35def process_json(path):
36 with open(path, 'r') as f:
37 data = json.load(f)
38
39 x = torch.tensor(data['features'], dtype=torch.float)
40 y = torch.tensor(data['labels'], dtype=torch.long)
41
42 edges = [[(i, j) for j in js] for i, js in enumerate(data['links'])]
43 edges = list(chain(*edges))
44 edge_index = torch.tensor(edges, dtype=torch.long).t().contiguous()
45 edge_index = to_undirected(edge_index, num_nodes=x.size(0))
46
47 train_mask = torch.tensor(data['train_masks'], dtype=torch.bool)
48 train_mask = train_mask.t().contiguous()
49
50 val_mask = torch.tensor(data['val_masks'], dtype=torch.bool)
51 val_mask = val_mask.t().contiguous()
52
53 test_mask = torch.tensor(data['test_mask'], dtype=torch.bool)
54
55 stopping_mask = torch.tensor(data['stopping_masks'], dtype=torch.bool)
56 stopping_mask = stopping_mask.t().contiguous()
57
58 return Graph(
59 x=x,
60 y=y,
61 edge_index=edge_index,
62 train_mask=train_mask,
63 val_mask=val_mask,
64 test_mask=test_mask,
65 stopping_mask=stopping_mask
66 )
67
68
69def normalize_feature(data):

Callers 1

get_dataFunction · 0.85

Calls 3

to_undirectedFunction · 0.90
GraphClass · 0.90
contiguousMethod · 0.80

Tested by

no test coverage detected