add new Chinese API docs and fix some bugs

This commit is contained in:
XiaoTianci 2022-02-28 21:50:37 +08:00 committed by Xiao Tianci
parent c1036cbfaf
commit cd43409e08
74 changed files with 582 additions and 259 deletions

View File

@ -168,7 +168,7 @@
**参数:**
- **operations** (Union[list[TensorOp], list[functions]]) - 一组数据增强操作支持数据集增强算子或者用户自定义的Python Callable对象。map操作将按顺序将一组数据增强作用在数据集对象上。
- **operations** (Union[list[TensorOperation], list[functions]]) - 一组数据增强操作支持数据集增强算子或者用户自定义的Python Callable对象。map操作将按顺序将一组数据增强作用在数据集对象上。
- **input_columns** (Union[str, list[str]], 可选) - 第一个数据增强操作的输入数据列。此列表的长度必须与 `operations` 列表中第一个数据增强的预期输入列数相匹配。默认值None。表示所有数据列都将传递给第一个数据增强操作。
- **output_columns** (Union[str, list[str]], 可选) - 最后一个数据增强操作的输出数据列。如果 `input_columns` 长度不等于 `output_columns` 长度则必须指定此参数。列表的长度必须必须与最后一个数据增强的输出列数相匹配。默认值None输出列将与输入列具有相同的名称。
- **column_order** (Union[str, list[str]], 可选) - 指定传递到下一个数据集操作的数据列的顺序。如果 `input_columns` 长度不等于 `output_columns` 长度,则必须指定此参数。 注意:参数的列名不限定在 `input_columns``output_columns` 中指定的列也可以是上一个操作输出的未被处理的数据列。默认值None按照原输入顺序排列。

View File

@ -27,6 +27,18 @@
numpy.ndarray带边界框和类别置信度的图像。
**异常:**
- **ImportError** - 当未安装opencv-python库。
- **AssertionError** - 当 `image` 的格式不为(H, W, C)或(C, H, W)。
- **AssertionError** - 当 `bboxes` 的格式不为(N, 4)或(N, 5)。
- **AssertionError** - 当 `labels` 的格式不为(N, 1)。
- **AssertionError** - 当 `segm` 的格式不为(M, H, W)。
- **AssertionError** - 当 `class_names` 的类型不为列表、元组或字典。
- **AssertionError** - 当 `bbox_color` 不为(B, G, R)格式的元组。
- **AssertionError** - 当 `text_color` 不为(B, G, R)格式的元组。
- **AssertionError** - 当 `mask_color` 不为(B, G, R)格式的元组。
**imshow_det_bbox在VOC2012数据集的使用图示**
.. image:: browse_dataset.png

View File

@ -7,4 +7,9 @@ API样例中常用的导入模块如下
.. code-block::
import mindspore.dataset as ds
import mindspore.dataset.audio.transforms as audio
import mindspore.dataset.audio.transforms as audio
常用数据处理术语说明如下:
- TensorOperation所有C++实现的数据处理操作的基类。
- AudioTensorOperation所有音频数据处理操作的基类派生自TensorOperation。

View File

@ -19,3 +19,12 @@ mindspore.dataset.audio.transforms.AllpassBiquad
- **sample_rate** (int) - 采样频率单位Hz不能为零。
- **central_freq** (float) - 中心频率单位Hz
- **Q** (float, 可选) - `品质因子 <https://zh.wikipedia.org/wiki/%E5%93%81%E8%B3%AA%E5%9B%A0%E5%AD%90>`_ ,能够反映带宽与采样频率和中心频率的关系,取值范围为(0, 1]默认值0.707。
**异常:**
- **TypeError** - 当 `sample_rate` 的类型不为整型。
- **ValueError** - 当 `sample_rate` 为0。
- **TypeError** - 当 `central_freq` 的类型不为浮点型。
- **TypeError** - 当 `Q` 的类型不为浮点型。
- **ValueError** - 当 `Q` 取值不在(0, 1]范围内。
- **RuntimeError** - 当输入音频的shape不为<..., time>。

View File

@ -16,3 +16,14 @@ mindspore.dataset.audio.transforms.AmplitudeToDB
- **amin** (float, 可选) - 波形取值下界低于该值的波形将会被裁切取值必须大于0默认值1e-10。
- **top_db** (float, 可选) - 最小负截止分贝值默认值80.0。
**异常:**
- **TypeError** - 当 `stype` 的类型不为 :class:`mindspore.dataset.audio.utils.ScaleType`
- **TypeError** - 当 `ref_value` 的类型不为浮点型。
- **ValueError** - 当 `ref_value` 不为正数。
- **TypeError** - 当 `amin` 的类型不为浮点型。
- **ValueError** - 当 `amin` 不为正数。
- **TypeError** - 当 `top_db` 的类型不为浮点型。
- **ValueError** - 当 `top_db` 不为正数。
- **RuntimeError** - 当输入音频的shape不为<..., freq, time>。

View File

@ -6,3 +6,7 @@ mindspore.dataset.audio.transforms.Angle
计算复数序列的角度。
.. note:: 待处理音频维度需为(..., complex=2)其中第0维代表实部第1维代表虚部。
**异常:**
- **RuntimeError** - 当输入音频的shape不为<..., complex=2>。

View File

@ -17,3 +17,13 @@ mindspore.dataset.audio.transforms.BandBiquad
- **central_freq** (float) - 中心频率单位Hz
- **Q** (float, 可选) - `品质因子 <https://zh.wikipedia.org/wiki/%E5%93%81%E8%B3%AA%E5%9B%A0%E5%AD%90>`_ ,能够反映带宽与采样频率和中心频率的关系,取值范围为(0, 1]默认值0.707。
- **noise** (bool, 可选) - 若为True则使用非音调音频如打击乐模式若为False则使用音调音频如语音、歌曲或器乐模式默认值False。
**异常:**
- **TypeError** - 当 `sample_rate` 的类型不为整型。
- **ValueError** - 当 `sample_rate` 为0。
- **TypeError** - 当 `central_freq` 的类型不为浮点型。
- **TypeError** - 当 `Q` 的类型不为浮点型。
- **ValueError** - 当 `Q` 取值不在(0, 1]范围内。
- **TypeError** - 当 `noise` 的类型不为布尔型。
- **RuntimeError** - 当输入音频的shape不为<..., time>。

View File

@ -25,3 +25,13 @@ mindspore.dataset.audio.transforms.BandpassBiquad
- **central_freq** (float) - 中心频率单位Hz
- **Q** (float, 可选) - `品质因子 <https://zh.wikipedia.org/wiki/%E5%93%81%E8%B3%AA%E5%9B%A0%E5%AD%90>`_ ,能够反映带宽与采样频率和中心频率的关系,取值范围为(0, 1]默认值0.707。
- **const_skirt_gain** (bool, 可选) - 若为True则使用恒定裙边增益峰值增益为Q若为False则使用恒定的0dB峰值增益。默认值False。
**异常:**
- **TypeError** - 当 `sample_rate` 的类型不为整型。
- **ValueError** - 当 `sample_rate` 为0。
- **TypeError** - 当 `central_freq` 的类型不为浮点型。
- **TypeError** - 当 `Q` 的类型不为浮点型。
- **ValueError** - 当 `Q` 取值不在(0, 1]范围内。
- **TypeError** - 当 `const_skirt_gain` 的类型不为布尔型。
- **RuntimeError** - 当输入音频的shape不为<..., time>。

View File

@ -21,3 +21,12 @@ mindspore.dataset.audio.transforms.BandrejectBiquad
- **sample_rate** (int) - 采样频率单位Hz不能为零。
- **central_freq** (float) - 中心频率单位Hz
- **Q** (float, 可选) - `品质因子 <https://zh.wikipedia.org/wiki/%E5%93%81%E8%B3%AA%E5%9B%A0%E5%AD%90>`_ ,能够反映带宽与采样频率和中心频率的关系,取值范围为(0, 1]默认值0.707。
**异常:**
- **TypeError** - 当 `sample_rate` 的类型不为整型。
- **ValueError** - 当 `sample_rate` 为0。
- **TypeError** - 当 `central_freq` 的类型不为浮点型。
- **TypeError** - 当 `Q` 的类型不为浮点型。
- **ValueError** - 当 `Q` 取值不在(0, 1]范围内。
- **RuntimeError** - 当输入音频的shape不为<..., time>。

View File

@ -20,3 +20,13 @@ mindspore.dataset.audio.transforms.BassBiquad
- **gain** (float) - 期望提升或衰减的音频增益单位dB
- **central_freq** (float, 可选) - 中心频率单位Hz默认值100.0。
- **Q** (float, 可选) - `品质因子 <https://zh.wikipedia.org/wiki/%E5%93%81%E8%B3%AA%E5%9B%A0%E5%AD%90>`_ ,能够反映带宽与采样频率和中心频率的关系,取值范围为(0, 1]默认值0.707。
**异常:**
- **TypeError** - 当 `sample_rate` 的类型不为整型。
- **ValueError** - 当 `sample_rate` 为0。
- **TypeError** - 当 `gain` 的类型不为浮点型。
- **TypeError** - 当 `central_freq` 的类型不为浮点型。
- **TypeError** - 当 `Q` 的类型不为浮点型。
- **ValueError** - 当 `Q` 取值不在(0, 1]范围内。
- **RuntimeError** - 当输入音频的shape不为<..., time>。

View File

@ -10,3 +10,9 @@ mindspore.dataset.audio.transforms.ComplexNorm
**参数:**
- **power** (float, 可选) - 范数的幂取值必须非负默认值1.0。
**异常:**
- **TypeError** - 当 `power` 的类型不为浮点型。
- **ValueError** - 当 `power` 为负数。
- **RuntimeError** - 当输入音频的shape不为<..., complex=2>。

View File

@ -14,3 +14,9 @@ mindspore.dataset.audio.transforms.Contrast
**参数:**
- **enhancement_amount** (float, 可选) - 控制音频增益的量,取值范围为[0,100]默认值75.0。请注意当 `enhancement_amount` 等于0时对比度增强效果仍然会很显著。
**异常:**
- **TypeError** - 当 `enhancement_amount` 的类型不为浮点型。
- **ValueError** - 当 `enhancement_amount` 取值不在[0, 100]范围内。
- **RuntimeError** - 当输入音频的shape不为<..., time>。

View File

@ -14,7 +14,17 @@ mindspore.dataset.audio.transforms.FrequencyMasking
- **mask_start** (int, 可选) - 添加掩码的起始位置,只有当 `iid_masks` 为True时该值才会生效。取值范围为[0, freq_length - frequency_mask_param],其中 `freq_length` 为音频波形在频域的长度默认值0。
- **mask_value** (float, 可选) - 掩码填充值默认值0.0。
**异常:**
- **TypeError** - 当 `iid_masks` 的类型不为布尔型。
- **TypeError** - 当 `freq_mask_param` 的类型不为整型。
- **ValueError** - 当 `freq_mask_param` 大于音频频域长度。
- **TypeError** - 当 `mask_start` 的类型不为整型。
- **ValueError** - 当 `mask_start` 为负数。
- **TypeError** - 当 `mask_value` 的类型不为浮点型。
- **ValueError** - 当 `mask_value` 为负数。
- **RuntimeError** - 当输入音频的shape不为<..., freq, time>。
.. image:: frequency_masking_original.png
.. image:: frequency_masking.png

View File

@ -19,3 +19,12 @@ mindspore.dataset.audio.transforms.LowpassBiquad
- **sample_rate** (int) - 采样频率单位Hz不能为零。
- **cutoff_freq** (float) - 滤波器截止频率单位Hz
- **Q** (float, 可选) - `品质因子 <https://zh.wikipedia.org/wiki/%E5%93%81%E8%B3%AA%E5%9B%A0%E5%AD%90>`_ ,能够反映带宽与采样频率和中心频率的关系,取值范围(0, 1]默认值0.707。
**异常:**
- **TypeError** - 当 `sample_rate` 的类型不为整型。
- **ValueError** - 当 `sample_rate` 为0。
- **TypeError** - 当 `central_freq` 的类型不为浮点型。
- **TypeError** - 当 `Q` 的类型不为浮点型。
- **ValueError** - 当 `Q` 取值不在(0, 1]范围内。
- **RuntimeError** - 当输入音频的shape不为<..., time>。

View File

@ -14,6 +14,17 @@ mindspore.dataset.audio.transforms.TimeMasking
- **mask_start** (int, 可选) - 添加掩码的起始位置,只有当 `iid_masks` 为True时该值才会生效。取值范围为[0, time_length - time_mask_param],其中 `time_length` 为音频波形在时域的长度默认值0。
- **mask_value** (float, 可选) - 掩码填充值默认值0.0。
**异常:**
- **TypeError** - 当 `iid_masks` 的类型不为布尔型。
- **TypeError** - 当 `time_mask_param` 的类型不为整型。
- **ValueError** - 当 `time_mask_param` 大于音频时域长度。
- **TypeError** - 当 `mask_start` 的类型不为整型。
- **ValueError** - 当 `mask_start` 为负数。
- **TypeError** - 当 `mask_value` 的类型不为浮点型。
- **ValueError** - 当 `mask_value` 为负数。
- **RuntimeError** - 当输入音频的shape不为<..., freq, time>。
.. image:: time_masking_original.png
.. image:: time_masking.png

View File

@ -13,6 +13,16 @@ mindspore.dataset.audio.transforms.TimeStretch
- **n_freq** (int, 可选) - STFT中的滤波器组数默认值201。
- **fixed_rate** (float, 可选) - 频谱在时域加快或减缓的比例默认值None表示保持原始速率。
**异常:**
- **TypeError** - 当 `hop_length` 的类型不为整型。
- **ValueError** - 当 `hop_length` 不为正数。
- **TypeError** - 当 `n_freq` 的类型不为整型。
- **ValueError** - 当 `n_freq` 不为正数。
- **TypeError** - 当 `fixed_rate` 的类型不为浮点型。
- **ValueError** - 当 `fixed_rate` 不为正数。
- **RuntimeError** - 当输入音频的shape不为<..., freq, num_frame, complex=2>。
.. image:: time_stretch_rate1.5.png
.. image:: time_stretch_original.png

View File

@ -5,8 +5,8 @@
:class:`SentencePieceTokenizer` 加载类型的枚举值。
可选的枚举值包括SPieceTokenizerLoadType.FILE和SPieceTokenizerLoadTypeMODEL
可选的枚举值包括SPieceTokenizerLoadType.FILE和SPieceTokenizerLoadType.MODEL
- **SPieceTokenizerLoadType.FILE** - 从本地sentencepiece vocab文件中加载sentencepiece分词器。
- **SPieceTokenizerLoadType.MODEL** - 从sentencepiece vocab实例中加载sentencepiece分词器。
- **SPieceTokenizerLoadType.FILE** - 从Vocab文件中加载SentencePiece分词器。
- **SPieceTokenizerLoadType.MODEL** - 从Vocab实例中加载SentencePiece分词器。

View File

@ -7,6 +7,6 @@
可选的枚举值包括SPieceTokenizerOutType.STRING和SPieceTokenizerOutType.INT
- **SPieceTokenizerOutType.STRING** - 表示SentencePice分词器的输出类型为string。
- **SPieceTokenizerOutType.INT** - 表示SentencePice分词器的输出类型为int。
- **SPieceTokenizerOutType.STRING** - 表示SentencePiece分词器的输出类型为string。
- **SPieceTokenizerOutType.INT** - 表示SentencePiece分词器的输出类型为int。

View File

@ -27,11 +27,10 @@
**返回:**
SentencePieceVocab从数据集构建的vocab。
.. py:method:: from_file(file_path, vocab_size, character_coverage, model_type, params)
单词列表中构建一个SentencePiece对象。
文件中构建一个SentencePiece对象。
**参数:**
@ -55,15 +54,13 @@
**返回:**
SentencePieceVocab表示从文件中构建的vocab。
.. py:method:: save_model(vocab, path, filename)
将模型保存到给定的文件路径。
**参数:**
- **vocab** (SentencePieceVocab) - 表示一个SentencePiece对象。
- **path** (str) - 表示存储模型的路径。
- **filename** (str) - 表示文件名称。

View File

@ -3,18 +3,19 @@
.. py:class:: mindspore.dataset.text.Vocab
用于查找单词的vocab对象。
用于查找单词的Vocab对象。
它包含一个映射将每个单词str映射到一个IDint
.. py:method:: from_dataset(dataset, columns=None, freq_range=None, top_k=None, special_tokens=None, special_first=True)
通过数据集构建vocab对象。
通过数据集构建Vocab对象。
这将收集数据集中的所有唯一单词并在freq_range中用户指定的频率范围内返回一个vocab。如果没有单词在该频率上用户将收到预警信息。
vocab中的单词按最高频率到最低频率的顺序进行排列。具有相同频率的单词将按词典顺序进行排列。
**参数:**
- **dataset** (Dataset) - 表示要从中构建vocab的数据集。
- **columns** (list[str],可选) - 表示要从中获取单词的列名。它可以是列名的列表默认值None。如果没有列是string类型将返回错误。
- **freq_range** (tuple可选) - 表示整数元组min_frequencymax_frequency。频率范围内的单词将被保留。0 <= min_frequency <= max_frequency <= total_words。min_frequency=0等同于min_frequency=1。max_frequency > total_words等同于max_frequency = total_words。min_frequency和max_frequency可以为None分别对应于0和total_words默认值None。
@ -23,25 +24,27 @@
- **Special_first** (bool可选) - 表示是否添加 `special_tokens` 到vocab。如果指定了 `special_tokens` 并将 `special_first` 设置为True则添加special_tokens默认值True。
**返回:**
表示从数据集构建的vocab。
Vocab从数据集构建的Vocab对象。
.. py:method:: from_dict(word_dict)
从dict中构建vocab对象。
通过字典构建Vocab对象。
**参数:**
- **word_dict** (dict) - 字典包含word和ID对其中 `word` 应是string类型 `ID` 应是int类型。至于 `ID` 建议从0开始并且不断续。如果 `ID` 为负数将引发ValueError。
**返回:**
Vocab表示从 `dict` 构建的vocab对象。
Vocab从字典构建的Vocab对象。
.. py:method:: from_file(file_path, delimiter='', vocab_size=None, special_tokens=None, special_first=True)
从单词列表构建一个vocab对象。
通过文件构建Vocab对象。
**参数:**
- **file_path** (str) - 表示包含vocab列表的文件的路径。
- **delimiter** (str可选) - 表示用来分隔文件中每一行的分隔符。第一个元素被视为单词,默认值:""。
- **vocab_size** (int可选) - 表示要从 `file_path` 读取的字数默认值None表示读取所有的字。
@ -49,18 +52,20 @@
- **special_first** (list可选) - 表示是否添加 `special_tokens` 到vocab。如果指定了 `special_tokens` 并将 `special_first` 设置为True则添加 `special_tokens` 默认值True。
**返回:**
Vocab表示从文件构建的vocab。
Vocab从文件构建的Vocab对象。
.. py:method:: from_list(word_list, special_tokens=None, special_first=True)
从单词列表构建一个vocab对象。
通过单词列表构建Vocab对象。
**参数:**
- **word_list** (list) - 表示字符串列表其中每个元素都是type类型的单词。
- **special_tokens** (list可选) - 表示字符串的列表。每个字符串都是一个特殊标记例如special_tokens=["<pad>","<unk>"]默认值None表示不添加特殊标记。
- **Special_first** (bool可选) - 表示是否添加 `special_tokens` 到vocab。如果指定了 `special_tokens` 并将 `special_first` 设置为True则添加 `special_tokens` 默认值True。
**返回:**
Vocab表示从 `list` 构建的vocab。
Vocab从单词列表构建的Vocab对象。

View File

@ -6,9 +6,10 @@
基于 `encoding` 字符集对每个元素进行编码,将 `string` 的NumPy数组转换为 `bytes` 的数组。
**参数:**
- **array** (numpy.ndarray) - 表示 `string` 类型的数组,代表字符串。
- **encoding** (str) - 表示用于编码的字符集。
**返回:**
numpy.ndarray表示 `bytes` 的NumPy数组。

View File

@ -6,9 +6,10 @@
基于 `encoding` 字符集对每个元素进行解码,借此将 `bytes` 的NumPy数组转换为 `string` 的数组。
**参数:**
- **array** (numpy.ndarray) - 表示 `bytes` 类型的数组,代表字符串。
- **encoding** (str) - 表示用于解码的字符集。
**返回:**
numpy.ndarray表示 `str` 的NumPy数组。

View File

@ -3,22 +3,21 @@
.. py:class:: mindspore.dataset.text.transforms.BasicTokenizer(lower_case=False, keep_whitespace=False, normalization_form=NormalizeForm.NONE, preserve_unused_token=True, with_offsets=False)
通过特定规则标记UTF-8字符串的标量Tensor
按照指定规则对输入的UTF-8字符串进行分词
.. note::
Windows平台尚不支持BasicTokenizer。
.. note:: Windows平台尚不支持 `BasicTokenizer`
**参数:**
**参数:**
- **lower_case** (bool可选) - 如果为True则在输入文本上应用CaseFold、 `NFD` 模式下的NormalizeUTF8、RegexReplace操作以将文本折叠到较低的用例并删除重音字符。如果为False则仅在输入文本上应用指定模式下的NormalizeUTF8操作默认为False
- **keep_whitespace** (bool可选) - 如果为True则把空白字符保留在输出标记中默认值False。
- **normalization_form** (NormalizeForm可选) - 用于指定归一化模式默认值NormalizeForm.NONE。这仅在 `lower_case` 为False时有效。可选值为NormalizeForm.NONE、NormalizeForm.NFC、NormalizeForm.NFKC、NormalizeForm.NFD和NormalizeForm.NFKD
- **lower_case** (bool可选) - 若为True将对输入执行 :class:`mindspore.dataset.text.transforms.CaseFold` 、NFD模式 :class:`mindspore.dataset.text.transforms.NormalizeUTF8`:class:`mindspore.dataset.text.transforms.RegexReplace` 等操作将文本转换为小写并删除重音字符若为False将只执行 `normalization_form` 模式 :class:`mindspore.dataset.text.transforms.NormalizeUTF8` 操作。默认值False
- **keep_whitespace** (bool可选) - 是否在分词输出中保留空格。默认值False。
- **normalization_form** (:class:`mindspore.dataset.text.NormalizeForm`,可选) - 字符串规范化模式,仅当 `lower_case` 为False时生效取值可为NormalizeForm.NONE、NormalizeForm.NFC、NormalizeForm.NFKC、NormalizeForm.NFD或NormalizeForm.NFKD。默认值NormalizeForm.NONE
- NormalizeForm.NONE对输入字符串不做任何处理。
- NormalizeForm.NFC对输入字符串进行C形式规范化。
- NormalizeForm.NFKC对输入字符串进行KC形式规范化。
- NormalizeForm.NFD对输入字符串进行D形式规范化。
- NormalizeForm.NFKD对输入字符串进行KD形式规范化。
- NormalizeForm.NONE对输入字符串不做任何处理。
- NormalizeForm.NFC对输入字符串进行C形式规范化。
- NormalizeForm.NFKC对输入字符串进行KC形式规范化。
- NormalizeForm.NFD对输入字符串进行D形式规范化。
- NormalizeForm.NFKD对输入字符串进行KD形式规范化。
- **preserve_unused_token** (bool可选) - 如果为True则不要拆分特殊标记如'[CLS]'、'[SEP]'、'[UNK]'、'[PAD]'和'[MASK]'默认值True。
- **with_offsets** (bool可选) - 表示是否输出标记的偏移量,默认值False。
- **preserve_unused_token** (bool可选) - 若为True将不会对特殊词汇进行分词如 '[CLS]', '[SEP]', '[UNK]', '[PAD]', '[MASK]' 等。默认值True。
- **with_offsets** (bool可选) - 是否输出词汇在字符串中的偏移量。默认值False。

View File

@ -0,0 +1,33 @@
mindspore.dataset.text.transforms.BertTokenizer
===============================================
.. py:class:: mindspore.dataset.text.transforms.BertTokenizer(vocab, suffix_indicator='##', max_bytes_per_token=100, unknown_token='[UNK]', lower_case=False, keep_whitespace=False, normalization_form=NormalizeForm.NONE, preserve_unused_token=True, with_offsets=False)
使用Bert分词器对字符串进行分词。
.. note:: Windows平台尚不支持 `BertTokenizer`
**参数:**
- **vocab** (:class:`mindspore.dataset.text.Vocab`) - 用于查词的词汇表。
- **suffix_indicator** (str可选) - 用于指示子词后缀的前缀标志。默认值:'##'。
- **max_bytes_per_token** (int可选) - 分词最大长度超过此长度的词汇将不会被拆分。默认值100。
- **unknown_token** (str可选) - 对未知词汇的分词输出。当设置为空字符串时,直接返回对应未知词汇作为分词输出;否则,返回该字符串作为分词输出。默认值:'[UNK]'。
- **lower_case** (bool可选) - 若为True将对输入执行 :class:`mindspore.dataset.text.transforms.CaseFold` 、NFD模式 :class:`mindspore.dataset.text.transforms.NormalizeUTF8`:class:`mindspore.dataset.text.transforms.RegexReplace` 等操作将文本转换为小写并删除重音字符若为False将只执行 `normalization_form` 模式 :class:`mindspore.dataset.text.transforms.NormalizeUTF8` 操作。默认值False。
- **keep_whitespace** (bool可选) - 是否在分词输出中保留空格。默认值False。
- **normalization_form** (:class:`mindspore.dataset.text.NormalizeForm`,可选) - 字符串规范化模式,仅当 `lower_case` 为False时生效。详见 :class:`mindspore.dataset.text.transforms.NormalizeUTF8` 。默认值NormalizeForm.NONE。
- **preserve_unused_token** (bool可选) - 若为True将不会对特殊词汇进行分词如 '[CLS]', '[SEP]', '[UNK]', '[PAD]', '[MASK]' 等。默认值True。
- **with_offsets** (bool可选) - 是否输出词汇在字符串中的偏移量。默认值False。
**异常:**
- **TypeError** - 当 `vocab` 的类型不为 :class:`mindspore.dataset.text.Vocab`
- **TypeError** - 当 `suffix_indicator` 的类型不为字符串。
- **TypeError** - 当 `max_bytes_per_token` 的类型不为整型。
- **ValueError** - 当 `max_bytes_per_token` 为负数。
- **TypeError** - 当 `unknown_token` 的类型不为字符串。
- **TypeError** - 当 `lower_case` 的类型不为布尔型。
- **TypeError** - 当 `keep_whitespace` 的类型不为布尔型。
- **TypeError** - 当 `normalization_form` 的类型不为 :class:`mindspore.dataset.text.NormalizeForm`
- **TypeError** - 当 `preserve_unused_token` 的类型不为布尔型。
- **TypeError** - 当 `with_offsets` 的类型不为布尔型。

View File

@ -16,5 +16,5 @@ mindspore.dataset.text.transforms.SentencePieceTokenizer
**异常:**
- **TypeError** - 参数 `mode` 的类型不是string:class:`mindspore.dataset.text.SentencePieceVocab`
- **TypeError** - 参数 `mode` 的类型不是字符串:class:`mindspore.dataset.text.SentencePieceVocab`
- **TypeError** - 参数 `out_type` 的类型不是 :class::`mindspore.dataset.text.SPieceTokenizerOutType`

View File

@ -12,6 +12,6 @@ mindspore.dataset.text.transforms.SlidingWindow
**异常:**
- **TypeError** - 参数 `width` 的类型不是int
- **ValueError** - 参数 `width` 的值不是正数。
- **TypeError** - 参数 `axis` 的类型不是int
- **TypeError** - 参数 `width` 的类型不为整型
- **ValueError** - 参数 `width` 不为正数。
- **TypeError** - 参数 `axis` 的类型不为整型

View File

@ -3,22 +3,21 @@ mindspore.dataset.text.transforms.WordpieceTokenizer
.. py:class:: mindspore.dataset.text.transforms.WordpieceTokenizer(vocab, suffix_indicator='##', max_bytes_per_token=100,unknown_token='[UNK]', with_offsets=False)
对输入的1-D字符串分词为子词(subword)标记
将输入的字符串切分为子词
**参数:**
- **vocab** (Vocab) - 词汇表对象。
- **suffix_indicator** (str, 可选) - 用来表示子词是某个词的一部分,默认值:'##'。
- **max_bytes_per_token** (int可选) - 指定最长标记(token)的长度,超过此长度的标记将不会被进一步拆分。
- **unknown_token** (str可选) - 当词表中无法找到某个标记(token)时,将替换为此参数的值。
如果此参数为空字符串,则直接返回该标记。默认值:'[UNK]'。
- **with_offsets** (bool, 可选) - 是否输出标记(token)的偏移量默认值False。
- **vocab** (Vocab) - 用于查词的词汇表。
- **suffix_indicator** (str, 可选) - 用于指示子词后缀的前缀标志。默认值:'##'。
- **max_bytes_per_token** (int可选) - 分词最大长度超过此长度的词汇将不会被拆分。默认值100。
- **unknown_token** (str可选) - 对未知词汇的分词输出。当设置为空字符串时,直接返回对应未知词汇作为分词输出;否则,返回该字符串作为分词输出。默认值:'[UNK]'。
- **with_offsets** (bool, 可选) - 是否输出词汇在字符串中的偏移量。默认值False。
**异常:**
- **TypeError** - 参数 `vocab` 的类型不为text.Vocab
- **TypeError** - 参数 `suffix_indicator` 的类型不为string
- **TypeError** - 参数 `max_bytes_per_token` 的类型不为int
- **TypeError** - 参数 `unknown_token` 的类型不为string
- **TypeError** - 参数 `with_offsets` 的类型不为bool
- **ValueError** - 参数 `max_bytes_per_token` 的值为负数。
- **TypeError** - `vocab` 的类型不为 :class:`mindspore.dataset.text.Vocab`
- **TypeError** - `suffix_indicator` 的类型不为字符串
- **TypeError** - `max_bytes_per_token` 的类型不为整型
- **TypeError** - `unknown_token` 的类型不为字符串
- **TypeError** - `with_offsets` 的类型不为布尔型
- **ValueError** - `max_bytes_per_token` 为负数。

View File

@ -13,5 +13,4 @@ mindspore.dataset.transforms.c_transforms.Compose
- **TypeError** - 参数 `transforms` 类型不为 list。
- **ValueError** - 参数 `transforms` 的长度为空。
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象
或类型不为 :class:`mindspore.dataset.transforms.c_transforms.TensorOperation`
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象或c_transforms模块中的数据处理操作。

View File

@ -11,7 +11,7 @@ mindspore.dataset.transforms.c_transforms.Mask
Relational.EQ、Relational.NE、Relational.LT、 Relational.GT、Relational.LE、Relational.GE。
以Relational.EQ为例将找出Tensor中与 `constant` 相等的元素。
- **constant** (Union[str, int, float, bool]) - 要进行比较的基准值。
- **dtype** (mindspore.dtype, 可选) - 生成的掩码Tensor的数据类型默认值mstype.bool。
- **dtype** (:class:`mindspore.dtype`, 可选) - 生成的掩码Tensor的数据类型默认值:class:`mindspore.dtype.bool_`
**异常:**

View File

@ -14,7 +14,6 @@ mindspore.dataset.transforms.c_transforms.RandomApply
- **TypeError** - 参数 `transforms` 类型不为 list。
- **ValueError** - 参数 `transforms` 的长度为空。
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象
或类型不为 :class:`mindspore.dataset.transforms.c_transforms.TensorOperation`
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象或c_transforms模块中的数据处理操作。
- **TypeError** - 参数 `prob` 的类型不为bool。
- **ValueError** - 参数 `prob` 的取值范围不为[0.0, 1.0]。

View File

@ -13,5 +13,4 @@ mindspore.dataset.transforms.c_transforms.RandomChoice
- **TypeError** - 参数 `transforms` 类型不为 list。
- **ValueError** - 参数 `transforms` 的长度为空。
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象
或类型不为 :class:`mindspore.dataset.transforms.c_transforms.TensorOperation`
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象或c_transforms模块中的数据处理操作。

View File

@ -1,6 +0,0 @@
mindspore.dataset.transforms.c_transforms.TensorOperation
=========================================================
.. py:class:: mindspore.dataset.transforms.c_transforms.TensorOperation()
数据增强处理的基类其作为mindspore.dataset.transforms.c_transforms模块中数据增强的基类。

View File

@ -4,10 +4,18 @@ mindspore.dataset.transforms.c_transforms.Unique
.. py:class:: mindspore.dataset.transforms.c_transforms.Unique()
对输入张量进行唯一运算,每次只支持对一个数据列进行变换。
Unique将返回3个Tensor: 运算结果Tensor索引Tensor计数Tensor。
运算结果Tensor包含输入张量的所有唯一元素且和输入张量的顺序是一样的。
索引Tensor包含输入Tensor的每个元素在运算结果中的索引。
计数Tensor包含运算结果Tensor的每个元素的计数。
.. note:: 这个操作需要在batch操作之后调用.
**异常:**
- **RuntimeError** - 当给定Tensor具有两列。

View File

@ -15,15 +15,19 @@ mindspore.dataset.transforms.py_transforms.Compose
- **transforms** (list) - 一个数据增强的列表。
**异常:**
- **TypeError** - 参数 `transforms` 类型不为 list。
- **ValueError** - 参数 `transforms` 的长度为空。
- **TypeError** - 参数 `transforms` 的元素不是Python的callable对象。
.. py:method:: reduce(operations)
静态方法,可以调用这个函数将多个数据增强算子组合起来
使用Compose将指定数据增强操作列表中相邻的Python操作组合以允许混用Python和C++操作
**参数:**
- **operations** (list) - 数据增强的列表。
- **operations** (list) - 数据增强的列表。
**返回:**
list组合后的数据增强操作列表。

View File

@ -1,7 +0,0 @@
mindspore.dataset.transforms.py_transforms.PyTensorOperation
============================================================
.. py:class:: mindspore.dataset.transforms.py_transforms.PyTensorOperation()
Python 数据增强处理的基类其作为vision、transforms的py_transform模块中数据增强的基类
包括mindspore.dataset.vision.py_transforms、mindspore.dataset.transforms.py_transforms。

View File

@ -14,7 +14,6 @@ mindspore.dataset.transforms.py_transforms.RandomApply
- **TypeError** - 参数 `transforms` 类型不为 list。
- **ValueError** - 参数 `transforms` 的长度为空。
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象
或类型不为 :class:`mindspore.dataset.transforms.py_transforms.PyTensorOperation`
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象或py_transforms模块中的数据处理操作。
- **TypeError** - 参数 `prob` 的类型不为bool。
- **ValueError** - 参数 `prob` 的取值范围不为[0.0, 1.0]。

View File

@ -12,6 +12,5 @@ mindspore.dataset.transforms.py_transforms.RandomChoice
**异常:**
- **TypeError** - 参数 `transforms` 类型不为 list。
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象
或类型不为 :class:`mindspore.dataset.transforms.py_transforms.PyTensorOperation`
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象或py_transforms模块中的数据处理操作。
- **ValueError** - 参数 `transforms` 的长度为空。

View File

@ -12,6 +12,5 @@ mindspore.dataset.transforms.py_transforms.RandomOrder
**异常:**
- **TypeError** - 参数 `transforms` 类型不为 list。
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象
或类型不为 :class:`mindspore.dataset.transforms.py_transforms.PyTensorOperation`
- **TypeError** - 参数 `transforms` 的元素不是Python可调用对象或py_transforms模块中的数据处理操作。
- **ValueError** - 参数 `transforms` 的长度为空。

View File

@ -12,7 +12,7 @@ mindspore.dataset.vision.c_transforms.BoundingBoxAugment
**异常:**
- **TypeError** - 如果 `transform` 不是 :class:`mindspore.dataset.vision.c_transforms.ImageTensorOperation` 的类型
- **TypeError** - 如果 `transform` 不是 :class:`mindspore.dataset.vision.c_transforms` 模块中的图像处理操作
- **TypeError** - 如果 `ratio` 不是float类型。
- **ValueError** - 如果 `ratio` 不在 [0, 1] 范围内。
- **RuntimeError** - 如果给定的边界框无效。

View File

@ -8,3 +8,9 @@ mindspore.dataset.vision.c_transforms.RandomResizeWithBBox
**参数:**
- **size** (Union[int, sequence]) - 调整后图像的输出大小。如果 `size` 是一个整数,图像的短边将被调整为 `size` 大小,并依据短边的调整比例相应调整图像长边的大小。如果 `size` 是一个长度为2的序列其输入格式应该为 (height, width)。
**异常:**
- **TypeError** - 当 `size` 的类型不为整型或整型序列。
- **ValueError** - 当 `size` 不为正数。
- **RuntimeError** - 当输入图像的shape不为<H, W>或<H, W, C>。

View File

@ -21,3 +21,16 @@ mindspore.dataset.vision.c_transforms.RandomResizedCrop
- Inter.PILCUBIC`pillow` 中实现的双三次插值效果一致输入应为3通道格式。
- **max_attempts** (int, optional): 生成随机裁剪位置的最大尝试次数超过该次数时将使用中心裁剪默认值10。
**异常:**
- **TypeError** - 当 `size` 的类型不为整型或整型序列。
- **TypeError** - 当 `scale` 的类型不为元组。
- **TypeError** - 当 `ratio` 的类型不为元组。
- **TypeError** - 当 `interpolation` 的类型不为 :class:`mindspore.dataset.vision.Inter`
- **TypeError** - 当 `max_attempts` 的类型不为整型。
- **ValueError** - 当 `size` 不为正数。
- **ValueError** - 当 `scale` 为负数。
- **ValueError** - 当 `ratio` 为负数。
- **ValueError** - 当 `max_attempts` 不为正数。
- **RuntimeError** 当输入图像的shape不为<H, W>或<H, W, C>。

View File

@ -17,3 +17,16 @@ mindspore.dataset.vision.c_transforms.RandomResizedCropWithBBox
- Inter.BICUBIC双三次插值。
- **max_attempts** (int, optional): 生成随机裁剪位置的最大尝试次数超过该次数时将使用中心裁剪默认值10。
**异常:**
- **TypeError** - 当 `size` 的类型不为整型或整型序列。
- **TypeError** - 当 `scale` 的类型不为元组。
- **TypeError** - 当 `ratio` 的类型不为元组。
- **TypeError** - 当 `interpolation` 的类型不为 :class:`mindspore.dataset.vision.Inter`
- **TypeError** - 当 `max_attempts` 的类型不为整型。
- **ValueError** - 当 `size` 不为正数。
- **ValueError** - 当 `scale` 为负数。
- **ValueError** - 当 `ratio` 为负数。
- **ValueError** - 当 `max_attempts` 不为正数。
- **RuntimeError** 当输入图像的shape不为<H, W>或<H, W, C>。

View File

@ -17,3 +17,13 @@ mindspore.dataset.vision.c_transforms.RandomRotation
- **expand** (bool, optional) - 图像大小拓宽标志若为True将扩展图像大小使其足以容纳整个旋转图像若为False或未指定则保持输出图像与输入图像大小一致。请注意扩展时将假设图像为中心旋转且未进行平移默认值False。
- **center** (tuple, optional) - 可选的旋转中心,以图像左上角为原点,旋转中心的位置按照 (width, height) 格式指定。默认值None表示中心旋转。
- **fill_value** (Union[int, tuple], optional) - 旋转图像之外区域的像素填充值。若输入3元素元组将分别用于填充R、G、B通道若输入整型将以该值填充RGB通道。 `fill_value` 值必须在 [0, 255] 范围内默认值0。
**异常:**
- **TypeError** - 当 `degrees` 的类型不为整型、浮点型或序列。
- **TypeError** - 当 `resample` 的类型不为 :class:`mindspore.dataset.vision.Inter`
- **TypeError** - 当 `expand` 的类型不为布尔型。
- **TypeError** - 当 `center` 的类型不为元组。
- **TypeError** - 当 `fill_value` 的类型不为整型或整型序列。
- **ValueError** - 当 `fill_value` 取值不在[0, 255]范围内。
- **RuntimeError** - 当输入图像的shape不为<H, W>或<H, W, C>。

View File

@ -7,4 +7,8 @@ mindspore.dataset.vision.c_transforms.RandomSelectSubpolicy
**参数:**
- **policy** (list(list(tuple(TensorOp, prob (float))))) - 可供选择的子策略列表。 子策略是一系列 (op, prob) 格式的元组组成的列表,其中 `op` 是针对 Tensor 的操作, `prob` 是应用此操作的概率, `prob` 值必须在 [0, 1] 范围内。 一旦选择了子策略,子策略中的每个操作都将根据其概率依次应用。
- **policy** (list[list[tuple[TensorOperation, float]]]) - 可供选择的子策略列表。子策略是一系列 (operation, prob) 格式的元组组成的列表,其中 `operation` 是数据处理操作, `prob` 是应用此操作的概率, `prob` 值必须在 [0, 1] 范围内。 一旦选择了子策略,子策略中的每个操作都将根据其概率依次应用。
**异常:**
- **TypeError** - 当 `policy` 包含无效数据处理操作。

View File

@ -8,3 +8,8 @@ mindspore.dataset.vision.c_transforms.RandomSolarize
**参数:**
- **threshold** (tuple, optional) - 随机曝光的阈值范围默认值0, 255`threshold` 输入格式应该为 (min, max),其中 `min``max` 是 (0, 255) 范围内的整数,并且 min <= max。 如果 min=max则反转所有高于 min(或max) 的像素值。
**异常:**
- **TypeError** - 当 `threshold` 的类型不为元组。
- **ValueError** - 当 `threshold` 取值不在[0, 255]范围内。

View File

@ -10,3 +10,7 @@ mindspore.dataset.vision.c_transforms.Rescale
- **rescale** (float) - 缩放因子。
- **shift** (float) - 平移因子。
**异常:**
- **TypeError** - 当 `rescale` 的类型不为浮点型。
- **TypeError** - 当 `shift` 的类型不为浮点型。

View File

@ -17,3 +17,13 @@ mindspore.dataset.vision.c_transforms.Rotate
- **expand** (bool, optional) - 图像大小拓宽标志若为True将扩展图像大小使其足以容纳整个旋转图像若为False或未指定则保持输出图像与输入图像大小一致。请注意扩展时将假设图像为中心旋转且未进行平移默认值False。
- **center** (tuple, optional) - 可选的旋转中心,以图像左上角为原点,旋转中心的位置按照 (width, height) 格式指定。默认值None表示中心旋转。
- **fill_value** (Union[int, tuple], optional) - 旋转图像之外区域的像素填充值。若输入3元素元组将分别用于填充R、G、B通道若输入整型将以该值填充RGB通道。 `fill_value` 值必须在 [0, 255] 范围内默认值0。
**异常:**
- **TypeError** - 当 `degrees` 的类型不为整型、浮点型或序列。
- **TypeError** - 当 `resample` 的类型不为 :class:`mindspore.dataset.vision.Inter`
- **TypeError** - 当 `expand` 的类型不为布尔型。
- **TypeError** - 当 `center` 的类型不为元组。
- **TypeError** - 当 `fill_value` 的类型不为整型或整型序列。
- **ValueError** - 当 `fill_value` 取值不在[0, 255]范围内。
- **RuntimeError** - 当输入图像的shape不为<H, W>或<H, W, C>。

View File

@ -28,10 +28,10 @@
按列名一次返回一个batch的数据。
**返回:**
**返回:**
Dictkey与数据列的列名相同的一个batch的数据
dict下一批数据键值与数据列名相同
**异常:**
**异常:**
- **MRMUnsupportedSchemaError** - schema无效。
- **MRMUnsupportedSchemaError** - schema无效。

View File

@ -10,6 +10,7 @@
- **file_name** (str) - 转换生成的MindRecord文件路径。
- **shard_num** (int可选) - 生成MindRecord的文件个数。默认值1。取值范围为[1, 1000]。
- **overwrite** (bool可选) - 当指定目录存在同名文件时是否覆盖写。默认值False。
**异常:**

View File

@ -10,12 +10,12 @@
- **map_file** (str) - 标签映射文件的路径。映射文件内容如下:
.. code-block::
.. code-block::
n02119789 0
n02100735 1
n02110185 2
n02096294 3
n02119789 0
n02100735 1
n02110185 2
n02096294 3
- **image_dir** (str) - ImageNet数据集的目录路径目录中包含类似n02119789、n02100735、n02110185和n02096294的子目录。
- **destination** (str) - 转换生成的MindRecord文件路径

View File

@ -9,7 +9,6 @@ API示例所需模块的导入代码如下
import mindspore.dataset as ds
.. py:function:: mindspore.dataset.config.get_auto_num_workers()
获取当前是否开启自动线程调整。
@ -17,7 +16,6 @@ API示例所需模块的导入代码如下
**返回:**
bool表示是否开启自动线程调整。
.. py:function:: mindspore.dataset.config.get_callback_timeout()
@ -27,16 +25,17 @@ API示例所需模块的导入代码如下
**返回:**
int表示在出现死锁情况下用于结束DSWaitedCallback中的等待函数的超时时间
.. py:function:: mindspore.dataset.config.get_enable_shared_mem()
获取当前是否开启共享内存。
.. note::
Windows和MacOS平台尚不支持 `get_enable_shared_mem`
**返回:**
bool表示是否启用共享内存。
.. py:function:: mindspore.dataset.config.get_monitor_sampling_interval()
@ -45,7 +44,6 @@ API示例所需模块的导入代码如下
**返回:**
int表示性能监控采样间隔时间毫秒
.. py:function:: mindspore.dataset.config.get_numa_enable()
@ -55,7 +53,6 @@ API示例所需模块的导入代码如下
**返回:**
bool表示NUMA的启动状态。
.. py:function:: mindspore.dataset.config.get_num_parallel_workers()
@ -65,7 +62,6 @@ API示例所需模块的导入代码如下
**返回:**
int表示每个操作中默认的并行工作进程的数量。
.. py:function:: mindspore.dataset.config.get_prefetch_size()
@ -74,7 +70,6 @@ API示例所需模块的导入代码如下
**返回:**
int表示预取的总行数。
.. py:function:: mindspore.dataset.config.get_seed()
@ -83,7 +78,6 @@ API示例所需模块的导入代码如下
**返回:**
int表示种子的随机数量。
.. py:function:: mindspore.dataset.config.load(file)
@ -96,7 +90,6 @@ API示例所需模块的导入代码如下
**异常:**
- **RuntimeError** - 文件无效,解析失败。
.. py:function:: mindspore.dataset.config.set_auto_num_workers(enable)
@ -115,7 +108,6 @@ API示例所需模块的导入代码如下
**异常:**
- **TypeError** - enable不是布尔类型。
.. py:function:: mindspore.dataset.config.set_callback_timeout(timeout)
@ -129,12 +121,14 @@ API示例所需模块的导入代码如下
**异常:**
- **ValueError** - `timeout` 小于等于0或 `timeout` 大于MAX_INT_32时 `timeout` 无效。
.. py:function:: mindspore.dataset.config.set_enable_shared_mem(enable)
设置共享内存标志的是否启用。如果 `shared_mem_enable` 为True则使用共享内存队列将数据传递给为数据集操作而创建的进程而这些数据集操作将设置 `python_multiprocessing` 为True。
.. note::
Windows和MacOS平台尚不支持 `set_enable_shared_mem`
**参数:**
- **enable** (bool) - 表示当 `python_multiprocessing` 为True时是否在数据集操作中使用共享内存。
@ -142,7 +136,6 @@ API示例所需模块的导入代码如下
**异常:**
- **TypeError** - `enable` 不是布尔数据类型。
.. py:function:: mindspore.dataset.config.set_monitor_sampling_interval(interval)
@ -155,7 +148,6 @@ API示例所需模块的导入代码如下
**异常:**
- **ValueError** - `interval` 小于等于0或 `interval` 大于MAX_INT_32时 `interval` 无效。
.. py:function:: mindspore.dataset.config.set_numa_enable(numa_enable)
@ -168,7 +160,6 @@ API示例所需模块的导入代码如下
**异常:**
- **TypeError** - `numa_enable` 不是布尔数据类型。
.. py:function:: mindspore.dataset.config.set_num_parallel_workers(num)
@ -182,7 +173,6 @@ API示例所需模块的导入代码如下
**异常:**
- **ValueError** - `num` 小于等于0或 `num` 大于MAX_INT_32时并行工作线程数量设置无效。
.. py:function:: mindspore.dataset.config.set_prefetch_size(size)
@ -199,7 +189,6 @@ API示例所需模块的导入代码如下
.. note::
用于预取的总内存可能会随着工作线程数量的增加而快速增长所以当工作线程数量大于4时每个工作线程的预取大小将减少。
每个工作线程在运行时预取大小将是 `prefetchsize` * (4 / `num_parallel_workers` )。
.. py:function:: mindspore.dataset.config.set_seed(seed)
@ -215,7 +204,6 @@ API示例所需模块的导入代码如下
**异常:**
- **ValueError** - `seed` 小于0或 `seed` 大于MAX_UINT_32时 `seed` 无效。
.. py:function:: mindspore.dataset.config.set_sending_batches(batch_num)
@ -229,5 +217,60 @@ API示例所需模块的导入代码如下
- **TypeError** - `batch_num` 不是int类型。
.. py:function:: mindspore.dataset.config.set_enable_autotune(enable, json_filepath=None)
设置是否开启自动数据加速。
自动数据加速用于在训练过程中根据环境资源的负载,自动调整数据处理管道全局配置,提高数据处理的速度。
可以通过设置 `json_filepath` 将优化后的全局配置保存为JSON文件以便后续复用。
**参数:**
- **enable** (bool) - 是否开启自动数据加速。
- **json_filepath** (str可选) - 优化后的全局配置的保存路径当路径存在同名文件时会自动覆盖。默认值None表示不保存配置文件。
**异常:**
- **TypeError** - 当 `enable` 的类型不为布尔型。
- **TypeError** - 当 `json_filepath` 的类型不为字符串。
- **RuntimeError** - 当 `json_filepath` 为空字符串。
- **RuntimeError** - 当 `json_filepath` 为目录。
- **RuntimeError** - 当 `json_filepath` 路径不存在。
- **RuntimeError** - 当 `json_filepath` 没有写入权限。
.. note::`enable` 为 False 时,`json_filepath` 值将会被忽略。
.. py:function:: mindspore.dataset.config.get_enable_autotune()
获取当前是否开启自动数据加速。
**返回:**
bool表示是否开启自动数据加速。
.. py:function:: mindspore.dataset.config.set_autotune_interval(interval)
设置自动数据加速的配置调整step间隔。
默认设置为0将在每个epoch结束后调整配置否则将每隔 `interval` 个step调整一次配置。
**参数:**
- **interval** (int) - 配置调整的step间隔。
**异常:**
- **TypeError** - 当 `interval` 类型不为整型。
- **ValueError** - 当 `interval` 不为非负数。
.. py:function:: mindspore.dataset.config.get_autotune_interval()
获取当前自动数据加速的配置调整step间隔。
**返回:**
int自动数据加速的配置调整step间隔。
.. automodule:: mindspore.dataset.config
:members:

View File

@ -7,7 +7,6 @@ mindspore.dataset.text
`utils` 提供了一些文本处理的工具方法。
在API示例中常用的模块导入方法如下
.. code-block::
@ -15,6 +14,11 @@ mindspore.dataset.text
import mindspore.dataset as ds
from mindspore.dataset import text
常用数据处理术语说明如下:
- TensorOperation所有C++实现的数据处理操作的基类。
- TextTensorOperation所有文本数据处理操作的基类派生自TensorOperation。
mindspore.dataset.text.transforms
---------------------------------

View File

@ -17,6 +17,11 @@ mindspore.dataset.transforms
from mindspore.dataset.transforms import c_transforms
from mindspore.dataset.transforms import py_transforms
常用数据处理术语说明如下:
- TensorOperation所有C++实现的数据处理操作的基类。
- PyTensorOperation所有Python实现的数据处理操作的基类。
mindspore.dataset.transforms.c_transforms
-----------------------------------------

View File

@ -13,6 +13,12 @@ API样例中常用的导入模块如下
import mindspore.dataset.vision.py_transforms as py_vision
from mindspore.dataset.transforms import c_transforms
常用数据处理术语说明如下:
- TensorOperation所有C++实现的数据处理操作的基类。
- PyTensorOperation所有Python实现的数据处理操作的基类。
- ImageTensorOperation所有图像数据处理操作的基类派生自TensorOperation。
mindspore.dataset.vision.c_transforms
------------------------------------------------

View File

@ -24,6 +24,11 @@ Common imported modules in corresponding API examples are as follows:
import mindspore.dataset as ds
import mindspore.dataset.audio.transforms as audio
Descriptions of common data processing terms are as follows:
- TensorOperation, the base class of all data processing operations implemented in C++.
- AudioTensorOperation, the base class of all audio processing operations. It is a derived class of TensorOperation.
"""
from . import transforms
from .utils import *

View File

@ -125,7 +125,7 @@ class AmplitudeToDB(AudioTensorOperation):
top_db (float, optional): Minimum cut-off decibels, which must be non-negative. Default: 80.0.
Raises:
TypeError: If `stype` is not of type ScaleType.
TypeError: If `stype` is not of type :class:`mindspore.dataset.audio.utils.ScaleType`.
TypeError: If `ref_value` is not of type float.
ValueError: If `ref_value` is not a positive number.
TypeError: If `amin` is not of type float.
@ -870,9 +870,9 @@ class FrequencyMasking(AudioTensorOperation):
Raises:
TypeError: If `iid_masks` is not of type bool.
TypeError: If `freq_mask_param` is not of type integer.
ValueError: If `freq_mask_param` is out of range of the length of audio waveform in frequency domain.
ValueError: If `freq_mask_param` is greater than the length of audio waveform in frequency domain.
TypeError: If `mask_start` is not of type integer.
ValueError: If `mask_start` is out of range.
ValueError: If `mask_start` is a negative number.
TypeError: If `mask_value` is not of type float.
ValueError: If `mask_value` is a negative number.
RuntimeError: If input tensor is not in shape of <..., freq, time>.
@ -1492,9 +1492,9 @@ class TimeMasking(AudioTensorOperation):
Raises:
TypeError: If `iid_masks` is not of type bool.
TypeError: If `time_mask_param` is not of type integer.
ValueError: If `time_mask_param` is out of range of the length of audio waveform in time domain.
ValueError: If `time_mask_param` is greater than the length of audio waveform in time domain.
TypeError: If `mask_start` is not of type integer.
ValueError: If `mask_start` is out of range.
ValueError: If `mask_start` a negative number.
TypeError: If `mask_value` is not of type float.
ValueError: If `mask_value` is a negative number.
RuntimeError: If input tensor is not in shape of <..., freq, time>.

View File

@ -13,7 +13,7 @@
# limitations under the License.
# ==============================================================================
"""
Validators for TensorOps.
Validators for Audio processing operations.
"""
from functools import wraps

View File

@ -424,34 +424,37 @@ def load(file):
def set_enable_autotune(enable, json_filepath=None):
"""
Set the default state of AutoTune flag. If it is True, will facilitate users to improve the
performance for a given workload by automatically finding better settings for data pipeline.
Optionally save the AutoTuned data pipeline configuration to a JSON file, which
can be loaded with deserialize().
Set whether to enable AutoTune.
AutoTune is used to automatically adjust the global configuration of the data pipeline
according to the workload of environmental resources during the training process to
improve the speed of data processing.
The optimized global configuration can be saved as a JSON file by setting `json_filepath`
for subsequent reuse.
Args:
enable (bool): Whether to use AutoTune feature when running data pipeline.
json_filepath (str, optional): The filepath where the AutoTuned data pipeline
configuration will be generated as a JSON file. If the file already exists,
it will be overwritten. If no AutoTuned data pipeline configuration is desired,
then set json_filepath to None (Default=None).
enable (bool): Whether to enable AutoTune.
json_filepath (str, optional): The filepath to save the optimized global configuration.
If the file already exists, it will be automatically overwritten. Default: None,
means not to save the configuration file.
Raises:
TypeError: If enable is not a boolean data type.
TypeError: If json_filepath is not a str value.
RuntimeError: If the value of json_filepath is the empty string.
RuntimeError: If json_filepath a directory.
RuntimeError: If parent path for json_filepath does not exist.
RuntimeError: If parent path for json_filepath does not have write permission.
TypeError: If `enable` is not of type boolean.
TypeError: If `json_filepath` is not of type str.
RuntimeError: If `json_filepath` is an empty string.
RuntimeError: If `json_filepath` is a directory.
RuntimeError: If `json_filepath` does not exist.
RuntimeError: If `json_filepath` does not have write permission.
Note:
When using enable is False, the value of json_filepath is ignored.
When `enable` is False, `json_filepath` will be ignored.
Examples:
>>> # Enable AutoTune and save AutoTuned data pipeline configuration
>>> # enable AutoTune and save optimized data pipeline configuration
>>> ds.config.set_enable_autotune(True, "/path/to/autotune_out.json")
>>>
>>> # Enable AutoTune
>>> # enable AutoTune
>>> ds.config.set_enable_autotune(True)
"""
if not isinstance(enable, bool):
@ -475,13 +478,13 @@ def set_enable_autotune(enable, json_filepath=None):
def get_enable_autotune():
"""
Get the default state of AutoTune enabled variable.
Get whether AutoTune is currently enabled.
Returns:
bool, the state of AutoTune enabled variable (default=True).
bool, whether AutoTune is currently enabled.
Examples:
>>> # Get the flag of AutoTune feature.
>>> # get the state of AutoTune
>>> autotune_flag = ds.config.get_enable_autotune()
"""
return _config.get_enable_autotune()
@ -489,18 +492,20 @@ def get_enable_autotune():
def set_autotune_interval(interval):
"""
Set the interval (in steps) for data pipeline autotuning. Setting interval to 0
configures autotune to run after every epoch instead of after a certain number of steps.
Default value is set to 0, meaning epoch based autotuning.
Set the configuration adjustment interval (in steps) for AutoTune.
The default setting is 0, which will adjust the configuration after each epoch.
Otherwise, the configuration will be adjusted every `interval` steps.
Args:
interval (int): Interval (in steps) to serve as gap for consecutive AutoTune runs.
interval (int): Interval (in steps) to adjust the configuration of the data pipeline.
Raises:
ValueError: If interval is invalid when interval < 0 or interval > MAX_INT_32.
TypeError: If `interval` is not of type int.
ValueError: If `interval` is not non-negative.
Examples:
>>> # Set a new global configuration value for the autotuning interval.
>>> # set a new interval for AutoTune
>>> ds.config.set_autotune_interval(30)
"""
if not isinstance(interval, int):
@ -512,14 +517,13 @@ def set_autotune_interval(interval):
def get_autotune_interval():
"""
Get the global configuration of pipeline autotuning step interval.
Get the current configuration adjustment interval (in steps) for AutoTune.
Returns:
int, interval (in steps) for data pipeline autotuning.
int, the configuration adjustment interval (in steps) for AutoTune.
Examples:
>>> # Get the global configuration of the autotuning interval.
>>> # If set_autotune_interval() is never called before, the default value(30) will be returned.
>>> # get the global configuration of the autotuning interval
>>> autotune_interval = ds.config.get_autotune_interval()
"""
return _config.get_autotune_interval()

View File

@ -47,7 +47,7 @@ class DatasetCache:
>>> # In the following code, suppose the session_id is 780643335
>>> some_cache = ds.DatasetCache(session_id=780643335, size=0)
>>>
>>> dataset_dir = "/path/to/imagefolder_directory"
>>> dataset_dir = "/path/to/image_folder_dataset_directory"
>>> ds1 = ds.ImageFolderDataset(dataset_dir, cache=some_cache)
"""

View File

@ -723,7 +723,7 @@ class Dataset:
columns will be in the same order as specified in column_order.
Args:
operations (Union[list[TensorOp], list[functions]]): List of operations to be
operations (Union[list[TensorOperation], list[functions]]): List of operations to be
applied on the dataset. Operations are applied in the order they appear in this list.
input_columns (Union[str, list[str]], optional): List of the names of the columns that will be passed to
the first operation as input. The size of this list must match the number of
@ -2969,7 +2969,7 @@ class MapDataset(UnionBaseDataset):
Args:
input_dataset (Dataset): Input Dataset to be mapped.
operations (TensorOp): A function mapping a nested structure of tensors
operations (Union[list[TensorOperation], list[functions]]): A function mapping a nested structure of tensors
to another nested structure of tensor (default=None).
input_columns (Union[str, list[str]]): List of names of the input columns
(default=None, the operations will be applied on the first columns in the dataset).

View File

@ -23,6 +23,11 @@ Common imported modules in corresponding API examples are as follows:
import mindspore.dataset as ds
from mindspore.dataset import text
Descriptions of common data processing terms are as follows:
- TensorOperation, the base class of all data processing operations implemented in C++.
- TextTensorOperation, the base class of all text processing operations. It is a derived class of TensorOperation.
"""
import platform
from .transforms import Lookup, JiebaTokenizer, UnicodeCharTokenizer, Ngram, WordpieceTokenizer, \

View File

@ -302,7 +302,7 @@ class Lookup(TextTensorOperation):
class Ngram(TextTensorOperation):
"""
TensorOp to generate n-gram from a 1-D string Tensor.
Generate n-gram from a 1-D string Tensor.
Refer to https://en.wikipedia.org/wiki/N-gram#Examples for an overview of what n-gram is and how it works.
@ -580,23 +580,25 @@ class UnicodeCharTokenizer(TextTensorOperation):
class WordpieceTokenizer(TextTensorOperation):
"""
Tokenize scalar token or 1-D tokens to 1-D subword tokens.
Tokenize the input text to subword tokens.
Args:
vocab (Vocab): A vocabulary object.
suffix_indicator (str, optional): Used to show that the subword is the last part of a word (default='##').
max_bytes_per_token (int, optional): Tokens exceeding this length will not be further split (default=100).
unknown_token (str, optional): When a token cannot be found: if 'unknown_token' is empty string,
return the token directly, else return 'unknown_token' (default='[UNK]').
with_offsets (bool, optional): Whether or not output offsets of tokens (default=False).
vocab (Vocab): Vocabulary used to look up words.
suffix_indicator (str, optional): Prefix flags used to indicate subword suffixes. Default: '##'.
max_bytes_per_token (int, optional): The maximum length of tokenization, words exceeding this length will
not be split. Default: 100.
unknown_token (str, optional): The output for unknown words. When set to an empty string, the corresponding
unknown word will be directly returned as the output. Otherwise, the set string will be returned as the
output. Default: '[UNK]'.
with_offsets (bool, optional): Whether to return the offsets of tokens. Default: False.
Raises:
TypeError: If `vocab` is not of type text.Vocab.
TypeError: If `suffix_indicator` is not of type string.
TypeError: If `vocab` is not of type :class:`mindspore.dataset.text.Vocab`.
TypeError: If `suffix_indicator` is not of type str.
TypeError: If `max_bytes_per_token` is not of type int.
TypeError: If `unknown_token` is not of type string.
TypeError: If `unknown_token` is not of type str.
TypeError: If `with_offsets` is not of type bool.
ValueError: If value of `max_bytes_per_token` is negative.
ValueError: If `max_bytes_per_token` is negative.
Supported Platforms:
``CPU``
@ -680,29 +682,30 @@ if platform.system().lower() != 'windows':
class BasicTokenizer(TextTensorOperation):
"""
Tokenize a scalar tensor of UTF-8 string by specific rules.
Tokenize the input UTF-8 string by specific rules.
Note:
BasicTokenizer is not supported on Windows platform yet.
`BasicTokenizer` is not supported on Windows platform yet.
Args:
lower_case (bool, optional): If True, apply CaseFold, NormalizeUTF8 with `NFD` mode, RegexReplace operation
on input text to fold the text to lower case and strip accents characters. If False, only apply
NormalizeUTF8 operation with the specified mode on input text (default=False).
keep_whitespace (bool, optional): If True, the whitespace will be kept in output tokens (default=False).
normalization_form (NormalizeForm, optional): Used to specify a specific normalize mode
(default=NormalizeForm.NONE). This is only effective when `lower_case` is False. It can be any of
[NormalizeForm.NONE, NormalizeForm.NFC, NormalizeForm.NFKC, NormalizeForm.NFD, NormalizeForm.NFKD].
lower_case (bool, optional): If True, will apply `CaseFold`, NormalizeForm.NFD mode `NormalizeUTF8`,
`RegexReplace` operations on the input to fold the text to lower case and strip accented characters.
If False, will only apply `NormalizeUTF8` operation of mode `normalization_form` on the input.
Default: False.
keep_whitespace (bool, optional): If True, the whitespace will be kept in the output. Default: False.
normalization_form (NormalizeForm, optional): Normalization mode, only valid when `lower_case` is False,
can be NormalizeForm.NONE, NormalizeForm.NFC, NormalizeForm.NFKC, NormalizeForm.NFD or
NormalizeForm.NFKD. Default: NormalizeForm.NONE.
- NormalizeForm.NONE, do nothing for input string tensor.
- NormalizeForm.NONE, do nothing for input string.
- NormalizeForm.NFC, normalize with Normalization Form C.
- NormalizeForm.NFKC, normalize with Normalization Form KC.
- NormalizeForm.NFD, normalize with Normalization Form D.
- NormalizeForm.NFKD, normalize with Normalization Form KD.
preserve_unused_token (bool, optional): If True, do not split special tokens like
'[CLS]', '[SEP]', '[UNK]', '[PAD]', '[MASK]' (default=True).
with_offsets (bool, optional): Whether or not output offsets of tokens (default=False).
preserve_unused_token (bool, optional): If True, will not split special tokens like
'[CLS]', '[SEP]', '[UNK]', '[PAD]', '[MASK]'. Default: True.
with_offsets (bool, optional): Whether to return the offsets of tokens. Default: False.
Examples:
>>> from mindspore.dataset.text import NormalizeForm
@ -752,34 +755,36 @@ if platform.system().lower() != 'windows':
Tokenizer used for Bert text process.
Note:
BertTokenizer is not supported on Windows platform yet.
`BertTokenizer` is not supported on Windows platform yet.
Args:
vocab (Vocab): A vocabulary object.
suffix_indicator (str, optional): Used to show that the subword is the last part of a word (default='##').
max_bytes_per_token (int, optional): If Tokens exceeding this length, it will not be further
split (default=100).
unknown_token (str, optional): When an unknown token is found, return the token directly if `unknown_token`
is an empty string, else return `unknown_token` instead (default='[UNK]').
lower_case (bool, optional): If True, apply CaseFold, NormalizeUTF8 with `NFD` mode, RegexReplace operation
on input text to fold the text to lower case and strip accented characters. If False, only apply
NormalizeUTF8 operation with the specified mode on input text (default=False).
keep_whitespace (bool, optional): If True, the whitespace will be kept in out tokens (default=False).
normalization_form (NormalizeForm, optional): This parameter is used to specify a specific normalize mode,
only effective when `lower_case` is False. See NormalizeUTF8 for details (default=NormalizeForm.NONE).
preserve_unused_token (bool, optional): If True, do not split special tokens like
'[CLS]', '[SEP]', '[UNK]', '[PAD]', '[MASK]' (default=True).
with_offsets (bool, optional): Whether or not output offsets of tokens (default=False).
vocab (Vocab): Vocabulary used to look up words.
suffix_indicator (str, optional): Prefix flags used to indicate subword suffixes. Default: '##'.
max_bytes_per_token (int, optional): The maximum length of tokenization, words exceeding this length will
not be split. Default: 100.
unknown_token (str, optional): The output for unknown words. When set to an empty string, the corresponding
unknown word will be directly returned as the output. Otherwise, the set string will be returned as the
output. Default: '[UNK]'.
lower_case (bool, optional): If True, will apply `CaseFold`, NormalizeForm.NFD mode `NormalizeUTF8`,
`RegexReplace` operations on the input to fold the text to lower case and strip accented characters.
If False, will only apply `NormalizeUTF8` operation of mode `normalization_form` on the input.
Default: False.
keep_whitespace (bool, optional): If True, the whitespace will be kept in the output. Default: False.
normalization_form (NormalizeForm, optional): Normalization mode, only valid when `lower_case` is False.
See `NormalizeUTF8` for details. Default: NormalizeForm.NONE.
preserve_unused_token (bool, optional): If True, will not split special tokens like
'[CLS]', '[SEP]', '[UNK]', '[PAD]', '[MASK]'. Default: True.
with_offsets (bool, optional): Whether to return the offsets of tokens. Default: False.
Raises:
TypeError: If `vocab` is not of type text.Vocab.
TypeError: If `suffix_indicator` is not of type string.
TypeError: If `vocab` is not of type :class:`mindspore.dataset.text.Vocab`.
TypeError: If `suffix_indicator` is not of type str.
TypeError: If `max_bytes_per_token` is not of type int.
ValueError: If `max_bytes_per_token` is a negative number.
TypeError: If `unknown_token` is not of type string.
ValueError: If `max_bytes_per_token` is negative.
TypeError: If `unknown_token` is not of type str.
TypeError: If `lower_case` is not of type bool.
TypeError: If `keep_whitespace` is not of type bool.
TypeError: If `normalization_form` is not of type NormalizeForm.
TypeError: If `normalization_form` is not of type :class:`mindspore.dataset.text.NormalizeForm`.
TypeError: If `preserve_unused_token` is not of type bool.
TypeError: If `with_offsets` is not of type bool.
@ -813,7 +818,6 @@ if platform.system().lower() != 'windows':
... "offsets_limit"],
... column_order=["token", "offsets_start",
... "offsets_limit"])
"""
@check_bert_tokenizer
@ -874,6 +878,7 @@ if platform.system().lower() != 'windows':
>>> replace_op = text.FilterWikipediaXML()
>>> text_file_dataset = text_file_dataset.map(operations=replace_op)
"""
def parse(self):
return cde.FilterWikipediaXMLOperation()

View File

@ -105,7 +105,7 @@ class Vocab:
@check_from_dataset
def from_dataset(cls, dataset, columns=None, freq_range=None, top_k=None, special_tokens=None, special_first=True):
"""
Build a vocab from a dataset.
Build a Vocab from a dataset.
This would collect all unique words in a dataset and return a vocab within
the frequency range specified by user in freq_range. User would be warned if no words fall into the frequency.
@ -130,7 +130,7 @@ class Vocab:
is specified and special_first is set to True, special_tokens will be prepended (default=True).
Returns:
Vocab, vocab built from the dataset.
Vocab, Vocab object built from the dataset.
Examples:
>>> dataset = ds.TextFileDataset("/path/to/sentence/piece/vocab/file", shuffle=False)
@ -139,6 +139,7 @@ class Vocab:
... special_first=True)
>>> dataset = dataset.map(operations=text.Lookup(vocab, "<unk>"), input_columns=["text"])
"""
vocab = Vocab()
vocab.c_vocab = dataset.build_vocab(columns, freq_range, top_k, special_tokens, special_first)
return vocab
@ -157,11 +158,12 @@ class Vocab:
is specified and special_first is set to True, special_tokens will be prepended (default=True).
Returns:
Vocab, vocab built from the `list`.
Vocab, Vocab object built from the list.
Examples:
>>> vocab = text.Vocab.from_list(["w1", "w2", "w3"], special_tokens=["<unk>"], special_first=True)
"""
if special_tokens is None:
special_tokens = []
vocab = Vocab()
@ -172,7 +174,7 @@ class Vocab:
@check_from_file
def from_file(cls, file_path, delimiter="", vocab_size=None, special_tokens=None, special_first=True):
"""
Build a vocab object from a list of word.
Build a vocab object from a file.
Args:
file_path (str): Path to the file which contains the vocab list.
@ -186,7 +188,7 @@ class Vocab:
special_tokens will be prepended (default=True).
Returns:
Vocab, vocab built from the file.
Vocab, Vocab object built from the file.
Examples:
>>> # Assume vocab file contains the following content:
@ -203,6 +205,7 @@ class Vocab:
>>> # Finally, there are 5 words in the vocab: "<pad>", "<unk>", "apple", "banana", "cat".
>>> vocabulary = vocab.vocab()
"""
if vocab_size is None:
vocab_size = -1
if special_tokens is None:
@ -222,11 +225,12 @@ class Vocab:
to start from 0 and be continuous. ValueError will be raised if id is negative.
Returns:
Vocab, vocab built from the `dict`.
Vocab, Vocab object built from the dict.
Examples:
>>> vocab = text.Vocab.from_dict({"home": 3, "behind": 2, "the": 4, "world": 5, "<unk>": 6})
"""
vocab = Vocab()
vocab.c_vocab = cde.Vocab.from_dict(word_dict)
return vocab
@ -280,7 +284,7 @@ class SentencePieceVocab(cde.SentencePieceVocab):
@check_from_file_sentencepiece
def from_file(cls, file_path, vocab_size, character_coverage, model_type, params):
"""
Build a SentencePiece object from a list of word.
Build a SentencePiece object from a file.
Args:
file_path(list): Path to the file which contains the SentencePiece list.
@ -315,6 +319,7 @@ class SentencePieceVocab(cde.SentencePieceVocab):
>>> vocab = text.SentencePieceVocab.from_file(["/path/to/sentence/piece/vocab/file"], 5000, 0.9995,
... SentencePieceModel.UNIGRAM, {})
"""
return super().from_file(file_path, vocab_size, character_coverage,
DE_C_INTER_SENTENCEPIECE_MODE[model_type], params)
@ -335,6 +340,7 @@ class SentencePieceVocab(cde.SentencePieceVocab):
... SentencePieceModel.UNIGRAM, {})
>>> text.SentencePieceVocab.save_model(vocab, "./", "m.model")
"""
super().save_model(vocab, path, filename)
@ -390,6 +396,7 @@ class JiebaMode(IntEnum):
- JiebaMode.MP: tokenize with MPSegment algorithm.
- JiebaMode.HMM: tokenize with Hidden Markov Model Segment algorithm.
"""
MIX = 0
MP = 1
HMM = 2
@ -408,6 +415,7 @@ class NormalizeForm(IntEnum):
- NormalizeForm.NFD: normalize with Normalization Form D.
- NormalizeForm.NFKD: normalize with Normalization Form KD.
"""
NONE = 0
NFC = 1
NFKC = 2
@ -429,6 +437,7 @@ class SentencePieceModel(IntEnum):
- SentencePieceModel.CHAR: refers to char based sentencePiece Model type.
- SentencePieceModel.WORD: refers to word based sentencePiece Model type.
"""
UNIGRAM = 0
BPE = 1
CHAR = 2
@ -452,19 +461,21 @@ class SPieceTokenizerOutType(IntEnum):
- SPieceTokenizerOutType.STRING: means output type of SentencePice Tokenizer is string.
- SPieceTokenizerOutType.INT: means output type of SentencePice Tokenizer is int.
"""
STRING = 0
INT = 1
class SPieceTokenizerLoadType(IntEnum):
"""
An enumeration for SPieceTokenizerLoadType.
An enumeration for loading type of SentencePieceTokenizer.
Possible enumeration values are: SPieceTokenizerLoadType.FILE, SPieceTokenizerLoadTypeMODEL.
Possible enumeration values are: SPieceTokenizerLoadType.FILE, SPieceTokenizerLoadType.MODEL.
- SPieceTokenizerLoadType.FILE: Load sentencepiece tokenizer from local sentencepiece vocab file.
- SPieceTokenizerLoadType.MODEL: Load sentencepiece tokenizer from sentencepiece vocab instance.
"""
FILE = 0
MODEL = 1

View File

@ -25,6 +25,11 @@ Common imported modules in corresponding API examples are as follows:
import mindspore.dataset.vision.py_transforms as py_vision
from mindspore.dataset.transforms import c_transforms
from mindspore.dataset.transforms import py_transforms
Descriptions of common data processing terms are as follows:
- TensorOperation, the base class of all data processing operations implemented in C++.
- PyTensorOperation, the base class of all data processing operations implemented in Python.
"""
from .. import vision
from . import c_transforms

View File

@ -273,7 +273,7 @@ class Mask(TensorOperation):
Relational.GT, Relational.LE, Relational.GE], take Relational.EQ as example, EQ refers to equal.
constant (Union[str, int, float, bool]): Constant to be compared to.
Constant will be cast to the type of the input tensor.
dtype (mindspore.dtype, optional): Type of the generated mask (Default mstype.bool\_).
dtype (mindspore.dtype, optional): Type of the generated mask. Default: mindspore.dtype.bool\_.
Raises:
TypeError: `operator` is not of type Relational.
@ -444,7 +444,7 @@ class Unique(TensorOperation):
Call batch op before calling this function.
Raises:
RuntimeError: If given tensor has two columns.
RuntimeError: If given Tensor has two columns.
Supported Platforms:
``CPU``
@ -466,7 +466,6 @@ class Unique(TensorOperation):
>>> # +---------+-----------------+---------+
>>> # | [0,1,2,3] | [0,1,2,1,2,3] | [1,2,2,1]
>>> # +---------+-----------------+---------+
"""
def parse(self):
@ -483,8 +482,8 @@ class Compose(TensorOperation):
Raises:
TypeError: If `transforms` is not of type list.
ValueError: If `transforms` is empty.
TypeError: If elements of `transforms` are neither Python callable objects nor have
type :class:`mindspore.dataset.transforms.c_transforms.TensorOperation` .
TypeError: If elements of `transforms` are neither Python callable objects nor data
processing operations in c_transforms.
Supported Platforms:
``CPU``
@ -519,8 +518,8 @@ class RandomApply(TensorOperation):
Raises:
TypeError: If `transforms` is not of type list.
ValueError: If `transforms` is empty.
TypeError: If elements of `transforms` are neither Python callable objects nor have
type :class:`mindspore.dataset.transforms.c_transforms.TensorOperation` .
TypeError: If elements of `transforms` are neither Python callable objects nor data
processing operations in c_transforms.
TypeError: If `prob` is not of type bool.
ValueError: If `prob` is not in range [0.0, 1.0].
@ -557,8 +556,8 @@ class RandomChoice(TensorOperation):
Raises:
TypeError: If `transforms` is not of type list.
ValueError: If `transforms` is empty.
TypeError: If elements of `transforms` are neither Python callable objects nor have
type :class:`mindspore.dataset.transforms.c_transforms.TensorOperation` .
TypeError: If elements of `transforms` are neither Python callable objects nor data
processing operations in c_transforms.
Supported Platforms:
``CPU``

View File

@ -258,8 +258,8 @@ class RandomApply(PyTensorOperation):
Raises:
TypeError: If `transforms` is not of type list.
ValueError: If `transforms` is empty.
TypeError: If elements of `transforms` are neither Python callable objects nor have
type :class:`mindspore.dataset.transforms.py_transforms.PyTensorOperation` .
TypeError: If elements of `transforms` are neither Python callable objects nor data
processing operations in py_transforms.
TypeError: If `prob` is not of type bool.
ValueError: If `prob` is not in range [0.0, 1.0].
@ -304,8 +304,8 @@ class RandomChoice(PyTensorOperation):
Raises:
TypeError: If `transforms` is not of type list.
TypeError: If elements of `transforms` are neither Python callable objects nor have
type :class:`mindspore.dataset.transforms.py_transforms.PyTensorOperation` .
TypeError: If elements of `transforms` are neither Python callable objects nor data
processing operations in py_transforms.
ValueError: If `transforms` is empty.
Supported Platforms:
@ -348,8 +348,8 @@ class RandomOrder(PyTensorOperation):
Raises:
TypeError: If `transforms` is not of type list.
TypeError: If elements of `transforms` are neither Python callable objects nor have
type :class:`mindspore.dataset.transforms.py_transforms.PyTensorOperation` .
TypeError: If elements of `transforms` are neither Python callable objects nor data
processing operations in py_transforms.
ValueError: If `transforms` is empty.
Supported Platforms:

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Validators for TensorOps.
"""Validators for data processing operations.
"""
from functools import wraps
import inspect

View File

@ -55,14 +55,14 @@ def imshow_det_bbox(image, bboxes, labels, segm=None, class_names=None, score_th
Raises:
ImportError: If opencv-python is not installed.
AssertionError: Input image is not in (H, W, C) or (C, H, W) format.
AssertionError: Input bboxes is not in (N, 4) or (N, 5) format.
AssertionError: Input labels is not in (N, 1) format.
AssertionError: Input segm is not in (M, H, W) format.
AssertionError: Input class_names is not a list, tuple or dict.
AssertionError: Input bbox_color is a not tuple, formatted (B, G, R).
AssertionError: Input text_color is a not tuple, formatted (B, G, R).
AssertionError: Input mask_color is a not tuple, formatted (B, G, R).
AssertionError: If `image` is not in (H, W, C) or (C, H, W) format.
AssertionError: If `bboxes` is not in (N, 4) or (N, 5) format.
AssertionError: If `labels` is not in (N, 1) format.
AssertionError: If `segm` is not in (M, H, W) format.
AssertionError: If `class_names` is not of type list, tuple or dict.
AssertionError: If `bbox_color` is not a tuple in format of (B, G, R).
AssertionError: If `text_color` is not a tuple in format of (B, G, R).
AssertionError: If `mask_color` is not a tuple in format of (B, G, R).
Examples:
>>> import numpy as np

View File

@ -24,6 +24,12 @@ Common imported modules in corresponding API examples are as follows:
import mindspore.dataset.vision.c_transforms as c_vision
import mindspore.dataset.vision.py_transforms as py_vision
from mindspore.dataset.transforms import c_transforms
Descriptions of common data processing terms are as follows:
- TensorOperation, the base class of all data processing operations implemented in C++.
- PyTensorOperation, the base class of all data processing operations implemented in Python.
- ImageTensorOperation, the base class of all image processing operations. It is a derived class of TensorOperation.
"""
from . import c_transforms
from . import py_transforms

View File

@ -282,16 +282,16 @@ class AutoContrast(ImageTensorOperation):
class BoundingBoxAugment(ImageTensorOperation):
"""
Apply a given image transform on a random selection of bounding box regions of a given image.
Apply a given image processing operation on a random selection of bounding box regions of a given image.
Args:
transform (TensorOperation): C++ transformation operator to be applied on random selection
transform (TensorOperation): C++ transformation operation to be applied on random selection
of bounding box regions of a given image.
ratio (float, optional): Ratio of bounding boxes to apply augmentation on.
Range: [0, 1] (default=0.3).
Raises:
TypeError: If `transform` is not of type :class:`mindspore.dataset.vision.c_transforms.ImageTensorOperation`.
TypeError: If `transform` is an image processing operation in :class:`mindspore.dataset.vision.c_transforms`.
TypeError: If `ratio` is not of type float.
ValueError: If `ratio` is not in range [0, 1].
RuntimeError: If given bounding box is invalid.
@ -1661,7 +1661,7 @@ class RandomResizedCrop(ImageTensorOperation):
TypeError: If `size` is not of type integer or sequence of integer.
TypeError: If `scale` is not of type tuple.
TypeError: If `ratio` is not of type tuple.
TypeError: If `interpolation` is not of type Inter.
TypeError: If `interpolation` is not of type :class:`mindspore.dataset.vision.Inter`.
TypeError: If `max_attempts` is not of type integer.
ValueError: If `size` is not positive.
ValueError: If `scale` is negative.
@ -1925,13 +1925,14 @@ class RandomSelectSubpolicy(ImageTensorOperation):
Choose a random sub-policy from a policy list to be applied on the input image.
Args:
policy (list(list(tuple(TensorOp, prob (float))))): List of sub-policies to choose from.
A sub-policy is a list of tuples (op, prob), where op is a TensorOp operation and prob is the probability
that this op will be applied, and the prob values must be in range [0, 1]. Once a sub-policy is selected,
each op within the sub-policy with be applied in sequence according to its probability.
policy (list[list[tuple[TensorOperation, float]]]): List of sub-policies to choose from.
A sub-policy is a list of tuple[operation, prob], where operation is a data processing operation and prob
is the probability that this operation will be applied, and the prob values must be in range [0, 1].
Once a sub-policy is selected, each operation within the sub-policy with be applied in sequence according
to its probability.
Raises:
TypeError: If `policy` contains invalid TensorOp.
TypeError: If `policy` contains invalid data processing operations.
Supported Platforms:
``CPU``
@ -2007,8 +2008,8 @@ class RandomSolarize(ImageTensorOperation):
If min=max, then invert all pixel values above min(max).
Raises:
TypeError : If `threshold` is not a tuple.
ValueError: If `threshold` is not in range [0, 255].
TypeError : If `threshold` is not of type tuple.
ValueError: If `threshold` is not in range of [0, 255].
Supported Platforms:
``CPU``
@ -2251,9 +2252,7 @@ class Rotate(ImageTensorOperation):
It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC].
- Inter.BILINEAR, means resample method is bilinear interpolation.
- Inter.NEAREST, means resample method is nearest-neighbor interpolation.
- Inter.BICUBIC, means resample method is bicubic interpolation.
expand (bool, optional): Optional expansion flag (default=False). If set to True, expand the output
@ -2270,7 +2269,7 @@ class Rotate(ImageTensorOperation):
Raises:
TypeError: If `degrees` is not of type integer, float or sequence.
TypeError: If `resample` is not of type Inter.
TypeError: If `expand` is not of type boolean.
TypeError: If `expand` is not of type bool.
TypeError: If `center` is not of type tuple.
TypeError: If `fill_value` is not of type integer or tuple of integer.
ValueError: If `fill_value` is not in range [0, 255].

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Validators for TensorOps.
"""Validators for image processing operations.
"""
import numbers
from functools import wraps

View File

@ -75,7 +75,7 @@ class FileReader:
Yield a batch of data according to columns at a time.
Yields:
Dict: a batch whose keys are the same as columns.
dict, a batch whose keys are the same as columns.
Raises:
MRMUnsupportedSchemaError: If schema is invalid.

View File

@ -44,7 +44,7 @@ class FileWriter:
file_name (str): File name of MindRecord file.
shard_num (int, optional): The Number of MindRecord files. Default: 1.
It should be between [1, 1000].
overwrite (bool, optional): Overwrite MindRecord files if true. Default: False.
overwrite (bool, optional): Whether to overwrite if the file already exists. Default: False.
Raises:
ParamValueError: If `file_name` or `shard_num` or `overwrite` is invalid.

View File

@ -37,12 +37,12 @@ class ImageNetToMR:
Args:
map_file (str): the map file that indicates label. The map file content should be like this:
.. code-block::
.. code-block::
n02119789 0
n02100735 1
n02110185 2
n02096294 3
n02119789 0
n02100735 1
n02110185 2
n02096294 3
image_dir (str): image directory contains n02119789, n02100735, n02110185 and n02096294 directory.
destination (str): the MindRecord file path to transform into.