Batched Graph Classification - Overwriting of features

#1

Hi,

In am reusing the “batched graph classification” example for my own experiments. However I have a concern about the possibility of overwriting the node features across epochs . I replaced the line looking at degree with, the features I had assigned to the graph earlier

h=g.ndata[‘h’]

However, my question is does the features (‘h’) get overwritten every time across epochs? I had assumed at the start of each epoch it starts with the initial features, but looking back at the example GCN example for the cora dataset it looks like you set the features for the graph during each iteration of the epoch ? is that what i am suppose to do.

Thanks
Maruthi

#2

Hi Maruthi,

This depends on which g you are referring to. If you are always using same BatchedDGLGraph objects, then the node features can easily be overwritten. Alternatively, if BatchedDGLGraph objects are created from dataloader for each iteration like with the collate function below, then you will be okay.

def collate(samples):
    # The input `samples` is a list of pairs
    #  (graph, label).
    graphs, labels = map(list, zip(*samples))
    batched_graph = dgl.batch(graphs)
    return batched_graph, torch.tensor(labels)

With dgl.batch, new BatchedDGLGraph objects are created and they are independent of the old batches you used for previous epochs.