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

Introduce pickle-agnostic save/load logic in Planetoid/TUDataset #7413

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `NodePropertySplit` transform for creating node-level splits using structural node properties ([#6894](https://github.com/pyg-team/pytorch_geometric/pull/6894))
- Added an option to preserve directed graphs in `CitationFull` datasets ([#7275](https://github.com/pyg-team/pytorch_geometric/pull/7275))
- Added support for `torch.sparse.Tensor` in `DataLoader` ([#7252](https://github.com/pyg-team/pytorch_geometric/pull/7252))
- Added `save` and `load` methods to `InMemoryDataset` ([#7250](https://github.com/pyg-team/pytorch_geometric/pull/7250))
- Added `save` and `load` methods to `InMemoryDataset` ([#7250](https://github.com/pyg-team/pytorch_geometric/pull/7250), [#7413](https://github.com/pyg-team/pytorch_geometric/pull/7413))
- Added an example for heterogeneous GNN explanation via `CaptumExplainer` ([#7096](https://github.com/pyg-team/pytorch_geometric/pull/7096))
- Added `visualize_feature_importance` functionality to `HeteroExplanation` ([#7096](https://github.com/pyg-team/pytorch_geometric/pull/7096))
- Added a `AddRemainingSelfLoops` transform ([#7192](https://github.com/pyg-team/pytorch_geometric/pull/7192))
Expand Down
4 changes: 2 additions & 2 deletions torch_geometric/datasets/planetoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, root: str, name: str, split: str = "public",
assert self.split in ['public', 'full', 'geom-gcn', 'random']

super().__init__(root, transform, pre_transform)
self.data, self.slices = torch.load(self.processed_paths[0])
self.load(self.processed_paths[0])

if split == 'full':
data = self.get(0)
Expand Down Expand Up @@ -162,7 +162,7 @@ def process(self):
data.test_mask = torch.stack(test_masks, dim=1)

data = data if self.pre_transform is None else self.pre_transform(data)
torch.save(self.collate([data]), self.processed_paths[0])
self.save([data], self.processed_paths[0])

def __repr__(self) -> str:
return f'{self.name}()'
13 changes: 10 additions & 3 deletions torch_geometric/datasets/tu_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

import torch

from torch_geometric.data import InMemoryDataset, download_url, extract_zip
from torch_geometric.data import (
Data,
InMemoryDataset,
download_url,
extract_zip,
)
from torch_geometric.io import read_tu_data


Expand Down Expand Up @@ -131,7 +136,8 @@ def __init__(self, root: str, name: str,
"If this error occurred while loading an already existing "
"dataset, remove the 'processed/' directory in the dataset's "
"root folder and try again.")
self.data, self.slices, self.sizes = out
data, self.slices, self.sizes = out
self.data = Data.from_dict(data) if isinstance(data, dict) else data

if self._data.x is not None and not use_node_attr:
num_node_attributes = self.num_node_attributes
Expand Down Expand Up @@ -199,7 +205,8 @@ def process(self):
self.data, self.slices = self.collate(data_list)
self._data_list = None # Reset cache.

torch.save((self._data, self.slices, sizes), self.processed_paths[0])
torch.save((self._data.to_dict(), self.slices, sizes),
self.processed_paths[0])

def __repr__(self) -> str:
return f'{self.name}({len(self)})'