MNISTSuperPixelDatasetΒΆ
-
class
dgl.data.
MNISTSuperPixelDataset
(raw_dir=None, split='train', use_feature=False, force_reload=False, verbose=False, transform=None)[source]ΒΆ Bases:
dgl.data.superpixel.SuperPixelDataset
MNIST superpixel dataset for the graph classification task.
DGL dataset of MNIST and CIFAR10 in the benchmark-gnn which contains graphs converted fromt the original MINST and CIFAR10 images.
Reference http://arxiv.org/abs/2003.00982
Statistics:
Train examples: 60,000
Test examples: 10,000
Size of dataset images: 28
- Parameters
raw_dir (str) β Directory to store all the downloaded raw datasets. Default: β~/.dgl/β.
split (str) β Should be chosen from [βtrainβ, βtestβ] Default: βtrainβ.
use_feature (bool) β
True: Adj matrix defined from super-pixel locations + features
False: Adj matrix defined from super-pixel locations (only)
Default: False.
force_reload (bool) β Whether to reload the dataset. Default: False.
verbose (bool) β Whether to print out progress information. Default: False.
transform (callable, optional) β A transform that takes in a
DGLGraph
object and returns a transformed version. TheDGLGraph
object will be transformed before every access.
Examples
>>> from dgl.data import MNISTSuperPixelDataset
>>> # MNIST dataset >>> train_dataset = MNISTSuperPixelDataset(split="train") >>> len(train_dataset) 60000 >>> graph, label = train_dataset[0] >>> graph Graph(num_nodes=71, num_edges=568, ndata_schemes={'feat': Scheme(shape=(3,), dtype=torch.float32)} edata_schemes={'feat': Scheme(shape=(1,), dtype=torch.float32)})
>>> # support tensor to be index when transform is None >>> # see details in __getitem__ function >>> import torch >>> idx = torch.tensor([0, 1, 2]) >>> train_dataset_subset = train_dataset[idx] >>> train_dataset_subset[0] Graph(num_nodes=71, num_edges=568, ndata_schemes={'feat': Scheme(shape=(3,), dtype=torch.float32)} edata_schemes={'feat': Scheme(shape=(1,), dtype=torch.float32)})
-
__getitem__
(idx)ΒΆ Get the idx-th sample.
- Parameters
idx (int or tensor) β The sample index. 1-D tensor as idx is allowed when transform is None.
- Returns
(
dgl.DGLGraph
, Tensor) β Graph with node feature stored infeat
field and its label.or
dgl.data.utils.Subset
β Subset of the dataset at specified indices
-
__len__
()ΒΆ The number of examples in the dataset.