mindspore_gl.dataloader

Dataloader for graph networks.

class mindspore_gl.dataloader.Dataset[source]

Mappable Dataset Definition, an abstract class represent Dataset. All datasets should subclass it which represent a map relation from key to sample. All subclass should overwrite __getitem__, which implement fetch a sample given a key.

Supported Platforms:

Ascend GPU

Examples

>>> from mindspore_gl.dataloader import Dataset
>>> class MyDataset(Dataset):
>>>    def __init__(self, *args, **kwargs):
>>>         ...
>>> my_dataset = MyDataset()
class mindspore_gl.dataloader.RandomBatchSampler(data_source, batch_size)[source]

Random Batched Node Sampler, random sample nodes form graph. The remained sample will be dropped.

Parameters
  • data_source (Union[List, Tuple, Iterable]) – data source sample from.

  • batch_size (int) – number of sampling subgraphs per batch.

Raises

TypeError – If batch_size is not a positive integer.

Supported Platforms:

Ascend GPU

Examples

>>> from mindspore_gl.dataloader.samplers import RandomBatchSampler
>>> ds = list(range(10))
>>> sampler = RandomBatchSampler(ds, 3)
>>> print(list(sampler))
# results will be random for suffle
[[5, 9, 3], [4, 6, 7], [2, 8, 1]]
mindspore_gl.dataloader.split_data(x, val_ratio=0.05, test_ratio=0.1, graph_type='undirected')[source]

Cut the training set into training set, validation set and test set according to the proportion of user input, and perform graph reconstruction on the training set, and then return.

Parameters
  • x (mindspore_gl.dataloader.Dataset) – Graph Structured Dataset

  • val_ratio (float, optional) – Validation set proportion. Default: 0.05.

  • test_ratio (float, optional) – Test set proportion. Default: 0.1.

  • graph_type (str, optional) – The type of graph.’undirected’: undirected graph, ‘directed’: directed graph. Default: ‘undirected’.

Returns

  • train (numpy.ndarray) - Train set positive examples, shape \((train\_len, 2)\) .

  • val (numpy.ndarray) - Validation set positive example, shape \((val\_len, 2)\) .

  • test (numpy.ndarray) - Test set positive examples, shape \((test\_len, 2)\) .

Supported Platforms:

Ascend GPU

Examples

>>> from mindspore_gl.dataloader import split_data
>>> from mindspore_gl.dataset import CoraV2
>>> ds = CoraV2('data_path')
>>> adj_coo, (train, val, test) = split_data(ds)
>>> print(train.shape, val.shape, test.shape)
(11684, 2) (263, 2) (527, 2)