Extending forward method of geometric pytorch NN to accept a vector

21 views Asked by At

I am extending a NN from here to accept an input also a vector, along with a graph. This is the code of the original forward function.

def forward(self, data):
    x, edge_index, batch = data.x, data.edge_index, data.batch
    edge_attr = None

    x = F.relu(self.conv1(x, edge_index, edge_attr))
    x, edge_index, edge_attr, batch = self.pool1(x, edge_index, edge_attr, batch)
    x1 = torch.cat([gmp(x, batch), gap(x, batch)], dim=1)

    x = F.relu(self.conv2(x, edge_index, edge_attr))
    x, edge_index, edge_attr, batch = self.pool2(x, edge_index, edge_attr, batch)
    x2 = torch.cat([gmp(x, batch), gap(x, batch)], dim=1)

    x = F.relu(self.conv3(x, edge_index, edge_attr))
    x3 = torch.cat([gmp(x, batch), gap(x, batch)], dim=1)

    x = F.relu(x1) + F.relu(x2) + F.relu(x3)

    x = F.relu(self.lin1(x))
    x = F.dropout(x, p=self.dropout_ratio, training=self.training)
    x = F.relu(self.lin2(x))
    x = F.dropout(x, p=self.dropout_ratio, training=self.training)
    x = F.log_softmax(self.lin3(x), dim=-1)

return x

I have added a new entry to the dataset (called inputvec here).

Batch(batch=[109], edge_index=[2, 404], ptr=[13], inputvec=[12], x=[109, 4], y=[12])

as you can see the batch size is 12. In my new forward method I convert it to a tensor, and then I send it to a 1d convolutional layer (i.e. not for graphs)

    vector_input = torch.from_numpy(np.array(data.inputvec))  # Assuming skew is your additional input
    vector_out = F.relu(self.conv1dlayer(vector_input.unsqueeze(1)))  # Reshape for Conv1d

How can I send x1 and vector_out as input to the conv2()

0

There are 0 answers