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

Method process

python/dgl/data/superpixel.py:142–222  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

140 extract_archive(path, target_dir=self.raw_path, overwrite=True)
141
142 def process(self):
143 if self._dataset_name == "MNIST":
144 plk_file = "mnist_75sp"
145 elif self._dataset_name == "CIFAR10":
146 plk_file = "cifar10_150sp"
147
148 with open(
149 os.path.join(
150 self.raw_path, "superpixels", f"{plk_file}_{self.split}.pkl"
151 ),
152 "rb",
153 ) as f:
154 self.labels, self.sp_data = pickle.load(f)
155 self.labels = F.tensor(self.labels)
156
157 self.Adj_matrices = []
158 self.node_features = []
159 self.edges_lists = []
160 self.edge_features = []
161
162 for index, sample in enumerate(
163 tqdm(self.sp_data, desc=f"Processing {self.split} dataset")
164 ):
165 mean_px, coord = sample[:2]
166 coord = coord / self.img_size
167
168 if self.use_feature:
169 A = compute_adjacency_matrix_images(
170 coord, mean_px
171 ) # using super-pixel locations + features
172 else:
173 A = compute_adjacency_matrix_images(
174 coord, mean_px, False
175 ) # using only super-pixel locations
176 edges_list, edge_values_list = compute_edges_list(A)
177
178 N_nodes = A.shape[0]
179
180 mean_px = mean_px.reshape(N_nodes, -1)
181 coord = coord.reshape(N_nodes, 2)
182 x = np.concatenate((mean_px, coord), axis=1)
183
184 edge_values_list = edge_values_list.reshape(-1)
185
186 self.node_features.append(x)
187 self.edge_features.append(edge_values_list)
188 self.Adj_matrices.append(A)
189 self.edges_lists.append(edges_list)
190
191 for index in tqdm(
192 range(len(self.sp_data)), desc=f"Dump {self.split} dataset"
193 ):
194 N = self.node_features[index].shape[0]
195
196 src_nodes = []
197 dst_nodes = []
198 for src, dsts in enumerate(self.edges_lists[index]):
199 # handling for 1 node where the self loop would be the only edge

Callers

nothing calls this directly

Calls 7

compute_edges_listFunction · 0.85
appendMethod · 0.80
extendMethod · 0.80
joinMethod · 0.45
loadMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected