pyg-team / pytorch_geometric

Graph Neural Network Library for PyTorch
https://pyg.org
MIT License
21.48k stars 3.68k forks source link

asking for the architecture GNN model #5230

Open tayssirmoussa66 opened 2 years ago

tayssirmoussa66 commented 2 years ago

🐛 Describe the bug

i'm building a GNN model using pytorch geometric for multicalssifiction of molécule edges. this is the code model.

`class GCN(torch.nn.Module):

def __init__(self, feature_size, n_layers, embedding_size, n_heads):
    super().__init__()

    self.layers = torch.nn.ModuleList()

    # construct input layer
    self.layers.append(GraphConv(feature_size, embedding_size))
    # construct hidden layers
    for i in range(n_layers -1):
        self.layers.append(GraphConv(embedding_size, embedding_size))

    self.att_layer = GATConv(embedding_size, embedding_size,heads=n_heads, 
                                )

    self.linear1 = Linear(embedding_size, feature_size)

    self.Linear2 = Linear(embedding_size*n_heads, embedding_size)
    self.Linear3 = Linear(embedding_size*2, embedding_size)

    self.out_Layer= MLP(in_channels=feature_size*2, hidden_channels=10,
      out_channels=5, num_layers=6)

def forward(self, x, edge_weight, edge_index):
    #Local embeddings 
    for layer in self.layers:
        x = layer( x, edge_index, edge_weight)
        x = F.relu(x)

     #attention layer

    y = self.att_layer(x, edge_index)
    y = F.elu(self.Linear2(y))
    y = F.dropout(y, p=0.6, training=self.training)

    #Global embeddings
    Global = F.log_softmax(y, dim=1)
    concat_vector = torch.cat([x, Global], 1)
    concat_vector=self.Linear3(concat_vector)

    x = self.linear1 (concat_vector)

    out = self.out_Layer(torch.cat([x[edge_index[0]], x[edge_index[1]]], dim=-1))

    return out
   `

'loss_fn= torch.nn.CrossEntropyLoss() model = GCN(feature_size=7, n_layers=10, embedding_size=10, n_heads=3) model.to(device) optimizer = AdamW(model.parameters(), lr = 10e-3 )'

during the training the accurracy does'nt increase , it still at 0.4, i tried to change the hyperparameters but it still weak . i think the problem is from the architecture of the model. any help please !

Environment

rusty1s commented 2 years ago

I think your architecture looks good, but I would start with something more simpler, e.g., not using attention and not using the log_softmax within the model.