mindspore/docs/api/api_python/dataset/mindspore.dataset.NumpySlic...

74 lines
4.1 KiB
ReStructuredText
Raw Normal View History

2021-11-27 16:09:05 +08:00
mindspore.dataset.NumpySlicesDataset
=====================================
2021-11-20 11:18:45 +08:00
2021-11-27 16:09:05 +08:00
.. py:class:: mindspore.dataset.NumpySlicesDataset(data, column_names=None, num_samples=None, num_parallel_workers=1, shuffle=None, sampler=None, num_shards=None, shard_id=None)
2021-12-29 21:06:37 +08:00
由Python数据构建数据集。生成的数据集的列名和列类型取决于用户传入的Python数据。
2021-11-20 11:18:45 +08:00
**参数:**
2021-12-29 21:06:37 +08:00
- **data** (Union[list, tuple, dict]) - 输入的Python数据。支持的数据类型包括list、tuple、dict和其他NumPy格式。
输入数据将沿着第一个维度切片并生成额外的行。如果输入是单个list则将生成一个数据列若是嵌套多个list则生成多个数据列。不建议通过这种方式加载大量的数据因为可能会在数据加载到内存时等待较长时间。
- **column_names** (list[str], 可选) - 指定数据集生成的列名默认值None不指定。
如果未指定该参数且当输入数据的类型是dict时输出列名称将被命名为dict的键名否则它们将被统一命名为column_0column_1...。
- **num_samples** (int, 可选) - 指定从数据集中读取的样本数。默认值None所有样本。
- **num_parallel_workers** (int, 可选) - 指定读取数据的工作线程数默认值1。
- **shuffle** (bool, 可选) - 是否混洗数据集。
只有输入的 `data` 参数带有可随机访问属性(`__getitem__`才可以指定该参数。默认值None下表中会展示不同配置的预期行为。
- **sampler** (Union[Sampler, Iterable], 可选) - 指定从数据集中选取样本的采样器。
只有输入的 `data` 参数带有可随机访问属性(`__getitem__`才可以指定该参数。默认值None下表中会展示不同配置的预期行为。
- **num_shards** (int, 可选) - 指定分布式训练时将数据集进行划分的分片数默认值None。指定此参数后 `num_samples` 表示每个分片的最大样本数。
- **shard_id** (int, 可选) - 指定分布式训练时使用的分片ID号默认值None。只有当指定了 `num_shards` 时才能指定此参数。
2021-11-27 16:09:05 +08:00
2021-12-29 21:06:37 +08:00
.. note:: 此数据集可以指定参数 `sampler` ,但参数 `sampler` 和参数 `shuffle` 的行为是互斥的。下表展示了几种合法的输入参数组合及预期的行为。
2021-11-20 11:18:45 +08:00
2021-11-27 16:09:05 +08:00
.. list-table:: 配置 `sampler``shuffle` 的不同组合得到的预期排序结果
2021-11-20 11:18:45 +08:00
:widths: 25 25 50
:header-rows: 1
2021-11-27 16:09:05 +08:00
* - 参数 `sampler`
- 参数 `shuffle`
2021-11-20 11:18:45 +08:00
- 预期数据顺序
* - None
- None
- 随机排列
* - None
- True
- 随机排列
* - None
- False
- 顺序排列
2021-12-29 21:06:37 +08:00
* - `sampler` 实例
2021-11-20 11:18:45 +08:00
- None
2021-11-27 16:09:05 +08:00
-`sampler` 行为定义的顺序
2021-12-29 21:06:37 +08:00
* - `sampler` 实例
2021-11-20 11:18:45 +08:00
- True
- 不允许
2021-12-29 21:06:37 +08:00
* - `sampler` 实例
2021-11-20 11:18:45 +08:00
- False
- 不允许
**异常:**
2021-12-04 20:36:47 +08:00
- **RuntimeError** - `column_names` 列表的长度与数据的输出列表长度不匹配。
2022-01-25 10:08:27 +08:00
- **ValueError** - `num_parallel_workers` 参数超过系统最大线程数。
2022-02-11 15:23:20 +08:00
- **ValueError** - 同时指定了 `sampler``shuffle` 参数。
2022-02-22 19:26:10 +08:00
- **ValueError** - 同时指定了 `sampler``num_shards` 参数或同时指定了 `sampler``shard_id` 参数。
2022-02-11 15:23:20 +08:00
- **ValueError** - 指定了 `num_shards` 参数,但是未指定 `shard_id` 参数。
- **ValueError** - 指定了 `shard_id` 参数,但是未指定 `num_shards` 参数。
- **ValueError** - `shard_id` 参数值错误小于0或者大于等于 `num_shards` )。
2021-11-27 16:09:05 +08:00
2021-12-04 14:38:46 +08:00
.. include:: mindspore.dataset.Dataset.add_sampler.rst
2021-12-03 17:02:40 +08:00
.. include:: mindspore.dataset.Dataset.rst
2021-12-04 14:38:46 +08:00
2022-01-19 11:26:42 +08:00
.. include:: mindspore.dataset.Dataset.b.rst
.. include:: mindspore.dataset.Dataset.c.rst
.. include:: mindspore.dataset.Dataset.d.rst
2021-12-04 14:38:46 +08:00
.. include:: mindspore.dataset.Dataset.use_sampler.rst
.. include:: mindspore.dataset.Dataset.zip.rst