Open miso47 opened 1 year ago
When I changed the convolution type to SAGEConv, i.e the model is:
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), hidden_channels)
self.fc1 = Linear(hidden_channels, out_channels)
def forward(self, x, edge_index,edge_weight):
x = self.conv1(x, edge_index,edge_weight).relu()
Vector = self.conv2(x, edge_index,edge_weight).relu()
x = self.fc1(Vector)
return x,Vector
model = GNN(hidden_channels=64, out_channels=2)
model = to_hetero(model, data_indicator.metadata(), aggr='sum')
print(model)
the error has changed to:
ValueError: Encountered tensor with size 55 in dimension -2, but expected size 0.03999999910593033
Hi there!
I wanted to try and reproduce this error, but I don't think you mention the data you are using. I assume it is a custom dataset. It would really help if you could provide a sample of that data, even only the first 5 nodes for each type, and some of the edges connecting them.
I still tried with a random dataset sample that follows your metadata schema, but I cannot assure you that it has the same behavior. (feature & node numbers are chosen arbitrarily for example)
Indeed I do not have any trouble running my code, although with a more recent version of both PyTorch and PyG.
Your version of PyTorch (1.9.0) seems quite outdated. The installation guide for PyG mentions that version 1.12.0 at least should be installed to use the current version without additional care. Did you check if the problem persisted with a newer version of PyTorch? Maybe you should try checking with that first if this is possible for you to upgrade the version.
Here is the sample I used, if that can help you spot a potential mistake:
from torch_geometric.nn import SAGEConv, to_hetero
from torch.nn import Linear
import torch
from torch_geometric.data import (
HeteroData,
)
from torch_geometric.loader import DataLoader
metadata = (['circuit_element', 'junction'], [('junction', 'wire', 'junction'), ('junction', 'wire', 'circuit_element')])
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), hidden_channels)
self.fc1 = Linear(hidden_channels, out_channels)
def forward(self, x, edge_index,edge_weight):
x = self.conv1(x, edge_index,edge_weight).relu()
Vector = self.conv2(x, edge_index,edge_weight).relu()
x = self.fc1(Vector)
return x,Vector
model = GNN(hidden_channels=64, out_channels=2)
model = to_hetero(model, metadata, aggr='sum')
# Create test data respecting the given metadata schema.
data = HeteroData()
data['circuit_element'].x = torch.rand((5, 8)) # 5 nodes, 8 feature each
data['junction'].x = torch.rand((5, 4)) # 5 nodes, 4 features each
test_edges = torch.sparse.Tensor([[0, 1], [1, 3]]).int()
data[('junction', 'wire', 'junction')].edge_index = test_edges # Some edge between nodes
data[('junction', 'wire', 'circuit_element')].edge_index = test_edges # Some edge between nodes
# Try and run the model with a dataloader.
train_loader = DataLoader([data])
for batch in train_loader:
model(batch.x_dict, batch.edge_index_dict, batch.edge_weight_dict)
🐛 Describe the bug
I am having this issue with my model as
The print out of data.metadata() is
(['circuit_element', 'junction'], [('junction', 'wire', 'junction'), ('junction', 'wire', 'circuit_element')])
However, I am getting this error when trying to train the model using a dataloader. The train code is:
The error message is cumbersome and leaves me clueless. The error printout is:
Environment
conda
,pip
, source):torch-scatter
):