Open Z-Rajaei opened 4 years ago
You can, of course, make use of TUDataset
loading mechanisms, but personally I would always process the data by myself (just for easier debugging and ensuring everything works as intended). Since your task is graph-classification, I do not fully-understand your network architecture. There seeems to be some kind of global aggregation missing that aggregates node features to global graph features.
I used TUDataset because it is very similar to my input data.
I have some graphs, each node has some attributes (the attributes are not the same in all nodes, for example node 1 has 2 attributes of the total 8 attributes, node 2 has 4 attributes of the total 8 attributes, ...). nodes and edges have labels. The graph classification is done according to the attributes of nodes and the label of nodes and edges.
I didn't understand your last sentence! Could you tell me what the error is for?
class Net(torch.nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = GCNConv(dataset.num_node_features, 4)
self.conv2 = GCNConv(4, 4)
self.lin = torch.nn.Linear(4, dataset.num_classes)
def forward(self, data):
x, edge_index, batch = data.x, data.edge_index, data.batch
x = self.conv1(x, edge_index)
x = F.relu(x)
x = F.dropout(x, training=self.training)
x = self.conv2(x, edge_index)
x = F.relu(x)
x = global_mean_pool(x, batch)
x = self.lin(x)
return F.log_softmax(x, dim=1)
Thank you very much!!!!! It works.
the result is as the following: Epoch: 001, Loss: 0.68808, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 002, Loss: 0.67881, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 003, Loss: 0.67722, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 004, Loss: 0.67096, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 005, Loss: 0.66708, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 006, Loss: 0.66639, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 007, Loss: 0.65875, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 008, Loss: 0.65206, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 009, Loss: 0.64866, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 010, Loss: 0.63805, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 011, Loss: 0.63464, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 012, Loss: 0.63463, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 013, Loss: 0.62172, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 014, Loss: 0.62425, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 015, Loss: 0.60330, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 016, Loss: 0.59983, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 017, Loss: 0.57610, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 018, Loss: 0.56826, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 019, Loss: 0.56400, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 020, Loss: 0.54949, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 021, Loss: 0.54285, Train Acc: 0.57143, Test Acc: 0.28571 Epoch: 022, Loss: 0.51800, Train Acc: 0.64286, Test Acc: 0.57143 Epoch: 023, Loss: 0.48245, Train Acc: 0.68571, Test Acc: 0.71429 Epoch: 024, Loss: 0.49753, Train Acc: 0.74286, Test Acc: 0.71429 Epoch: 025, Loss: 0.47759, Train Acc: 0.91429, Test Acc: 0.85714 Epoch: 026, Loss: 0.44741, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 027, Loss: 0.43629, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 028, Loss: 0.43012, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 029, Loss: 0.37574, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 030, Loss: 0.38201, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 031, Loss: 0.36425, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 032, Loss: 0.36529, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 033, Loss: 0.34476, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 034, Loss: 0.31921, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 035, Loss: 0.33876, Train Acc: 0.92857, Test Acc: 0.85714 Epoch: 036, Loss: 0.28582, Train Acc: 0.94286, Test Acc: 1.00000 Epoch: 037, Loss: 0.30076, Train Acc: 0.97143, Test Acc: 1.00000 Epoch: 038, Loss: 0.27581, Train Acc: 0.97143, Test Acc: 1.00000 Epoch: 039, Loss: 0.26290, Train Acc: 0.97143, Test Acc: 1.00000 Epoch: 040, Loss: 0.25185, Train Acc: 0.97143, Test Acc: 1.00000 Epoch: 041, Loss: 0.22169, Train Acc: 0.97143, Test Acc: 1.00000 Epoch: 042, Loss: 0.21283, Train Acc: 0.97143, Test Acc: 1.00000 Epoch: 043, Loss: 0.21101, Train Acc: 1.00000, Test Acc: 1.00000 Epoch: 044, Loss: 0.19844, Train Acc: 1.00000, Test Acc: 1.00000 Epoch: 045, Loss: 0.22333, Train Acc: 1.00000, Test Acc: 1.00000 Epoch: 046, Loss: 0.18416, Train Acc: 1.00000, Test Acc: 1.00000 Epoch: 047, Loss: 0.19532, Train Acc: 1.00000, Test Acc: 1.00000 Epoch: 048, Loss: 0.16506, Train Acc: 1.00000, Test Acc: 1.00000 Epoch: 049, Loss: 0.17910, Train Acc: 1.00000, Test Acc: 1.00000 Epoch: 050, Loss: 0.18781, Train Acc: 1.00000, Test Acc: 1.00000
Does it show that my model works as well? Is it reliable?
❓ Questions & Help
Hello, I'm trying to learn pytorch geometric, you have helped me a lot before and I'm thankful. I need your help to know if the way I am following is right or not. I have some graphs, including nodes and edges. There is 8 attributes for the nodes. Each node has some of these attributes with a value for it. I want to do classification of the graphs. I created my dataset like the tu-dataset: there is some files including: MM_A.txt 1, 2 2, 1 1, 3 3, 1 1, 4 4, 1 5, 6 6, 5 5, 7 7, 5 ...
MM_edge_labels.txt 0 0 0 0 1 1 0 ...
MM_graph_indicator.txt 1 1 1 1 2 2 ...
MM_graph_labels.txt 0 1 0 1 0 0 0 0 ...
MM_node_attributes.txt 1, 0, 0, 0, 0, 0, 0, 0
0, 0, 1, 5, 1, 0, 0, 0
0, 0, 1, 8, 3, 0, 0, 0
0, 0, 0, 0, 0, 1, 1, 1
1, 1, 0, 0, 0, 0, 0, 0
0, 0, 1, 10, 3, 0, 0, 0 0, 0, 1, 5, 3, 0, 0, 0
...
MM_node_labels.txt 0 1 1 2 0 1 ...
Here is the code to create the dataset and learning:
``
``
In the first place, I want to know if the way I created my input files and the dataset and laerning process is true or not. And second, I encounter the following error: ValueError: Expected input batch_size (256) to match target batch_size (70).
please help me know that the way I'm following is right or not, and how to overcome the error.