-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph_classification.py
46 lines (40 loc) · 1.21 KB
/
graph_classification.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
import numpy as np
#print(data.shape)
#print(labels.shape)
from cogdl import experiment
from cogdl.data import Graph
from cogdl.datasets import GraphDataset
import torch
class MyGraphDataset(GraphDataset):
def __init__(self, path="data.pt"):
self.path = path
super(MyGraphDataset, self).__init__(path, metric="accuracy")
def process(self):
data = np.load('PMI_data.npy')
labels = np.load('14EEG_EMG_pull_push_label.npy')
# Load and preprocess data
# Here we randomly generate several graphs for simplicity as an example
graphs = []
for i in range(labels.shape[0]):
edges = []
edge_weight = []
label = torch.tensor([labels[i]]).reshape(1,)
for j in range(40):
for k in range(40):
if data[i,j,k] > 0.5:
edges.append([j, k])
edge_weight.append(data[i,j,k])
edges = torch.tensor(edges).t()
edge_weight = torch.tensor(edge_weight)
print(edges)
print(edges.shape)
print(label.shape)
g = Graph(edge_index=edges, y=label)
g.edge_weight = edge_weight
graphs.append(g)
# break
return graphs
if __name__ == "__main__":
dataset = MyGraphDataset()
#dataset.process()
experiment(model="gin", dataset=dataset, cpu=True, epochs=100, train_ratio=0.8, test_ratio=0.2)