Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when loading datasets from the torch_geometric.dataset package #7124

Closed
TNodeCode opened this issue Apr 5, 2023 · 2 comments · Fixed by #7141
Closed

Error when loading datasets from the torch_geometric.dataset package #7124

TNodeCode opened this issue Apr 5, 2023 · 2 comments · Fixed by #7141
Labels

Comments

@TNodeCode
Copy link

🐛 Describe the bug

Hello community,

when I try to load a dataset from the torch_geometric.datasetspackage I get an error.

This is my code:

from torch_geometric.datasets import Planetoid

dataset = Planetoid(root="./data", name='Cora')

I am using PyTorch version 2.0.0+cu117 and torch_geometric version 2.3.0

And this is the error I get:

Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.x
Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.tx
Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.allx
Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.y
Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.ty
Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.ally
Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.graph
Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.test.index
Processing...
----------------------------------------------------------------
ValueError                     Traceback (most recent call last)
Input In [11], in <cell line: 2>()
      1 # Download the 'Cora' dataset and cache it in the local './data' directory
----> 2 dataset = Planetoid(root="./data", name='Cora')

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\torch_geometric\datasets\planetoid.py:92, in Planetoid.__init__(self, root, name, split, num_train_per_class, num_val, num_test, transform, pre_transform)
     89 self.split = split.lower()
     90 assert self.split in ['public', 'full', 'geom-gcn', 'random']
---> 92 super().__init__(root, transform, pre_transform)
     93 self.data, self.slices = torch.load(self.processed_paths[0])
     95 if split == 'full':

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\torch_geometric\data\in_memory_dataset.py:57, in InMemoryDataset.__init__(self, root, transform, pre_transform, pre_filter, log)
     49 def __init__(
     50     self,
     51     root: Optional[str] = None,
   (...)
     55     log: bool = True,
     56 ):
---> 57     super().__init__(root, transform, pre_transform, pre_filter, log)
     58     self._data = None
     59     self.slices = None

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\torch_geometric\data\dataset.py:97, in Dataset.__init__(self, root, transform, pre_transform, pre_filter, log)
     94     self._download()
     96 if self.has_process:
---> 97     self._process()

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\torch_geometric\data\dataset.py:230, in Dataset._process(self)
    227     print('Processing...', file=sys.stderr)
    229 makedirs(self.processed_dir)
--> 230 self.process()
    232 path = osp.join(self.processed_dir, 'pre_transform.pt')
    233 torch.save(_repr(self.pre_transform), path)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\torch_geometric\datasets\planetoid.py:150, in Planetoid.process(self)
    149 def process(self):
--> 150     data = read_planetoid_data(self.raw_dir, self.name)
    152     if self.split == 'geom-gcn':
    153         train_masks, val_masks, test_masks = [], [], []

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\torch_geometric\io\planetoid.py:21, in read_planetoid_data(folder, prefix)
     19 def read_planetoid_data(folder, prefix):
     20     names = ['x', 'tx', 'allx', 'y', 'ty', 'ally', 'graph', 'test.index']
---> 21     items = [read_file(folder, prefix, name) for name in names]
     22     x, tx, allx, y, ty, ally, graph, test_index = items
     23     train_index = torch.arange(y.size(0), dtype=torch.long)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\torch_geometric\io\planetoid.py:21, in <listcomp>(.0)
     19 def read_planetoid_data(folder, prefix):
     20     names = ['x', 'tx', 'allx', 'y', 'ty', 'ally', 'graph', 'test.index']
---> 21     items = [read_file(folder, prefix, name) for name in names]
     22     x, tx, allx, y, ty, ally, graph, test_index = items
     23     train_index = torch.arange(y.size(0), dtype=torch.long)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\torch_geometric\io\planetoid.py:106, in read_file(folder, prefix, name)
    103     return out
    105 out = out.todense() if hasattr(out, 'todense') else out
--> 106 out = torch.Tensor(out)
    107 return out

ValueError: too many dimensions 'matrix'

Environment

  • PyG version: 2.3.0
  • PyTorch version: 2.0.0+cu117
  • OS: Windows 11
  • Python version: 3.10.6
  • CUDA/cuDNN version: 11.4
  • How you installed PyTorch and PyG (conda, pip, source): pip
  • Any other relevant information (e.g., version of torch-scatter):
    torch_scatter-2.1.1+pt20cpu
    torch_sparse-0.6.17+pt20cpu
    torch_spline_conv-1.2.2+pt20cpu
@TNodeCode TNodeCode added the bug label Apr 5, 2023
@EdisonLeeeee
Copy link
Contributor

Thanks for reporting. We should use torch.tensor rather than torch.Tensor here.

@rusty1s
Copy link
Member

rusty1s commented Apr 9, 2023

I fixed this in #7141. Can you please confirm that this works for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants