Multiple edge attributes
See original GitHub issueFrom now on, we recommend using our discussion forum (https://github.com/rusty1s/pytorch_geometric/discussions) for general questions.
❓ Questions & Help
I use GraphConv
layers in my model. My graph is represented as follows:
Data(edge_attr=[1357, 2], edge_index=[2, 1357], test_mask=[943], train_mask=[943], val_mask=[943], x=[943, 7], y=[943])
From the edge_attr
we see that I have 2 features per edge. When I propagate my data through the model, I receive an error:
RuntimeError Traceback (most recent call last)
<ipython-input-102-8bd3fc340e4f> in <module>
1 model = GraphConvClass(data_for_train, hidden_channels=16)
----> 2 out = model(data_for_train.x, data_for_train.edge_index, data_for_train.edge_attr)
3
4 visualize(out, color=data_for_train.y)
~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
<ipython-input-82-1825ffb98b68> in forward(self, x, edge_index, edge_weight)
15
16 def forward(self, x, edge_index, edge_weight): # Define forward propagation path
---> 17 x = self.conv1(x, edge_index, edge_weight)
18 x = x.relu()
19 x = self.conv2(x, edge_index, edge_weight)
~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
~\anaconda3\lib\site-packages\torch_geometric\nn\conv\graph_conv.py in forward(self, x, edge_index, edge_weight, size)
60
61 # propagate_type: (x: OptPairTensor, edge_weight: OptTensor)
---> 62 out = self.propagate(edge_index, x=x, edge_weight=edge_weight,
63 size=size)
64 out = self.lin_l(out)
~\anaconda3\lib\site-packages\torch_geometric\nn\conv\message_passing.py in propagate(self, edge_index, size, **kwargs)
235
236 msg_kwargs = self.inspector.distribute('message', coll_dict)
--> 237 out = self.message(**msg_kwargs)
238
239 # For `GNNExplainer`, we require a separate message and aggregate
~\anaconda3\lib\site-packages\torch_geometric\nn\conv\graph_conv.py in message(self, x_j, edge_weight)
71
72 def message(self, x_j: Tensor, edge_weight: OptTensor) -> Tensor:
---> 73 return x_j if edge_weight is None else edge_weight.view(-1, 1) * x_j
74
75 def message_and_aggregate(self, adj_t: SparseTensor,
RuntimeError: The size of tensor a (2714) must match the size of tensor b (1357) at non-singleton dimension 0
I guess the error says that the number of edge attributes > number of edges. In other words, I do not understand how to code 2 features per edge explicitly .
My edge_attr
looks like this:
tensor([[1.5888e-04, 3.3484e-01],
[1.3956e-04, 4.6317e-01],
[3.2826e-04, 2.5242e-01],
...,
[2.5134e-04, 3.2950e-01],
[1.1220e-03, 1.7618e-01],
[1.5108e-04, 2.3872e-01]])
Can somebody point me to the relevant example or to give a hint how to solve my problem?
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to define multiple attributes for an edge in multi Digraph
I have a graph with four nodes with two directional edges betweeen each node (a to b and b to a) ...
Read more >MultiGraph.edges — NetworkX 2.8.8 documentation
The MultiEdgeView provides set-like operations on the edge-tuples as well as edge attribute lookup. When called, it also provides an EdgeDataView object ...
Read more >Adding weighted edges with multiple attributes - Google Groups
be very appreciated. I have a large directed graph of unconnected nodes where I want to add edges. My edges are stored in...
Read more >How do multi-attribute edge-weights influence community ...
My graph consists of a computer network topology where each vertex is a physical node/device (depicted using its IP address). Two vertices will ......
Read more >Representing multiple edge attributes as a 3-D tensor
Download scientific diagram | Representing multiple edge attributes as a 3-D tensor from publication: Change Detection in Dynamic Attributed Networks | A ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think that issue has anything to do with
edge_attr
, as it failsl on transforming node features inquery = self.lin_query(x_i).view(-1, self.heads, self.out_channels)
. It looks like your node features have 20 features, whilein_channels
was set to2
. Can you confirm?@rusty1s Exactly! This solves my problem, thank you very much!