fix api chinese doc

This commit is contained in:
shenwei41 2022-01-05 16:22:27 +08:00
parent 813c9d6ee6
commit 6dcba68c60
10 changed files with 151 additions and 142 deletions

View File

@ -1,6 +1,6 @@
.. py:method:: add_child(sampler)
为给定采样器添加子采样器。子采样器接收父采样器输出的所有数据,并应用其采样逻辑返回新的采样。
为给定采样器添加子采样器。子采样器接收父采样器输出数据作为输入,并应用其采样逻辑返回新的采样结果
**参数:**
@ -18,7 +18,7 @@
.. py:method:: get_num_samples()
所有采样器都可以包含 `num_samples` 数值也可以将其设置为None。子采样器可以存在也可以为None。如果存在子采样器则子采样器计数可以是数值或None。这些条件会影响最终的采样结果。
返回采样器采集样本数量,如果存在子采样器则子采样器计数可以是数值或None。这些条件会影响最终的采样结果。
下表显示了调用此函数的可能结果。

View File

@ -9,17 +9,9 @@ mindspore.dataset.DistributedSampler
- **num_shards** (int) - 数据集分片数量。
- **shard_id** (int) - 当前分片的分片ID应在[0, num_shards-1]范围内。
- **shuffle** (bool, optional) - 如果为True则索引将被打乱默认为True
- **num_samples** (int, optional) - 要采样的样本数默认为None对所有元素进行采样
- **offset** (int, optional) - 将数据集中的元素发送到的起始分片ID不应超过 `num_shards` 。仅当ConcatDataset以DistributedSampler为采样器时此参数才有效。此参数影响每个分片的样本数默认为-1每个分片具有相同的样本数
**样例:**
>>> # 创建一个分布式采样器共10个分片。当前分片为分片5。
>>> sampler = ds.DistributedSampler(10, 5)
>>> dataset = ds.ImageFolderDataset(image_folder_dataset_dir,
... num_parallel_workers=8,
... sampler=sampler)
- **shuffle** (bool, 可选) - 是否混洗采样得到的样本默认值True混洗样本。
- **num_samples** (int, 可选) - 获取的样本数可用于部分获取采样得到的样本默认值None获取采样到的所有样本。
- **offset** (int, 可选) - 分布式采样结果进行分配时的起始分片ID号值不能大于参数 `num_shards` 。从不同的分片ID开始分配数据可能会影响每个分片的最终样本数。仅当ConcatDataset以DistributedSampler为采样器时此参数才有效。默认值-1每个分片具有相同的样本数。
**异常:**
@ -33,4 +25,12 @@ mindspore.dataset.DistributedSampler
- **RuntimeError** - `shard_id` 小于0或大于等于 `num_shards`
- **RuntimeError** - `offset` 大于 `num_shards`
**样例:**
>>> # 创建一个分布式采样器共10个分片。当前分片为分片5。
>>> sampler = ds.DistributedSampler(10, 5)
>>> dataset = ds.ImageFolderDataset(image_folder_dataset_dir,
... num_parallel_workers=8,
... sampler=sampler)
.. include:: mindspore.dataset.BuiltinSampler.rst

View File

@ -3,22 +3,22 @@ mindspore.dataset.GraphData
.. py:class:: mindspore.dataset.GraphData(dataset_file, num_parallel_workers=None, working_mode='local', hostname='127.0.0.1', port=50051, num_client=1, auto_shutdown=True)
从共享文件数据库中读取用于GNN训练的图数据集。
从共享文件数据库中读取用于GNN训练的图数据集。
**参数:**
- **dataset_file** (str) - 数据集文件路径。
- **num_parallel_workers** (int, 可选) - 读取数据的工作线程数默认为None
- **working_mode** (str, 可选) - 设置工作模式,目前支持'local'/'client'/'server'(默认为'local'
- **num_parallel_workers** (int, 可选) - 读取数据的工作线程数默认值None使用mindspore.dataset.config中配置的线程数
- **working_mode** (str, 可选) - 设置工作模式,目前支持'local'/'client'/'server',默认值:'local'
- **local**:用于非分布式训练场景。
- **client**:用于分布式训练场景。客户端不加载数据,而是从服务器获取数据。
- **server**:用于分布式训练场景。服务器加载数据并可供客户端使用。
- **hostname** (str, 可选) - 图数据集服务器的主机名。该参数仅在工作模式设置为 'client' 或 'server' 时有效(默认为'127.0.0.1'
- **port** (int, 可选) - 图数据服务器的端口取值范围为1024-65535。此参数仅当工作模式设置为 'client' 或 'server' 默认为50051时有效
- **num_client** (int, 可选) - 期望连接到服务器的最大客户端数。服务器将根据该参数分配资源。该参数仅在工作模式设置为 'server' 时有效默认为1
- **auto_shutdown** (bool, 可选) - 当工作模式设置为 'server' 时有效。当连接的客户端数量达到 `num_client` ,且没有客户端正在连接时,服务器将自动退出默认为True
- **hostname** (str, 可选) - 图数据集服务器的主机名。该参数仅在工作模式设置为 'client' 或 'server' 时有效,默认值:'127.0.0.1'
- **port** (int, 可选) - 图数据服务器的端口取值范围为1024-65535。此参数仅当工作模式设置为 'client' 或 'server' 时有效默认值50051
- **num_client** (int, 可选) - 期望连接到服务器的最大客户端数。服务器将根据该参数分配资源。该参数仅在工作模式设置为 'server' 时有效默认值1
- **auto_shutdown** (bool, 可选) - 当工作模式设置为 'server' 时有效。当连接的客户端数量达到 `num_client` ,且没有客户端正在连接时,服务器将自动退出默认值True
**样例:**
@ -34,21 +34,21 @@ mindspore.dataset.GraphData
**参数:**
- **edge_type** (int) - 指定边的类型。
- **edge_type** (int) - 指定边的类型在数据集转换为MindRecord格式时需要指定`edge_type`的值并在此API中对应使用。详见 `加载图数据集 <https://www.mindspore.cn/docs/programming_guide/zh-CN/master/load_dataset_gnn.html>`_
**返回:**
numpy.ndarray包含边的数组。
**样例:**
>>> edges = graph_dataset.get_all_edges(edge_type=0)
**异常:**
**TypeError**:参数 `edge_type` 的类型不为整型。
.. py:method:: get_all_neighbors(node_list, neighbor_type, output_format=<OutputFormat.NORMAL: 0。
**样例:**
>>> edges = graph_dataset.get_all_edges(edge_type=0)
.. py:method:: get_all_neighbors(node_list, neighbor_type, output_format=<OutputFormat.NORMAL)
获取 `node_list` 所有节点的相邻节点,以 `neighbor_type` 类型返回。格式的定义参见以下示例1表示两个节点之间连接0表示不连接。
@ -140,12 +140,17 @@ mindspore.dataset.GraphData
- **node_list** (Union[list, numpy.ndarray]) - 给定的节点列表。
- **neighbor_type** (int) - 指定相邻节点的类型。
- **output_format** (OutputFormat, 可选) - 输出存储格式默认为mindspore.dataset.engine.OutputFormat.NORMAL取值范围:[OutputFormat.NORMAL, OutputFormat.COO, OutputFormat.CSR]。
- **output_format** (OutputFormat, 可选) - 输出存储格式默认值mindspore.dataset.OutputFormat.NORMAL取值范围:[OutputFormat.NORMAL, OutputFormat.COO, OutputFormat.CSR]。
**返回:**
对于普通格式或COO格式将返回numpy.ndarray类型的数组表示相邻节点。如果指定了CSR格式将返回两个numpy.ndarray数组第一个表示偏移表第二个表示相邻节点。
**异常:**
- **TypeError** - 参数 `node_list` 的类型不为列表或numpy.ndarray。
- **TypeError** - 参数 `neighbor_type` 的类型不为整型。
**样例:**
>>> from mindspore.dataset.engine import OutputFormat
@ -156,31 +161,26 @@ mindspore.dataset.GraphData
>>> offset_table, neighbors_csr = graph_dataset.get_all_neighbors(node_list=nodes, neighbor_type=2,
... output_format=OutputFormat.CSR)
**异常:**
- **TypeError** - 参数 `node_list` 的类型不为列表或numpy.ndarray。
- **TypeError** - 参数 `neighbor_type` 的类型不为整型。
.. py:method:: get_all_nodes(node_type)
获取图中的所有节点。
**参数:**
- **node_type** (int) - 指定节点的类型。
- **node_type** (int) - 指定节点的类型。在数据集转换为MindRecord格式时需要指定`node_type`的值并在此API中对应使用。详见 `加载图数据集 <https://www.mindspore.cn/docs/programming_guide/zh-CN/master/load_dataset_gnn.html>`_
**返回:**
numpy.ndarray包含节点的数组。
**异常:**
**TypeError**:参数 `node_type` 的类型不为整型。
**样例:**
>>> nodes = graph_dataset.get_all_nodes(node_type=1)
**异常:**
**TypeError**:参数 `node_type` 的类型不为整型。
.. py:method:: get_edges_from_nodes(node_list)
从节点获取边。
@ -193,14 +193,14 @@ mindspore.dataset.GraphData
numpy.ndarray含一个或多个边ID的数组。
**示例:**
>>> edges = graph_dataset.get_edges_from_nodes(node_list=[(101, 201), (103, 207)])
**异常:**
**TypeError**:参数 `edge_list` 的类型不为列表或numpy.ndarray。
**样例:**
>>> edges = graph_dataset.get_edges_from_nodes(node_list=[(101, 201), (103, 207)])
.. py:method:: get_edge_feature(edge_list, feature_types)
获取 `edge_list` 列表中边的特征,以 `feature_types` 类型返回。
@ -214,16 +214,16 @@ mindspore.dataset.GraphData
numpy.ndarray包含特征的数组。
**样例:**
>>> edges = graph_dataset.get_all_edges(edge_type=0)
>>> features = graph_dataset.get_edge_feature(edge_list=edges, feature_types=[1])
**异常:**
- **TypeError** - 参数 `edge_list` 的类型不为列表或numpy.ndarray。
- **TypeError** - 参数 `feature_types` 的类型不为列表或numpy.ndarray。
**样例:**
>>> edges = graph_dataset.get_all_edges(edge_type=0)
>>> features = graph_dataset.get_edge_feature(edge_list=edges, feature_types=[1])
.. py:method:: get_neg_sampled_neighbors(node_list, neg_neighbor_num, neg_neighbor_type)
@ -239,18 +239,18 @@ mindspore.dataset.GraphData
numpy.ndarray包含相邻节点的数组。
**样例:**
>>> nodes = graph_dataset.get_all_nodes(node_type=1)
>>> neg_neighbors = graph_dataset.get_neg_sampled_neighbors(node_list=nodes, neg_neighbor_num=5,
... neg_neighbor_type=2)
**异常:**
- **TypeError** - 参数 `node_list` 的类型不为列表或numpy.ndarray。
- **TypeError** - 参数 `neg_neighbor_num` 的类型不为整型。
- **TypeError** - 参数 `neg_neighbor_type` 的类型不为整型。
**样例:**
>>> nodes = graph_dataset.get_all_nodes(node_type=1)
>>> neg_neighbors = graph_dataset.get_neg_sampled_neighbors(node_list=nodes, neg_neighbor_num=5,
... neg_neighbor_type=2)
.. py:method:: get_nodes_from_edges(edge_list)
从图中的边获取节点。
@ -267,6 +267,11 @@ mindspore.dataset.GraphData
**TypeError** 参数 `edge_list` 不为列表或ndarray。
**样例:**
>>> edge_list = graph_dataset.get_all_edges(node_type=1)
>>> nodes = graph_dataset.get_nodes_from_edges(edge_list)
.. py:method:: get_node_feature(node_list, feature_types)
获取 `node_list` 中节点的特征,以 `feature_types` 类型返回。
@ -280,16 +285,16 @@ mindspore.dataset.GraphData
numpy.ndarray包含特征的数组。
**示例:**
>>> nodes = graph_dataset.get_all_nodes(node_type=1)
>>> features = graph_dataset.get_node_feature(node_list=nodes, feature_types=[2, 3])
**异常:**
- **TypeError** - 参数 `node_list` 的类型不为列表或numpy.ndarray。
- **TypeError** - 参数 `feature_types` 的类型不为列表或numpy.ndarray。
**样例:**
>>> nodes = graph_dataset.get_all_nodes(node_type=1)
>>> features = graph_dataset.get_node_feature(node_list=nodes, feature_types=[2, 3])
.. py:method:: get_sampled_neighbors(node_list, neighbor_nums, neighbor_types, strategy=<SamplingStrategy.RANDOM: 0>)
获取已采样相邻节点信息。此API支持多跳相邻节点采样。即将上一次采样结果作为下一跳采样的输入最多允许6跳。采样结果平铺成列表格式为[input node, 1-hop sampling result, 2-hop samling result ...]
@ -299,7 +304,7 @@ mindspore.dataset.GraphData
- **node_list** (Union[list, numpy.ndarray]) - 包含节点的列表。
- **neighbor_nums** (Union[list, numpy.ndarray]) - 每跳采样的相邻节点数。
- **neighbor_types** (Union[list, numpy.ndarray]) - 每跳采样的相邻节点类型。
- **strategy** (SamplingStrategy, 可选) - 采样策略默认为mindspore.dataset.engine.SamplingStrategy.RANDOM。取值范围:[SamplingStrategy.RANDOM, SamplingStrategy.EDGE_WEIGHT]。
- **strategy** (SamplingStrategy, 可选) - 采样策略默认值mindspore.dataset.SamplingStrategy.RANDOM。取值范围:[SamplingStrategy.RANDOM, SamplingStrategy.EDGE_WEIGHT]。
- **SamplingStrategy.RANDOM**:随机抽样,带放回采样。
- **SamplingStrategy.EDGE_WEIGHT**:以边缘权重为概率进行采样。
@ -308,18 +313,18 @@ mindspore.dataset.GraphData
numpy.ndarray包含相邻节点的数组。
*样例:**
>>> nodes = graph_dataset.get_all_nodes(node_type=1)
>>> neighbors = graph_dataset.get_sampled_neighbors(node_list=nodes, neighbor_nums=[2, 2],
... neighbor_types=[2, 1])
**异常:**
- **TypeError** - 参数 `node_list` 的类型不为列表或numpy.ndarray。
- **TypeError** - 参数 `neighbor_nums` 的类型不为列表或numpy.ndarray。
- **TypeError** - 参数 `neighbor_types` 的类型不为列表或numpy.ndarray。
**样例:**
>>> nodes = graph_dataset.get_all_nodes(node_type=1)
>>> neighbors = graph_dataset.get_sampled_neighbors(node_list=nodes, neighbor_nums=[2, 2],
... neighbor_types=[2, 1])
.. py:method:: graph_info()
@ -327,7 +332,11 @@ mindspore.dataset.GraphData
**返回:**
dict图的元信息。键为 `node_num``node_type``node_feature_type``edge_num``edge_type` 、和 `edge_feature_type`
dict图的元信息。键为 `node_num``node_type``node_feature_type``edge_num``edge_type``edge_feature_type`
**样例:**
>>> graph_info = graph_dataset.graph_info()
.. py:method:: random_walk(target_nodes, meta_path, step_home_param=1.0, step_away_param=1.0, default_node=-1)
@ -338,20 +347,20 @@ mindspore.dataset.GraphData
- **target_nodes** (list[int]) - 随机游走中的起始节点列表。
- **meta_path** (list[int]) - 每个步长的节点类型。
- **step_home_param** (float, 可选) - 返回node2vec算法中的超参默认为1.0
- **step_away_param** (float, 可选) - node2vec算法中的in和out超参默认为1.0
- **default_node** (int, 可选) - 如果找不到更多相邻节点,则为默认节点(默认值为-1表示不给定节点
- **step_home_param** (float, 可选) - 返回 `node2vec算法 <https://www.kdd.org/kdd2016/papers/files/rfp0218-groverA.pdf>`_ 中的超参默认值1.0
- **step_away_param** (float, 可选) - `node2vec算法 <https://www.kdd.org/kdd2016/papers/files/rfp0218-groverA.pdf>`_ 中的in和out超参默认值1.0
- **default_node** (int, 可选) - 如果找不到更多相邻节点,则为默认节点,默认值:-1表示不给定节点
**返回:**
numpy.ndarray包含节点的数组。
**示例:**
>>> nodes = graph_dataset.get_all_nodes(node_type=1)
>>> walks = graph_dataset.random_walk(target_nodes=nodes, meta_path=[2, 1, 2])
**异常:**
- **TypeError** - 参数 `target_nodes` 的类型不为列表或numpy.ndarray。
- **TypeError** - 参数 `meta_path` 的类型不为列表或numpy.ndarray。
**样例:**
>>> nodes = graph_dataset.get_all_nodes(node_type=1)
>>> walks = graph_dataset.random_walk(target_nodes=nodes, meta_path=[2, 1, 2])

View File

@ -3,23 +3,15 @@ mindspore.dataset.PKSampler
.. py:class:: mindspore.dataset.PKSampler(num_val, num_class=None, shuffle=False, class_column='label', num_samples=None)
为数据集中的每个P类采样K个元素
为数据集中每P个类别各采样K个样本
**参数:**
- **num_val** (int): 每个类要采样的元素数量。
- **num_class** (int, optional): 要采样的类数量默认值为None采样所有类。当前不支持指定该参数。
- **shuffle** (bool, optional): 如果为True则class ID将被打乱否则它将不会被打乱默认值为False
- **class_column** (str, optional): 具有MindDataset类标签的列的名称默认值'label')。
- **num_samples** (int, optional): 要采样的样本数默认值为None对所有元素进行采样
**样例:**
>>> # 创建一个PKSampler从每个类中获取3个样本。
>>> sampler = ds.PKSampler(3)
>>> dataset = ds.ImageFolderDataset(image_folder_dataset_dir,
... num_parallel_workers=8,
... sampler=sampler)
- **num_class** (int, 可选): 要采样的类数量默认值为None采样所有类。当前不支持指定该参数。
- **shuffle** (bool, 可选): 是否混洗采样得到的样本默认值False不混洗样本。
- **class_column** (str, 可选): 指定label所属数据列的名称将基于此列作为数据标签进行采样默认值'label'。
- **num_samples** (int, 可选): 获取的样本数可用于部分获取采样得到的样本。默认值None获取采样到的所有样本。
**异常:**
@ -30,4 +22,12 @@ mindspore.dataset.PKSampler
- **RuntimeError** `num_val` 不是正值。
- **ValueError** `num_samples` 为负值。
**样例:**
>>> # 创建一个PKSampler从每个类中获取3个样本。
>>> sampler = ds.PKSampler(3)
>>> dataset = ds.ImageFolderDataset(image_folder_dataset_dir,
... num_parallel_workers=8,
... sampler=sampler)
.. include:: mindspore.dataset.BuiltinSampler.rst

View File

@ -7,8 +7,14 @@ mindspore.dataset.RandomSampler
**参数:**
- **replacement** (bool, optional): 如果为True则将样本ID放回下一次采样默认值为False
- **num_samples** (int, optional): 要采样的元素数量默认值为None采样所有元素
- **replacement** (bool, 可选): 是否将样本ID放回下一次采样默认值True有放回采样。
- **num_samples** (int, 可选): 获取的样本数可用于部分获取采样得到的样本。默认值None获取采样到的所有样本。
**异常:**
- **TypeError** `replacement` 不是bool值。
- **TypeError** `num_samples` 不是整数值。
- **ValueError** `num_samples` 为负值。
**样例:**
@ -18,10 +24,4 @@ mindspore.dataset.RandomSampler
... num_parallel_workers=8,
... sampler=sampler)
**异常:**
- **TypeError** `replacement` 不是bool值。
- **TypeError** `num_samples` 不是整数值。
- **ValueError** `num_samples` 为负值。
.. include:: mindspore.dataset.BuiltinSampler.rst

View File

@ -3,11 +3,11 @@ mindspore.dataset.Schema
.. py:class:: mindspore.dataset.Schema(schema_file=None)
代表一个解析和存储数据列属性的类。
用于解析和存储数据列属性的类。
**参数:**
- **schema_file** (str): schema文件的路径默认值为None
- **schema_file** (str): schema文件的路径默认值None
**返回:**
@ -33,7 +33,7 @@ mindspore.dataset.Schema
- **name** (str): 列的新名称。
- **de_type** (str): 列的数据类型。
- **shape** (list[int], optional): 列shape默认值为None[-1]表示rank 1的未知shape
- **shape** (list[int], 可选): 列shape默认值None-1表示该维度的shape是未知的
**异常:**

View File

@ -3,12 +3,19 @@ mindspore.dataset.SequentialSampler
.. py:class:: mindspore.dataset.SequentialSampler(start_index=None, num_samples=None)
顺序采样数据集元素,相当于不使用采样器。
数据集的读取顺序采样数据集样本,相当于不使用采样器。
**参数:**
- **start_index** (int, optional): 开始采样的索引。默认值为None从第一个ID开始
- **num_samples** (int, optional): 要采样的元素数量。默认值为None采样所有元素
- **start_index** (int, 可选): 采样的起始样本ID默认值None从数据集第一个样本开始采样。
- **num_samples** (int, 可选): 获取的样本数可用于部分获取采样得到的样本。默认值None获取采样到的所有样本。
**异常:**
- **TypeError** `start_index` 不是整数值。
- **TypeError** `num_samples` 不是整数值。
- **RuntimeError** `start_index` 为负值。
- **ValueError** `num_samples` 为负值。
**样例:**
@ -18,11 +25,4 @@ mindspore.dataset.SequentialSampler
... num_parallel_workers=8,
... sampler=sampler)
**异常:**
- **TypeError** `start_index` 不是整数值。
- **TypeError** `num_samples` 不是整数值。
- **RuntimeError** `start_index` 为负值。
- **ValueError** `num_samples` 为负值。
.. include:: mindspore.dataset.BuiltinSampler.rst

View File

@ -3,20 +3,12 @@ mindspore.dataset.SubsetRandomSampler
.. py:class:: mindspore.dataset.SubsetRandomSampler(indices, num_samples=None)
对索引序列中的元素进行随机采样。
给定样本的索引序列,从序列中随机获取索引对数据集进行采样。
**参数:**
- **indices** (Any iterable Python object but string): 索引的序列。
- **num_samples** (int, optional): 要采样的元素数量默认值为None采样所有元素
**样例:**
>>> indices = [0, 1, 2, 3, 7, 88, 119]
>>>
>>> # 创建一个SubsetRandomSampler从提供的索引中采样
>>> sampler = ds.SubsetRandomSampler(indices)
>>> data = ds.ImageFolderDataset(image_folder_dataset_dir, num_parallel_workers=8, sampler=sampler)
- **indices** (Iterable): 样本索引的序列除了string类型外的任意Python可迭代对象类型
- **num_samples** (int, 可选): 获取的样本数可用于部分获取采样得到的样本。默认值None获取采样到的所有样本。
**异常:**
@ -24,4 +16,12 @@ mindspore.dataset.SubsetRandomSampler
- **TypeError** `num_samples` 不是整数值。
- **ValueError** `num_samples` 为负值。
**样例:**
>>> indices = [0, 1, 2, 3, 7, 88, 119]
>>>
>>> # 创建一个SubsetRandomSampler根据提供的索引序列对数据集进行随机采样
>>> sampler = ds.SubsetRandomSampler(indices)
>>> data = ds.ImageFolderDataset(image_folder_dataset_dir, num_parallel_workers=8, sampler=sampler)
.. include:: mindspore.dataset.BuiltinSampler.rst

View File

@ -3,22 +3,12 @@ mindspore.dataset.SubsetSampler
.. py:class:: mindspore.dataset.SubsetSampler(indices, num_samples=None)
对索引序列中的元素进行采样
给定样本的索引序列,对数据集采样指定索引的样本
**参数:**
- **indices** (Any iterable Python object but string): 索引的序列。
- **num_samples** (int, optional): 要采样的元素数量默认值为None采样所有元素
**样例:**
>>> indices = [0, 1, 2, 3, 4, 5]
>>>
>>> # 创建SubsetSampler从提供的索引采样
>>> sampler = ds.SubsetSampler(indices)
>>> dataset = ds.ImageFolderDataset(image_folder_dataset_dir,
... num_parallel_workers=8,
... sampler=sampler)
- **indices** (Iterable): 索引的序列包括除了string类型的任意Python可迭代对象类型
- **num_samples** (int, 可选): 获取的样本数可用于部分获取采样得到的样本。默认值None获取采样到的所有样本。
**异常:**
@ -26,4 +16,14 @@ mindspore.dataset.SubsetSampler
- **TypeError** `num_samples` 不是整数值。
- **ValueError** `num_samples` 为负值。
**样例:**
>>> indices = [0, 1, 2, 3, 4, 5]
>>>
>>> # 创建SubsetSampler根据提供的索引序列对数据集进行采样
>>> sampler = ds.SubsetSampler(indices)
>>> dataset = ds.ImageFolderDataset(image_folder_dataset_dir,
... num_parallel_workers=8,
... sampler=sampler)
.. include:: mindspore.dataset.BuiltinSampler.rst

View File

@ -3,13 +3,21 @@ mindspore.dataset.WeightedRandomSampler
.. py:class:: mindspore.dataset.WeightedRandomSampler(weights, num_samples=None, replacement=True)
使用给定的权重(概率)进行随机采样[0len(weights) - 1]中的元素
给定样本的权重列表,根据权重决定样本的采样概率,随机采样[0len(weights) - 1]中的样本
**参数:**
- **weights** (list[float, int]) - 权重序列总和不一定为1。
- **num_samples** (int, optional) - 待采样的元素数量默认值为None代表采样所有元素
- **replacement** (bool) - 如果值为True则将样本ID放回下一次采样默认值为True
- **num_samples** (int, 可选) - 获取的样本数可用于部分获取采样得到的样本。默认值None获取采样到的所有样本。
- **replacement** (bool) - 是否将样本ID放回下一次采样默认值True有放回采样。
**异常:**
- **TypeError** `weights` 元素的类型不是数字。
- **TypeError** `num_samples` 不是整数值。
- **TypeError** `replacement` 不是布尔值。
- **RuntimeError** `weights` 为空或全为零。
- **ValueError** `num_samples` 为负值。
**样例:**
@ -21,12 +29,4 @@ mindspore.dataset.WeightedRandomSampler
... num_parallel_workers=8,
... sampler=sampler)
**异常:**
- **TypeError** `weights` 元素的类型不是数字。
- **TypeError** `num_samples` 不是整数值。
- **TypeError** `replacement` 不是布尔值。
- **RuntimeError** `weights` 为空或全为零。
- **ValueError** `num_samples` 为负值。
.. include:: mindspore.dataset.BuiltinSampler.rst