MCPcopy
hub / github.com/dmlc/dgl / process

Method process

python/dgl/data/yelp.py:88–129  ·  view source on GitHub ↗

process raw data to graph, labels and masks

(self)

Source from the content-addressed store, hash-verified

86 )
87
88 def process(self):
89 """process raw data to graph, labels and masks"""
90 coo_adj = sp.load_npz(os.path.join(self.raw_path, "adj_full.npz"))
91 g = from_scipy(coo_adj)
92
93 features = np.load(os.path.join(self.raw_path, "feats.npy"))
94 features = F.tensor(features, dtype=F.float32)
95
96 y = [-1] * features.shape[0]
97 with open(os.path.join(self.raw_path, "class_map.json")) as f:
98 class_map = json.load(f)
99 for key, item in class_map.items():
100 y[int(key)] = item
101 labels = F.tensor(np.array(y), dtype=F.int64)
102
103 with open(os.path.join(self.raw_path, "role.json")) as f:
104 role = json.load(f)
105
106 train_mask = np.zeros(features.shape[0], dtype=bool)
107 train_mask[role["tr"]] = True
108
109 val_mask = np.zeros(features.shape[0], dtype=bool)
110 val_mask[role["va"]] = True
111
112 test_mask = np.zeros(features.shape[0], dtype=bool)
113 test_mask[role["te"]] = True
114
115 g.ndata["feat"] = features
116 g.ndata["label"] = labels
117 g.ndata["train_mask"] = generate_mask_tensor(train_mask)
118 g.ndata["val_mask"] = generate_mask_tensor(val_mask)
119 g.ndata["test_mask"] = generate_mask_tensor(test_mask)
120
121 if self._reorder:
122 self._graph = reorder_graph(
123 g,
124 node_permute_algo="rcmk",
125 edge_permute_algo="dst",
126 store_ids=False,
127 )
128 else:
129 self._graph = g
130
131 def has_cache(self):
132 graph_path = os.path.join(self.save_path, "dgl_graph.bin")

Callers

nothing calls this directly

Calls 6

from_scipyFunction · 0.85
generate_mask_tensorFunction · 0.85
reorder_graphFunction · 0.85
joinMethod · 0.45
loadMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected