Nodes features and edges labels from a DGLBlock object

pls i want to extract the features of nodes and edge labels from a DGLBlock object.
namely my graph is heterogeneous.

G = dgl.heterograph({
        ('user', 'rates', 'item') : M.nonzero(),
        ('item', 'rated_by', 'user') : M.transpose().nonzero()})
G.nodes['user'].data['x'] = users_features
G.nodes['item'].data['x'] = items_features
G.edges['rates'].data['label'] = weights
G.edges['rated_by'].data['label'] = weights

and the DGLBlock object is obtained from

train_loader = dgl.dataloading.DataLoader(G, eids, sampler, batch_size=batch_size, shuffle=True, drop_last=False, num_workers=4)
for input_nodes, output_nodes, blocks in tqdm(valid_loader):
     .........................................

and thank you

Can you try block.edata[‘label’]?

I am not very sure whether you are asking for this or not, if this does not answer your question, please elaborate more here.

Now, after your suggestion block.edata[‘label’]the error I got is as follows:
AttributeError: ‘list’ object has no attribute ‘edata’

Can you provide the full code or maybe in colab, so that I can help you debug?

1 Like

thank you very much, i solved this problem… blocks was a list which contains several graph type elements [blocks[0] block[1] …block[n]] .
we must access each block by blocks[i].edata['label'].

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.