Raise DGLError('Expect number of features to match number of nodes (len(u)).' dgl._ffi.base.DGLError: Expect number of features to match number of nodes (len(u)). Got 1316 and 1322 instead

I have graph g and nodes list, I have created subgraph
sg = dgl.edge_subgraph(g, nodes)
eid = sg.edata[EID]
block = to_block(sg, seed_nodes)
block.edata[EID] = eid
seed_nodes = block.srcdata[NID]
blocks.insert(0, block)
return seed_nodes, output_nodes, blocks

Giving error while running
def forward(self, blocks, x):
h = x
for l, (layer, block) in enumerate(zip(self.layers, blocks)):
h = layer(block, h)
if l != len(self.layers) - 1:
h = F.relu(h)
h = self.dropout(h)
return h

def evaluate(model, graph, dataloader, num_classes):
model.eval()
ys = []
y_hats = []
for it, (input_nodes, output_nodes, blocks) in enumerate(dataloader):
with torch.no_grad():
x = blocks[0].srcdata[“feat”]
ys.append(blocks[-1].dstdata[“label”])
y_hats.append(model(blocks, x))
return MF.accuracy(
torch.cat(y_hats),
torch.cat(ys),
task=“multiclass”,
num_classes=num_classes,
)

I believe the problem may arise from mishandling the correspondence between the number of nodes in different blocks when passing messages between them. You can use print(blocks) to check and verify this.

I also agree with @BearBiscuit05. You may need to carefully check where the blocks[0].srcdata[“feat”] from and its shape.

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