forked from rampasek/GraphGPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mirror.py
55 lines (45 loc) · 1.59 KB
/
mirror.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
import fsspec
import io
import os.path as osp
import pickle
import shutil
import torch
from torch_geometric.data import InMemoryDataset, Data
def torch_save(data, path) -> None:
buffer = io.BytesIO()
torch.save(data, buffer)
with fsspec.open(path, 'wb') as f:
f.write(buffer.getvalue())
def torch_load(path):
with fsspec.open(path, 'rb') as f:
return torch.load(f)
class Mirror(InMemoryDataset):
def __init__(self, root):
super().__init__(root)
path = osp.join(self.processed_dir, self.processed_file_names[0])
self.load(path)
def download(self):
src = "/nobackup/vbalivada/GraphGPS/cs762/mirror.pkl"
dst = osp.join(self.raw_dir, "mirror.pkl")
shutil.copy(src, dst)
@property
def raw_file_names(self):
return ['r3.pkl']
@property
def processed_file_names(self):
return ['p3.pt']
def process(self):
with open(osp.join(self.raw_dir, "mirror.pkl"), "rb") as f:
graphs = pickle.load(f)
self.save(self.__class__, graphs, osp.join(self.processed_dir, self.processed_file_names[0]))
@staticmethod
def save(cls, data_list, path):
r"""Saves a list of data objects to the file path :obj:`path`."""
data, slices = cls.collate(data_list)
torch_save((data.to_dict(), slices), path)
def load(self, path):
r"""Loads the dataset from the file path :obj:`path`."""
data, self.slices = torch_load(path)
if isinstance(data, dict): # Backward compatibility.
data = Data.from_dict(data)
self.data = data