GCN node classification errors

I am trying to do section 3 of Google Colaboratory

However, there are two errors.When I try to train my model, I get an error for the loss function: multi-target not supported at /pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu:15.

The second error occurs when I change the hidden_dim back to 256, I get an error regarding the batch normalization.

How do I fix these problems?

This error is raised, if the shapes of the input tensors are unexpected, so make sure the model output has the shape [batch_size, nb_classes, *], while the target has the shape [batch_size, *] containing the class indicex in the range [0, nb_classes-1].
Here is a small code snippet showing the error:

batch_size, nb_classes = 2, 10
x = torch.randn(batch_size, nb_classes)
y = torch.randint(0, nb_classes, (batch_size,))
criterion = nn.CrossEntropyLoss()
loss = criterion(x, y)

y = torch.randint(0, nb_classes, (batch_size, nb_classes))
loss = criterion(x, y)
> RuntimeError: 1D target tensor expected, multi-target not supported

Still not sure how to fix this. My pred.shape is [169343, 40], my data.y shape is [169343, 1], where each entry in data.y is in [0, 39].

Remove the unnecessary dim1 from the target via .squeeze(1) and it should work.

1 Like