Model with simple heterodata throws IndexError #4336
Answered
by
rusty1s
tristen-tooming
asked this question in
Q&A
-
Pytorch-geometric: 2.0.5 With data: data: HeteroData(
machine_0={ x=[1] },
machine_1={ x=[1] },
machine_2={ x=[1] },
(machine_0, edge_0, machine_1)={ edge_index=[2, 1] },
(machine_1, edge_1, machine_2)={ edge_index=[2, 1] },
(machine_1, rev_edge_0, machine_0)={ edge_index=[2, 1] },
(machine_2, rev_edge_1, machine_1)={ edge_index=[2, 1] }
)
edge_index_dict: {
('machine_0', 'edge_0', 'machine_1'): tensor([[0], [1]]),
('machine_1', 'edge_1', 'machine_2'): tensor([[1], [2]]),
('machine_1', 'rev_edge_0', 'machine_0'): tensor([[1], [0]]),
('machine_2', 'rev_edge_1', 'machine_1'): tensor([[2], [1]])} and model defined as: class GNN(torch.nn.Module):
def __init__(self, hidden_channels, out_channels):
super().__init__()
self.conv1 = SAGEConv((-1, -1), hidden_channels)
self.conv2 = SAGEConv((-1, -1), out_channels)
def forward(self, x, edge_index):
x = self.conv1(x, edge_index).relu()
x = self.conv2(x, edge_index)
return x
model = GNN(hidden_channels=32, out_channels=1)
model = to_hetero(model, data.metadata(), aggr='sum')
data, model = data.to(device), model.to(device)
with torch.no_grad(): # Initialize lazy modules.
out = model(data.x_dict, data.edge_index_dict) the code produces an IndexError in line [/usr/local/lib/python3.7/dist-packages/torch/fx/graph_module.py](https://localhost:8080/#) in wrapped_call(self, *args, **kwargs)
614 print(generate_error_message(topmost_framesummary),
615 file=sys.stderr)
--> 616 raise e.with_traceback(None)
617
618 cls.__call__ = wrapped_call
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got -2) The scenario is simple but I don't have a clue why the error is thrown. Could you help a bit to to get the |
Beta Was this translation helpful? Give feedback.
Answered by
rusty1s
Mar 25, 2022
Replies: 1 comment 3 replies
-
Can you convert your node features to be two-dimensional ( data['machine_0'].x = data['machine_0'].x.view(1, 1)
data['machine_1'].x = data['machine_1'].x.view(1, 1)
data['machine_2'].x = data['machine_2'].x.view(1, 1) |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
tristen-tooming
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you convert your node features to be two-dimensional (
[num_nodes, num_features]
)? For example, via: