GNN for node regression task

I am working on GNN for node regression.

I create my graphs as follows :
nb_of_data_objects = 1000
for i in range(nb_of_data_objects):
# Define edge indices
edge_indices = ……
# Define target values
target_values = ……
# Define node_features
node_features = ……
# Create the Data object
data = Data(x=node_features, edge_index=edge_indices, y=target_values)
print(“Data objects”, data_objects)

Then normalise and create data loader

Create a DataLoader for the training/testing data

train_loader = DataLoader(train_data, batch_size=64, shuffle=True)
test_loader = DataLoader(test_data, batch_size=64, shuffle=False)

Is this the correct way to enter the training loop? Does the model takes one graph at a time? # Create the GNN model instance
model = GCNModel(1, hidden_size, 1, num_layers)

Define the loss function

criterion = nn.L1Loss(reduction=‘none’)

Define the optimizer

optimizer = optim.Adam(model.parameters(), lr=lr)

Training loop

for epoch in range(num_epochs):
print (“epoch”, epoch)
running_loss = 0.0
total_nodes = 0
for batch_idx, data_batch in enumerate(train_loader):
for epoch in range(num_epochs):
running_loss = 0.0
for batch_idx, data_batch in enumerate(train_loader):

are you construct a single DGLGraph or multiple DGLGraphs? What’s the DataObject? Here’s an example of GCN full graph train: For mini-batch training with DataLoader, please refer to 6.1 Training GNN for Node Classification with Neighborhood Sampling — DGL 1.1.2 documentation. During iteration on DataLoader, each mini-batch is a subgraph sampled from original one.

1 Like

Thank you for your answer. I am using Pytorch library to construct graphs. Yes, multiple graphs.
For data object: To train a GNN model, you need to transform a graph into a certain data structure called “data object” to feed it to the model.

Are you using — pytorch_geometric documentation?

Yes, this is exactly what I am using

Perhaps you could post this question to their forum.