Skip to content
Discussion options

You must be logged in to vote

Modifying a dataset via dataset.data is not really recommended since this is only meant as an internal storage layer. For this to work, you also need to set the dataset.slices object, and reset caching:

import torch
from torch_geometric.datasets import WikiCS

dataset = WikiCS('/tmp/Wiki')
data = dataset[0]
dataset.data.ext_features = torch.randn(data.num_nodes, 128)
dataset.slices['ext_features'] = torch.tensor([0, data.num_nodes])
dataset._data_list = None  # Reset caching.
print(dataset[0])

A better way to do this is via transforms:

def add_features(data):
    data.ext_features = ... # Add your features

dataset = WikiCS('/tmp/Wiki', transform=add_features)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@sidhantls
Comment options

@sidhantls
Comment options

@rusty1s
Comment options

Answer selected by sidhantls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants