0
$\begingroup$

I'm currently working on a system that predicts energy consumption of a set of buildings using graph convolutionals networks (GCN), which is a Graph-Level regression task (1 prediction for every subset of buildings represented as a graph). However, I don't find any existing implementation / tutorial on how to do this type of tasks in Py Geometric, DGL, and StellarGraph libraries.

Some Stackoverflow Questions and Github Issues mentioned to add a linear layer without any activation function at the end of the model's class to achieve this. However, I'm still unsure that it's the right thing to do especially that I don't get clear signs of convergence in the loss.

Here is my current code that I toke from here:

class GNN(torch.nn.Module):
def __init__(self, hidden_channels):
    super(GNN, self).__init__()
    # Multiply hidden_channels to scale up the network size
    self.hidden_channels_gcn = hidden_channels * 2
    self.hidden_channels_gat = self.hidden_channels_gcn * 2 
    self.hidden_channels_gin = self.hidden_channels_gat * 2         
    # Assuming layers are defined as before
    self.conv1 = None
    self.conv2 = GCNConv(self.hidden_channels_gcn, self.hidden_channels_gcn)
    self.gat_conv1 = GATConv(self.hidden_channels_gcn, self.hidden_channels_gat)
    self.gat_conv2 = GATConv(self.hidden_channels_gat, self.hidden_channels_gat)

    mlp = torch.nn.Sequential(
        torch.nn.Linear(self.hidden_channels_gat, self.hidden_channels_gin),
        torch.nn.ReLU(),
        torch.nn.Linear(self.hidden_channels_gin, self.hidden_channels_gin)
    )
    self.gin_conv1 = GINConv(mlp)
    self.out = torch.nn.Linear(self.hidden_channels_gin, 1)

def forward(self, x, edge_index, batch):
    # Dynamic creation of the first GCNConv layer
    if self.conv1 is None:
        self.conv1 = GCNConv(x.size(1), self.hidden_channels_gcn).to(x.device)
    
    x = F.relu(self.conv1(x, edge_index))
    x = F.relu(self.conv2(x, edge_index))
    x = F.relu(self.gat_conv1(x, edge_index))
    x = F.relu(self.gat_conv2(x, edge_index))
    x = F.relu(self.gin_conv1(x, edge_index))

    # Aggregating to graph-level feature
    x = pyg_nn.global_mean_pool(x, batch)  # Pooling node features to the graph level

    x = self.out(x)
    return x

Does someone know how to deal with this situation?

$\endgroup$
1
  • $\begingroup$ Can you please put your specific question in your title? It's not fully clear what you're asking here. $\endgroup$
    – nbro
    Commented Apr 22 at 13:31

0

You must log in to answer this question.

Browse other questions tagged .