RuntimeError: 0D or 1D target tensor expected, multi-target not supported #6803
Answered
by
LukeLIN-web
LukeLIN-web
asked this question in
Q&A
-
I can train Reddit, yelp, but I don't know how to train the amazon dataset. class SAGE(torch.nn.Module):
def __init__(self, in_channels, hidden_channels, out_channels,
num_layers=2):
super(SAGE, self).__init__()
self.num_layers = num_layers
self.convs = torch.nn.ModuleList()
self.convs.append(SAGEConv(in_channels, hidden_channels))
for _ in range(self.num_layers - 2):
self.convs.append(SAGEConv(hidden_channels, hidden_channels))
self.convs.append(SAGEConv(hidden_channels, out_channels))
def forward(self, x, adjs):
for i, (edge_index, _, size) in enumerate(adjs):
x_target = x[:size[1]] # Target nodes are always placed first.
x = self.convs[i]((x, x_target), edge_index)
if i != self.num_layers - 1:
x = F.relu(x)
x = F.dropout(x, p=0.5, training=self.training)
return x.log_softmax(dim=-1) dataset = AmazonProducts('/data/AmazonProducts')
...
model = SAGE(data.num_features, 256, dataset.num_classes)
....
for seeds in train_loader:
optimizer.zero_grad()
n_id, batch_size, adjs = quiver_sampler.sample(seeds)
target_node = n_id[:len(seeds)]
out = model(x[n_id], adjs) # forward
# loss = F.nll_loss(out, y[target_node][:batch_size]) # reddit loss, can work.
# loss = F.cross_entropy(out, y[target_node][:batch_size]) #yelp loss ,can work
loss = F.nll_loss(out, y[target_node][:batch_size]) # amazon loss
loss.backward()
optimizer.step() It error is :
I tried ogbn-product, but also meet this problem. |
Beta Was this translation helpful? Give feedback.
Answered by
LukeLIN-web
Feb 27, 2023
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
LukeLIN-web
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
loss = F.cross_entropy(out, y[target_node][:batch_size].squeeze() ) # products loss