-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_dataset.py
48 lines (37 loc) · 1.34 KB
/
graph_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
# graph_dataset
import os
import torch
from torch_geometric.data import Dataset
class VideoGraphDataset(Dataset):
def __init__(self, root_dir, transform=None, pre_transform=None, pre_filter=None):
self.root_dir = root_dir
self.file_list = [f for f in os.listdir(root_dir) if f.endswith('.pt')]
self.graphs = []
for file in self.file_list:
file_path = os.path.join(self.root_dir, file)
graphs_in_file = torch.load(file_path)
self.graphs.extend([graph for graph in graphs_in_file if graph is not None])
super(VideoGraphDataset, self).__init__(root_dir, transform, pre_transform, pre_filter)
@property
def raw_file_names(self):
return self.file_list
@property
def processed_file_names(self):
return self.file_list
def download(self):
# Implement download logic if necessary
pass
def process(self):
# Implement process logic if necessary
pass
def len(self):
return len(self.graphs)
def get(self, idx):
return self.graphs[idx]
@property
def num_features(self):
return self._get_num_features()
def _get_num_features(self):
if len(self.graphs) > 0:
return 18 # self.graphs[0].x.shape[1] # Get the feature dimension from the first graph
return 0