Collate gives index out of range when iterating over dataloader in pytorch geometric #3301
LarsDoorenbos
started this conversation in
General
Replies: 1 comment 5 replies
-
How do you save your graphs? The following works for me: from torch_geometric.data import Data
from torch_geometric.loader import DataLoader
import torch
import pickle
def load_obj(name):
with open(name + '.pkl', 'rb') as f:
return pickle.load(f)
# Toy data
edge_index = torch.tensor([[0, 1], [1, 0], [1, 2], [2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
graph1 = Data(x=x, edge_index=edge_index.t().contiguous())
graph2 = Data(x=x, edge_index=edge_index.t().contiguous())
print(graph1)
print(graph2)
data_list = [graph1, graph2]
loader = DataLoader(data_list, batch_size=32)
print(next(iter(loader)))
with open('train0.pkl', 'wb') as f:
pickle.dump(data_list, f)
#Own data:
train_graphs1 = load_obj('train0')
graph1 = train_graphs1[0]
graph2 = train_graphs1[1]
print(graph1)
print(graph2)
data_list = [graph1, graph2]
loader = DataLoader(data_list, batch_size=32)
print(next(iter(loader))) |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to use a dataloader with graphs I load in. When using this with toy data it works, but with the loaded data it does not. Both times the graphs are Data objects, the only difference is added attributes. Why does this raise an error in the collate function?
This gives:
Beta Was this translation helpful? Give feedback.
All reactions