fix the examples in docs of minddata

pull/12956/head
Xiao Tianci 4 years ago
parent 6a028cd863
commit bf69444b3a

@ -340,8 +340,7 @@ def load(file):
RuntimeError: If file is invalid and parsing fails. RuntimeError: If file is invalid and parsing fails.
Examples: Examples:
>>> # Set new default configuration values according to values in the configuration file. >>> # Set new default configuration according to values in the configuration file.
>>> ds.config.load("/path/to/config_directory/config.cfg")
>>> # example config file: >>> # example config file:
>>> # { >>> # {
>>> # "logFilePath": "/tmp", >>> # "logFilePath": "/tmp",
@ -349,5 +348,7 @@ def load(file):
>>> # "seed": 5489, >>> # "seed": 5489,
>>> # "monitorSamplingInterval": 30 >>> # "monitorSamplingInterval": 30
>>> # } >>> # }
>>> config_file = "/path/to/config/file"
>>> ds.config.load(config_file)
""" """
_config.load(file) _config.load(file)

File diff suppressed because it is too large Load Diff

@ -73,7 +73,7 @@ class GraphData:
Examples: Examples:
>>> graph_dataset = ds.GraphData(graph_dataset_dir, 2) >>> graph_dataset = ds.GraphData(graph_dataset_dir, 2)
>>> nodes = graph_dataset.get_all_nodes(0) >>> nodes = graph_dataset.get_all_nodes(1)
>>> features = graph_dataset.get_node_feature(nodes, [1]) >>> features = graph_dataset.get_node_feature(nodes, [1])
""" """
@ -114,7 +114,7 @@ class GraphData:
numpy.ndarray, array of nodes. numpy.ndarray, array of nodes.
Examples: Examples:
>>> nodes = graph_dataset.get_all_nodes(0) >>> nodes = graph_dataset.get_all_nodes(1)
Raises: Raises:
TypeError: If `node_type` is not integer. TypeError: If `node_type` is not integer.
@ -175,8 +175,8 @@ class GraphData:
numpy.ndarray, array of neighbors. numpy.ndarray, array of neighbors.
Examples: Examples:
>>> nodes = graph_dataset.get_all_nodes(0) >>> nodes = graph_dataset.get_all_nodes(1)
>>> neighbors = graph_dataset.get_all_neighbors(nodes, 0) >>> neighbors = graph_dataset.get_all_neighbors(nodes, 2)
Raises: Raises:
TypeError: If `node_list` is not list or ndarray. TypeError: If `node_list` is not list or ndarray.
@ -211,8 +211,8 @@ class GraphData:
numpy.ndarray, array of neighbors. numpy.ndarray, array of neighbors.
Examples: Examples:
>>> nodes = graph_dataset.get_all_nodes(0) >>> nodes = graph_dataset.get_all_nodes(1)
>>> neighbors = graph_dataset.get_sampled_neighbors(nodes, [2, 2], [0, 0]) >>> neighbors = graph_dataset.get_sampled_neighbors(nodes, [2, 2], [2, 1])
Raises: Raises:
TypeError: If `node_list` is not list or ndarray. TypeError: If `node_list` is not list or ndarray.
@ -240,8 +240,8 @@ class GraphData:
numpy.ndarray, array of neighbors. numpy.ndarray, array of neighbors.
Examples: Examples:
>>> nodes = graph_dataset.get_all_nodes(0) >>> nodes = graph_dataset.get_all_nodes(1)
>>> neg_neighbors = graph_dataset.get_neg_sampled_neighbors(nodes, 5, 0) >>> neg_neighbors = graph_dataset.get_neg_sampled_neighbors(nodes, 5, 2)
Raises: Raises:
TypeError: If `node_list` is not list or ndarray. TypeError: If `node_list` is not list or ndarray.
@ -266,8 +266,8 @@ class GraphData:
numpy.ndarray, array of features. numpy.ndarray, array of features.
Examples: Examples:
>>> nodes = graph_dataset.get_all_nodes(0) >>> nodes = graph_dataset.get_all_nodes(1)
>>> features = graph_dataset.get_node_feature(nodes, [1]) >>> features = graph_dataset.get_node_feature(nodes, [2, 3])
Raises: Raises:
TypeError: If `node_list` is not list or ndarray. TypeError: If `node_list` is not list or ndarray.
@ -347,7 +347,7 @@ class GraphData:
numpy.ndarray, array of nodes. numpy.ndarray, array of nodes.
Examples: Examples:
>>> nodes = graph_dataset.random_walk([1,2], [1,2,1,2,1]) >>> nodes = graph_dataset.random_walk([1, 2], [1, 2, 1, 2, 1])
Raises: Raises:
TypeError: If `target_nodes` is not list or ndarray. TypeError: If `target_nodes` is not list or ndarray.

@ -203,14 +203,12 @@ class Sampler(BuiltinSampler):
dataset_size and num_samples will be set by dataset once a dataset iterator is created. dataset_size and num_samples will be set by dataset once a dataset iterator is created.
Examples: Examples:
>>> import mindspore.dataset as ds >>> class ReverseSampler(ds.Sampler):
... def __iter__(self):
... for i in range(self.dataset_size - 1, -1, -1):
... yield i
>>> >>>
>>> class ReverseSampler(ds,Sampler): >>> ds = ds.ImageFolderDataset(image_folder_dataset_dir, sampler=ReverseSampler())
>>> def __iter__(self):
>>> for i in range(self.dataset_size - 1, -1, -1):
>>> yield i
>>>
>>> ds = ds.ImageFolderDataset(path, sampler=ReverseSampler())
""" """
def __init__(self, num_samples=None): def __init__(self, num_samples=None):
@ -698,15 +696,11 @@ class SubsetRandomSampler(SubsetSampler):
num_samples (int, optional): Number of elements to sample (default=None, all elements). num_samples (int, optional): Number of elements to sample (default=None, all elements).
Examples: Examples:
>>> import mindspore.dataset as ds
>>>
>>> dataset_dir = "path/to/imagefolder_directory"
>>>
>>> indices = [0, 1, 2, 3, 7, 88, 119] >>> indices = [0, 1, 2, 3, 7, 88, 119]
>>> >>>
>>> # creates a SubsetRandomSampler, will sample from the provided indices >>> # create a SubsetRandomSampler, will sample from the provided indices
>>> sampler = ds.SubsetRandomSampler(indices) >>> sampler = ds.SubsetRandomSampler(indices)
>>> data = ds.ImageFolderDataset(dataset_dir, num_parallel_workers=8, sampler=sampler) >>> data = ds.ImageFolderDataset(image_folder_dataset_dir, num_parallel_workers=8, sampler=sampler)
Raises: Raises:
TypeError: If type of indices element is not a number. TypeError: If type of indices element is not a number.

@ -106,14 +106,15 @@ class TypeCast(cde.TypeCastOp):
Examples: Examples:
>>> import numpy as np >>> import numpy as np
>>> import mindspore.common.dtype as mstype >>> import mindspore.common.dtype as mstype
>>> from mindspore.dataset import GeneratorDataset >>>
>>> # Generate 1d int numpy array from 0 - 63 >>> # Generate 1d int numpy array from 0 - 63
>>> def generator_1d(): >>> def generator_1d():
>>> for i in range(64): ... for i in range(64):
... yield (np.array([i]),) ... yield (np.array([i]),)
>>> generator_dataset = GeneratorDataset(generator_1d,column_names='col') >>>
>>> dataset = ds.GeneratorDataset(generator_1d, column_names='col')
>>> type_cast_op = c_transforms.TypeCast(mstype.int32) >>> type_cast_op = c_transforms.TypeCast(mstype.int32)
>>> generator_dataset = generator_dataset.map(operations=type_cast_op) >>> dataset = dataset.map(operations=type_cast_op)
""" """
@check_de_type @check_de_type

@ -40,7 +40,7 @@ class OneHotOp:
>>> # Assume that dataset has 10 classes, thus the label ranges from 0 to 9 >>> # Assume that dataset has 10 classes, thus the label ranges from 0 to 9
>>> transforms_list = [py_transforms.OneHotOp(num_classes=10, smoothing_rate=0.1)] >>> transforms_list = [py_transforms.OneHotOp(num_classes=10, smoothing_rate=0.1)]
>>> transform = py_transforms.Compose(transforms_list) >>> transform = py_transforms.Compose(transforms_list)
>>> mnist_dataset = mnist_dataset(input_columns=["label"], operations=transform) >>> mnist_dataset = mnist_dataset.map(input_columns=["label"], operations=transform)
""" """
@check_one_hot_op @check_one_hot_op

Loading…
Cancel
Save