add vision api

This commit is contained in:
liu-yongqi-63 2022-02-15 15:42:31 +08:00
parent b31c800d23
commit f3219b4cf7
33 changed files with 688 additions and 23 deletions

View File

@ -0,0 +1,15 @@
mindspore.dataset.vision.Border
===============================
.. py:class:: mindspore.dataset.vision.Border()
边界填充方式枚举类。
可选枚举值为Border.CONSTANT、Border.EDGE、Border.REFLECT、Border.SYMMETRIC。
- **Border.CONSTANT** - 使用常量值进行填充。
- **Border.EDGE** - 使用各边的边界像素值进行填充。
- **Border.REFLECT** - 以各边的边界为轴进行镜像填充,忽略边界像素值。
- **Border.SYMMETRIC** - 以各边的边界为轴进行对称填充,包括边界像素值。
.. note:: 该类派生自 :class:`str` 以支持 JSON 可序列化。

View File

@ -0,0 +1,11 @@
mindspore.dataset.vision.ImageBatchFormat
=========================================
.. py:class:: mindspore.dataset.vision.ImageBatchFormat()
图像批处理输出格式枚举类。
可选枚举值为ImageBatchFormat.NHWC、ImageBatchFormat.NCHW。
- **ImageBatchFormat.NHWC** - 按批次N、高度H、宽度W、通道C的顺序存储数据。
- **ImageBatchFormat.NCHW** - 按批次N、通道C、高度H、宽度W的顺序存储数据。

View File

@ -0,0 +1,17 @@
mindspore.dataset.vision.Inter
==============================
.. py:class:: mindspore.dataset.vision.Inter()
图像插值方式枚举类。
可选枚举值为Inter.NEAREST、Inter.ANTIALIAS、Inter.LINEAR、Inter.BILINEAR、Inter.CUBIC、Inter.BICUBIC、Inter.AREA、Inter.PILCUBIC。
- **Inter.Nest** - 最近邻插值。
- **Inter.ANTIALIAS** - 抗锯齿插值。
- **Inter.LINEAR** - 线性插值实现同Inter.BILINEAR。
- **Inter.BILINEAR** - 是双线性插值。
- **Inter.CUBIC** - 三次插值实现同Inter.BICUBIC。
- **Inter.BICUBIC** - 双三次插值。
- **Inter.AREA** - 像素区域插值。
- **Inter.PILCUBIC** - Pillow库中实现的双三次插值输入需为3通道格式。

View File

@ -0,0 +1,11 @@
mindspore.dataset.vision.SliceMode
==================================
.. py:class:: mindspore.dataset.vision.SliceMode()
Tensor切片方式枚举类。
可选枚举值为SliceMode.PAD、SliceMode.DROP。
- **SliceMode.PAD** - 当Tensor无法进行整数切分时对剩余部分进行填充。
- **SliceMode.DROP** - 当Tensor无法进行整数切分时对剩余部分进行丢弃。

View File

@ -0,0 +1,19 @@
mindspore.dataset.vision.c_transforms.AutoContrast
==================================================
.. py:class:: mindspore.dataset.vision.c_transforms.AutoContrast(cutoff=0.0, ignore=None)
在输入图像上应用自动对比度。首先计算图像的直方图将直方图中最亮像素的值映射为255将直方图中最暗像素的值映射为0。
**参数:**
- **cutoff** (float, 可选) - 输入图像直方图中最亮和最暗像素的百分比。该值必须在 [0.0, 50.0) 范围内, 默认值0.0。
- **ignore** (Union[int, sequence], 可选) - 要忽略的背景像素值,忽略值必须在 [0, 255] 范围内, 默认值None。
**异常:**
- **TypeError** - 如果 `cutoff` 不是float类型。
- **TypeError** - 如果 `ignore` 不是int或sequence类型。
- **ValueError** - 如果 `cutoff` 不在[0, 50.0) 范围内。
- **ValueError** - 如果 `ignore` 不在[0, 255] 范围内。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,18 @@
mindspore.dataset.vision.c_transforms.BoundingBoxAugment
========================================================
.. py:class:: mindspore.dataset.vision.c_transforms.BoundingBoxAugment(transform, ratio=0.3)
对图像的标注边界框(bounding box)区域随机应用给定的图像变换处理。
**参数:**
- **transform** (TensorOperation) - 要应用的图像变换处理。
- **ratio** (float, 可选) - 应用图像变换处理的概率。范围:[0, 1], 默认值0.3。
**异常:**
- **TypeError** - 如果 `transform` 不是 :class:`mindspore.dataset.vision.c_transforms.ImageTensorOperation` 的类型。
- **TypeError** - 如果 `ratio` 不是float类型。
- **ValueError** - 如果 `ratio` 不在 [0, 1] 范围内。
- **RuntimeError** - 如果给定的边界框无效。

View File

@ -0,0 +1,19 @@
mindspore.dataset.vision.c_transforms.CenterCrop
================================================
.. py:class:: mindspore.dataset.vision.c_transforms.CenterCrop(size)
对输入图像应用中心区域裁剪。如果输入图像尺寸小于输出尺寸则在裁剪前对输入图像边界填充0像素。
**参数:**
- **size** (Union[int, sequence]) - 裁剪区域大小。
如果 size 是整数,则返回大小为 (size, size) 的正方形裁剪。
如果 size 是一个长度为 2 的序列,它应该是 (高度, 宽度)。
大小值必须大于 0。
**异常:**
- **TypeError** - 如果 `size` 不是int或sequence类型。
- **ValueError** - 如果 `size` 小于或等于 0。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,36 @@
mindspore.dataset.vision.c_transforms.ConvertColor
==================================================
.. py:class:: mindspore.dataset.vision.c_transforms.ConvertColor(convert_mode)
更改图像的色彩空间。
**参数:**
- **convert_mode** (ConvertMode) - 图像色彩空间转换的模式。
- **ConvertMode.COLOR_BGR2BGRA**: 将 BGR 图像转换为 BGRA 图像。
- **ConvertMode.COLOR_RGB2RGBA**:将 RGB 图像转换为 RGBA 图像。
- **ConvertMode.COLOR_BGRA2BGR**: 将 BGRA 图像转换为 BGR 图像。
- **ConvertMode.COLOR_RGBA2RGB**: 将 RGBA 图像转换为 RGB 图像。
- **ConvertMode.COLOR_BGR2RGBA**: 将 BGR 图像转换为 RGBA 图像。
- **ConvertMode.COLOR_RGB2BGRA**: 将 RGB 图像转换为 BGRA 图像。
- **ConvertMode.COLOR_RGBA2BGR**: 将 RGBA 图像转换为 BGR 图像。
- **ConvertMode.COLOR_BGRA2RGB**: 将 BGRA 图像转换为 RGB 图像。
- **ConvertMode.COLOR_BGR2RGB**: 将 BGR 图像转换为 RGB 图像。
- **ConvertMode.COLOR_RGB2BGR**: 将 RGB 图像转换为 BGR 图像。
- **ConvertMode.COLOR_BGRA2RGBA**: 将 BGRA 图像转换为 RGBA 图像。
- **ConvertMode.COLOR_RGBA2BGRA**: 将 RGBA 图像转换为 BGRA 图像。
- **ConvertMode.COLOR_BGR2GRAY**: 将 BGR 图像转换为 GRAY 图像。
- **ConvertMode.COLOR_RGB2GRAY**: 将 RGB 图像转换为 GRAY 图像。
- **ConvertMode.COLOR_GRAY2BGR**: 将 GRAY 图像转换为 BGR 图像。
- **ConvertMode.COLOR_GRAY2RGB**: 将 GRAY 图像转换为 RGB 图像。
- **ConvertMode.COLOR_GRAY2BGRA**: 将 GRAY 图像转换为 BGRA 图像。
- **ConvertMode.COLOR_GRAY2RGBA**: 将 GRAY 图像转换为 RGBA 图像。
- **ConvertMode.COLOR_BGRA2GRAY**: 将 BGRA 图像转换为 GRAY 图像。
- **ConvertMode.COLOR_RGBA2GRAY**: 将 RGBA 图像转换为 GRAY 图像。
**异常:**
- **TypeError** - 如果 `convert_mode` 不是类 :class:`mindspore.dataset.vision.ConvertMode` 的类型。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,22 @@
mindspore.dataset.vision.c_transforms.Crop
==========================================
.. py:class:: mindspore.dataset.vision.c_transforms.Crop(coordinates, size)
在输入图像上裁剪出指定区域。
**参数:**
- **coordinates** (sequence) - 裁剪区域的起始左上角坐标。 必须是两个值的序列,形式为(上,左)。
- **size** (Union[int, sequence]) - 裁剪区域的大小。
如果 size 是整数,则返回大小为 (size, size) 的正方形裁剪。
如果 size 是一个长度为 2 的序列,它代表 (高度, 宽度)。
大小值必须大于 0。
**异常:**
- **TypeError** - 如果 `coordinates` 不是sequence类型。
- **TypeError** - 如果 `size` 不是int或sequence类型。
- **ValueError** - 如果 `coordinates` 小于 0。
- **ValueError** - 如果 `size` 小于或等于 0。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,22 @@
mindspore.dataset.vision.c_transforms.CutMixBatch
=================================================
.. py:class:: mindspore.dataset.vision.c_transforms.CutMixBatch(image_batch_format, alpha=1.0, prob=1.0)
对输入批次的图像和标签应用剪切混合转换。
请注意,在调用此操作符之前,您需要将标签制作为 one-hot 格式并进行批处理。
**参数:**
- **image_batch_format** (ImageBatchFormat) - 图像批处理输出格式。可以是 [ImageBatchFormat.NHWC、ImageBatchFormat.NCHW] 中的任何一个。
- **alpha** (float, 可选) - β分布的超参数,必须大于 0, 默认值1.0。
- **prob** (float, 可选) - 对每个图像应用CutMix处理的概率范围[0, 1], 默认值1.0。
**异常:**
- **TypeError** - 如果 `image_batch_format` 不是 :class:`mindspore.dataset.vision.ImageBatchFormat` 的类型。
- **TypeError** - 如果 `alpha` 不是float类型。
- **TypeError** - 如果 `prob` 不是 float 类型。
- **ValueError** - 如果 `alpha` 小于或等于 0。
- **ValueError** - 如果 `prob` 不在 [0, 1] 范围内。
- **RuntimeError** - 如果输入图像的shape不是 <H, W, C>。

View File

@ -0,0 +1,19 @@
mindspore.dataset.vision.c_transforms.CutOut
============================================
.. py:class:: mindspore.dataset.vision.c_transforms.CutOut(length, num_patches=1)
从输入图像数组中随机裁剪出给定数量的正方形区域。
**参数:**
- **length** (int) - 每个正方形区域的边长,必须大于 0。
- **num_patches** (int, 可选) - 要从图像中切出的正方形区域数必须大于0, 默认值1。
**异常:**
- **TypeError** - 如果 `length` 不是int类型。
- **TypeError** - 如果 `num_patches` 不是int类型。
- **ValueError** - 如果 `length` 小于或等于 0。
- **ValueError** - 如果 `num_patches` 小于或等于 0。
- **RuntimeError** - 如果输入图像的shape不是 <H, W, C>。

View File

@ -0,0 +1,16 @@
mindspore.dataset.vision.c_transforms.Decode
============================================
.. py:class:: mindspore.dataset.vision.c_transforms.Decode(rgb=True)
以 RGB 模式(默认)或 BGR 模式(选项已弃用)解码输入图像。
**参数:**
- **rgb** (bool可选) - 解码输入图像的模式, 默认值True。
如果 True 表示解码图像的格式为 RGB否则为 BGR选项已弃用
**异常:**
- **RuntimeError** - 如果 `rgb` 为 False因为此选项已弃用。
- **RuntimeError** - 如果输入图像的shape不是一维序列。

View File

@ -0,0 +1,10 @@
mindspore.dataset.vision.c_transforms.Equalize
==============================================
.. py:class:: mindspore.dataset.vision.c_transforms.Equalize()
对输入图像应用直方图均衡。
**异常:**
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,24 @@
mindspore.dataset.vision.c_transforms.GaussianBlur
==================================================
.. py:class:: mindspore.dataset.vision.c_transforms.GaussianBlur(kernel_size, sigma=None)
使用指定的高斯核对输入图像进行模糊处理。
**参数:**
- **kernel_size** (Union[int, sequence]) - 要使用的高斯核的大小。该值必须是正数和奇数。
如果只提供一个整数,内核大小将为 (size, size)。
如果提供了整数序列,则它必须是表示(宽度、高度)的 2 个值的序列。
- **sigma** (Union[float, sequence], 可选) - 要使用的高斯核的标准差, 默认值None。该值必须是正数。
如果仅提供浮点数,则 sigma 将为 (sigma, sigma)。
如果提供了一系列浮点数,则它必须是代表宽度和高度的 sigma 的 2 个值的序列。
如果为Nonesigma采用的值为 ((kernel_size - 1) * 0.5 - 1) * 0.3 + 0.8。
**异常:**
- **TypeError** - 如果 `kernel_size` 不是int或sequence类型或元素不为int类型。
- **TypeError** - 如果 `sigma` 不是float类型或sequence类型或元素不为float类型。
- **ValueError** - 如果 `kernel_size` 不是正数和奇数。
- **ValueError** - 如果 `sigma` 不是正数。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,10 @@
mindspore.dataset.vision.c_transforms.HWC2CHW
=============================================
.. py:class:: mindspore.dataset.vision.c_transforms.HWC2CHW()
将输入图像从形状 (H, W, C) 转置为形状 (C, H, W)。 输入图像应为 3 通道图像。
**异常:**
- **RuntimeError** - 如果输入图像的shape不是 <H, W, C>。

View File

@ -0,0 +1,10 @@
mindspore.dataset.vision.c_transforms.HorizontalFlip
====================================================
.. py:class:: mindspore.dataset.vision.c_transforms.HorizontalFlip()
水平翻转输入图像。
**异常:**
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,10 @@
mindspore.dataset.vision.c_transforms.Invert
============================================
.. py:class:: mindspore.dataset.vision.c_transforms.Invert()
在 RGB 模式下对输入图像应用像素反转, 计算方式为255 - pixel
**异常:**
- **RuntimeError** - 如果输入图像的shape不是 <H, W, C>。

View File

@ -0,0 +1,20 @@
mindspore.dataset.vision.c_transforms.MixUpBatch
================================================
.. py:class:: mindspore.dataset.vision.c_transforms.MixUpBatch(alpha=1.0)
对输入批次的图像和标签应用混合转换。从批处理中随机抽取两个图像,其中一个图像乘以随机权重 (lambda),另一个图像乘以 (1 - lambda), 并相加。该处理将会同时应用于label。
上述的 lambda 是根据指定的参数 `alpha` 生成的。 计算方式为在 [alpha, 1] 范围内随机生成两个系数 x1x2 ,然后 lambda = (x1 / (x1 + x2))。
请注意在调用此处理之前您需要将label制作成 one-hot 格式并进行batch操作。
**参数:**
- **alpha** (float, 可选) - β分布的超参数该值必须为正默认值1.0。
**异常:**
- **TypeError** - 如果 `alpha` 不是float类型。
- **ValueError** - 如果 `alpha` 不是正数。
- **RuntimeError** - 如果输入图像的shape不是 <N, H, W, C> 或 <N, C, H, W>。

View File

@ -0,0 +1,20 @@
mindspore.dataset.vision.c_transforms.Normalize
===============================================
.. py:class:: mindspore.dataset.vision.c_transforms.Normalize(mean, std)
根据均值和标准差对输入图像进行归一化。
此处理将使用以下公式对输入图像进行归一化output[channel] = (input[channel] - mean[channel]) / std[channel],其中 channel 代表通道索引channel >= 1。
**参数:**
- **mean** (sequence) - 图像每个通道的均值组成的列表或元组。 平均值必须在 [0.0, 255.0] 范围内。
- **std** (sequence) - 图像每个通道的标准差组成的列表或元组。 标准偏差值必须在 (0.0, 255.0] 范围内。
**异常:**
- **TypeError** - 如果 `mean` 不是sequence类型。
- **TypeError** - 如果 `std` 不是sequence类型。
- **ValueError** - 如果 `mean` 不在 [0.0, 255.0] 范围内。
- **ValueError** - 如果 `mean` 不在范围内 (0.0, 255.0]。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,21 @@
mindspore.dataset.vision.c_transforms.NormalizePad
==================================================
.. py:class:: mindspore.dataset.vision.c_transforms.NormalizePad(mean, std, dtype="float32")
根据均值和标准差对输入图像进行归一化,然后用零值填充一个额外的通道。
**参数:**
- **mean** (sequence) - 图像每个通道的均值组成的列表或元组。 平均值必须在 (0.0, 255.0] 范围内。
- **std** (sequence) - 图像每个通道的标准差组成的列表或元组。 标准偏差值必须在 (0.0, 255.0] 范围内。
- **dtype** (str, 可选) - 设置归一化图像的输出数据类型, 默认值:"float32"。
**异常:**
- **TypeError** - 如果 `mean` 不是sequence类型。
- **TypeError** - 如果 `std` 不是sequence类型。
- **TypeError** - 如果 `dtype` 不是str类型。
- **ValueError** - 如果 `mean` 不在 [0.0, 255.0] 范围内。
- **ValueError** - 如果 `mean` 不在范围内 (0.0, 255.0]。
- **RuntimeError** - 如果输入图像的shape不是 <H, W, C>。

View File

@ -0,0 +1,33 @@
mindspore.dataset.vision.c_transforms.Pad
=========================================
.. py:class:: mindspore.dataset.vision.c_transforms.Pad(padding, fill_value=0, padding_mode=Border.CONSTANT)
根据填充参数填充图像。
**参数:**
- **padding** (Union[int, sequence]) - 填充图像的像素数。
如果 `padding` 是一个整数,代表为图像的所有方向填充该值大小的像素。
如果 `padding` 是一个包含2个值的元组或列表第一个值会用于填充图像的左侧和上侧第二个值会用于填充图像的右侧和下侧。
如果 `padding` 是一个包含4个值的元组或列表则分别填充图像的左侧、上侧、右侧和下侧。
填充值必须为非负值。
- **fill_value** (Union[int, tuple], 可选) - 填充的像素值,仅在 `padding_mode` 取值为Border.CONSTANT时有效。
如果是3元组则分别用于填充R、G、B通道。
如果是整数,则用于所有 RGB 通道。
`fill_value` 值必须在 [0, 255] 范围内, 默认值0。
- **padding_mode** (Border, 可选) - 边界填充方式, 默认值Border.CONSTANT。可以是 [Border.CONSTANT、Border.EDGE、Border.REFLECT、Border.SYMMETRIC] 中的任何一个。
- **Border.CONSTANT** - 使用常量值进行填充。
- **Border.EDGE** - 使用各边的边界像素值进行填充。
- **Border.REFLECT** - 以各边的边界为轴进行镜像填充,忽略边界像素值。
- **Border.SYMMETRIC** - 以各边的边界为轴进行对称填充,包括边界像素值。
**异常:**
- **TypeError** - 如果 `padding` 不是int或sequence类型或元素不为int类型。
- **TypeError** - 如果 `fill_value` 不是int或tuple类型或元素不为int类型。
- **TypeError** - 如果 `padding_mode` 不是 :class:`mindspore.dataset.vision.Border` 的类型。
- **ValueError** - 如果 `padding` 为负数。
- **ValueError** - 如果 `fill_value` 不在 [0, 255] 范围内。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,44 @@
mindspore.dataset.vision.c_transforms.RandomAffine
==================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomAffine(degrees, translate=None, scale=None, shear=None, resample=Inter.NEAREST, fill_value=0)
对输入图像应用随机仿射变换。
**参数:**
- **degrees** (Union[int, float, sequence]) - 旋转度数的范围。
如果 `degrees` 是一个数字,它代表旋转范围是(-degreesdegrees
如果 `degrees` 是一个序列,它代表旋转是 (min, max)。
- **translate** (sequence, 可选) - 一个序列(tx_min, tx_max, ty_min, ty_max)用于表示水平tx方向和垂直ty方向的最小/最大平移范围,取值范围 [-1.0, 1.0], 默认值None。
水平和垂直偏移分别从以下范围中随机选择:(tx_min*width, tx_max*width) 和 (ty_min*height, ty_max*height)。
如果 `translate` 是一个包含2个值的元组或列表则 (translate[0], translate[1]) 表示水平X方向的随机平移范围。
如果 `translate` 是一个包含4个值的元组或列表则 (translate[0], translate[1]) 表示水平X方向的随机平移范围, (translate[2], translate[3]) 表示垂直Y方向的随机平移范围。
如果为空,则不对图像进行任何平移。
- **scale** (sequence, 可选) - 图像的比例因子的随机范围,必须为非负数, 默认值None使用原始比例。
- **shear** (Union[int, float, sequence], 可选) - 图像的剪切因子的随机范围,必须为正数, 默认值None。
如果是数字,则应用在 (-shear, +shear) 范围内平行于 X 轴的剪切。
如果 `shear` 是一个包含2个值的元组或列表则在 (shear[0],shear[1]) 范围内进行水平X方向的剪切变换。
如果 `shear` 是一个包含4个值的元组或列表则在 (shear[0],shear[1]) 范围内进行水平X方向的剪切变换, 并在(shear[2], shear[3]) 范围内进行垂直Y方向的剪切变换。
如果为空,则不应用任何剪切。
- **resample** (Inter, 可选) - 图像插值方式, 默认值Inter.NEAREST。它可以是 [Inter.BILINEAR、Inter.NEAREST、Inter.BICUBIC] 中的任何一个。
- **Inter.BILINEAR**: 双线性插值。
- **Inter.NEAREST**: 最近邻插值。
- **Inter.BICUBIC**: 双三次插值。
- **fill_value** (Union[int, tuple], 可选) - 用于填充输出图像中变换之外的区域。元组中必须有三个值,取值范围是[0, 255], 默认值0。
**异常:**
- **TypeError** - 如果 `degrees` 不是int、float或sequence类型。
- **TypeError** - 如果 `translate` 不是sequence类型。
- **TypeError** - 如果 `scale` 不是sequence类型。
- **TypeError** - 如果 `shear` 不是int、float或sequence类型。
- **TypeError** - 如果 `resample` 不是 :class:`mindspore.dataset.vision.Inter` 的类型。
- **TypeError** - 如果 `fill_value` 不是int或tuple类型或元素不为int类型。
- **ValueError** - 如果 `degrees` 为负数。
- **ValueError** - 如果 `translate` 不在范围 [-1.0, 1.0] 内。
- **ValueError** - 如果 `scale` 为负数。
- **ValueError** - 如果 `shear` 不是正数。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,17 @@
mindspore.dataset.vision.c_transforms.RandomColor
=================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomColor(degrees=(0.1, 1.9))
随机调整输入图像的颜色。此操作仅适用于 3 通道彩色图像。
**参数:**
- **degrees** (sequence, 可选) - 随机颜色调整度数的范围,必须为非负数。 它应该是min, max格式。
如果min=max则代表颜色变化步长固定, 默认值0.11.9)。
**异常:**
- **TypeError** - 如果 `degrees` 不是sequence类型或元素不为float类型。
- **ValueError** - 如果 `degrees` 为负数。
- **RuntimeError** - 如果输入图像的shape不是 <H, W, C>。

View File

@ -0,0 +1,33 @@
mindspore.dataset.vision.c_transforms.RandomColorAdjust
=======================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomColorAdjust(brightness=(1, 1), contrast=(1, 1), saturation=(1, 1), hue=(0, 0))
随机调整输入图像的亮度、对比度、饱和度和色调。
**参数:**
- **brightness** (Union[float, list, tuple], 可选) - 亮度调整因子, 默认值:(1, 1)。不能为负。
如果是浮点数,则从 [max(0, 1-brightness), 1+brightness] 范围内统一选择因子。
如果它是一个序列,则代表是范围 [min, max], 从此范围中选择调整因子。
- **contrast** (Union[float, list, tuple], 可选) - 对比度调整因子, 默认值:(1, 1)。不能为负。
如果是浮点数,则从 [max(0, 1-contrast), 1+contrast] 范围内统一选择因子。
如果它是一个序列,则代表是范围 [min, max], 从此范围中选择调整因子。
- **saturation** (Union[float, list, tuple], 可选) - 饱和度调整因子, 默认值:(1, 1)。不能为负。
如果是浮点数,则从 [max(0, 1-saturation), 1+saturation] 范围内统一选择因子。
如果它是一个序列,则代表是范围 [min, max], 从此范围中选择调整因子。
- **hue** (Union[float, list, tuple], 可选) - 色调调整因子, 默认值:(0, 0)。
如果是浮点数,则代表是范围 [-hue, hue], 从此范围中选择调整因子。注意取值应为 0 <= `hue` <= 0.5。
如果它是一个序列,则代表是范围 [min, max], 从此范围中选择调整因子。注意取值范围是 -0.5 <= min <= max <= 0.5。
**异常:**
- **TypeError** - 如果 `brightness` 不是float或sequence类型或元素不为float类型。
- **TypeError** - 如果 `contrast` 不是float或sequence类型或元素不为float类型。
- **TypeError** - 如果 `saturation` 不是float或sequence类型或元素不为float类型。
- **TypeError** - 如果 `hue` 不是float或sequence类型或元素不为float类型。
- **ValueError** - 如果 `brightness` 为负数。
- **ValueError** - 如果 `contrast` 为负数。
- **ValueError** - 如果 `saturation` 为负数。
- **ValueError** - 如果 `hue` 不在 [-0.5, 0.5] 范围内。
- **RuntimeError** - 如果输入图像的shape不是 <H, W, C>。

View File

@ -0,0 +1,42 @@
mindspore.dataset.vision.c_transforms.RandomCrop
================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomCrop(size, padding=None, pad_if_needed=False, fill_value=0, padding_mode=Border.CONSTANT)
对输入图像进行随机区域的裁剪。如果输入图像尺寸小于输出尺寸,输入图像将在裁剪前被填充。
.. note:: 如果在多个数据列上应用此处理则需要确保每个数据列的图像shape相同。
**参数:**
- **size** (Union[int, sequence]) - 裁剪图像的输出大小。大小值必须为正。
如果 size 是整数,则返回大小为 (size, size) 的正方形裁剪。
如果 size 是一个长度为 2 的序列,它应该是 (高度, 宽度)。
- **padding** (Union[int, sequence], 可选) - 填充图像的像素数。填充值必须为非负值, 默认值None。
如果 `padding` 不为 None则首先使用 `padding` 填充图像。
如果 `padding` 是一个整数,代表为图像的所有方向填充该值大小的像素。
如果 `padding` 是一个包含2个值的元组或列表第一个值会用于填充图像的左侧和上侧第二个值会用于填充图像的右侧和下侧。
如果 `padding` 是一个包含4个值的元组或列表则分别填充图像的左侧、上侧、右侧和下侧。
- **pad_if_needed** (bool, 可选) - 如果输入图像高度或者宽度小于 `size` 指定的输出图像大小是否进行填充。默认值False不填充。
- **fill_value** (Union[int, tuple], 可选) - 边框的像素强度仅对padding_mode Border.CONSTANT有效。
如果是3元组则分别用于填充R、G、B通道。
如果是整数则用于所有RGB通道。
fill_value 值必须在 [0, 255] 范围内, 默认值0。
- **padding_mode** (Border, 可选) - 边界填充方式, 默认值Border.CONSTANT。它可以是 [Border.CONSTANT、Border.EDGE、Border.REFLECT、Border.SYMMETRIC] 中的任何一个。
- **Border.CONSTANT** - 使用常量值进行填充。
- **Border.EDGE** - 使用各边的边界像素值进行填充。
- **Border.REFLECT** - 以各边的边界为轴进行镜像填充,忽略边界像素值。
- **Border.SYMMETRIC** - 以各边的边界为轴进行对称填充,包括边界像素值。
**异常:**
- **TypeError** - 如果 `size` 不是int或sequence类型或元素不为int类型。
- **TypeError** - 如果 `padding` 不是int或sequence类型或元素不为int类型。
- **TypeError** - 如果 `pad_if_needed` 不是bool类型。
- **TypeError** - 如果 `fill_value` 不是int或sequence类型或元素不为int类型。
- **TypeError** - 如果 `padding_mode` 不是 :class:`mindspore.dataset.vision.Border` 的类型。
- **ValueError** - 如果 `size` 不是正数。
- **ValueError** - 如果 `padding` 为负数。
- **ValueError** - 如果 `fill_value` 不在 [0, 255] 范围内。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,37 @@
mindspore.dataset.vision.c_transforms.RandomCropDecodeResize
============================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomCropDecodeResize(size, scale=(0.08, 1.0), ratio=(3. / 4., 4. / 3.), interpolation=Inter.BILINEAR, max_attempts=10)
"裁剪"、"解码"和"调整大小"的组合处理。该算子将在随机位置裁剪输入图像,以 RGB 模式对裁剪后的图像进行解码,并调整解码图像的大小。针对 JPEG 图像进行了优化, 可以获得更好的性能。
**参数:**
- **size** (Union[int, sequence]) - 调整后图像的输出大小。大小值必须为正。
如果 size 是整数,则返回大小为 (size, size) 的正方形裁剪。
如果 size 是一个长度为 2 的序列,它应该是 (高度, 宽度)。
- **scale** (list, tuple, 可选) - 要裁剪的原始大小的各个大小的范围[min, max),必须为非负数, 默认值0.08, 1.0)。
- **ratio** (list, tuple, 可选) - 宽高比的范围 [min, max) 裁剪,必须为非负数, 默认值:(3. / 4., 4. / 3.)。
- **interpolation** (Inter, 可选) - resize算子的图像插值模式, 默认值Inter.BILINEAR。它可以是 [Inter.BILINEAR、Inter.NEAREST、Inter.BICUBIC、Inter.AREA、Inter.PILCUBIC] 中的任何一个。
- **Inter.BILINEAR**: 双线性插值。
- **Inter.NEAREST**: 最近邻插值。
- **Inter.BICUBIC**: 双三次插值。
- **Inter.AREA**: 像素区域插值。
- **Inter.PILCUBIC**: Pillow库中实现的双三次插值输入需为3通道格式。
- **max_attempts** (int, 可选) - 提出有效crop_area 的最大尝试次数, 默认值10。
如果超过,则回退到使用 center_crop 代替。 max_attempts 值必须为正数。
**异常:**
- **TypeError** - 如果 `size` 不是int或sequence类型或元素不为int类型。
- **TypeError** - 如果 `scale` 不是tuple类型。
- **TypeError** - 如果 `ratio` 不是tuple类型。
- **TypeError** - 如果 `interpolation` 不是 :class:`mindspore.dataset.vision.Inter` 的类型。
- **TypeError** - 如果 `max_attempts` 不是int类型。
- **ValueError** - 如果 `size` 不是正数。
- **ValueError** - 如果 `scale` 为负数。
- **ValueError** - 如果 `ratio` 为负数。
- **ValueError** - 如果 `max_attempts` 不是正数。
- **RuntimeError** - 如果输入图像的shape不是一维序列。

View File

@ -0,0 +1,40 @@
mindspore.dataset.vision.c_transforms.RandomCropWithBBox
========================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomCropWithBBox(size, padding=None, pad_if_needed=False, fill_value=0, padding_mode=Border.CONSTANT)
对输入图像进行随机位置裁剪并相应地调整边界框。
**参数:**
- **size** (Union[int, sequence]) - 裁剪图像的输出大小。大小值必须为正。
如果 size 是整数,则返回大小为 (size, size) 的正方形裁剪。
如果 size 是一个长度为 2 的序列,它应该是 (高度, 宽度)。
- **padding** (Union[int, sequence], 可选) - 填充图像的像素数。填充值必须非负值, 默认值None。
如果 `padding` 不为 None则首先使用 `padding` 填充图像。
如果 `padding` 是一个整数,代表为图像的所有方向填充该值大小的像素。
如果 `padding` 是一个包含2个值的元组或列表第一个值会用于填充图像的左侧和上侧第二个值会用于填充图像的右侧和下侧。
如果 `padding` 是一个包含4个值的元组或列表则分别填充图像的左侧、上侧、右侧和下侧。
- **pad_if_needed** (bool, 可选) - 如果输入图像高度或者宽度小于 `size` 指定的输出图像大小是否进行填充。默认值False不填充。
- **fill_value** (Union[int, tuple], 可选) - 边框的像素强度仅对padding_mode Border.CONSTANT有效。
如果是3元组则分别用于填充R、G、B通道。
如果是整数,则用于所有 RGB 通道。
fill_value 值必须在 [0, 255] 范围内, 默认值0。
- **padding_mode** (Border, 可选) - 边界填充方式, 默认值Border.CONSTANT。它可以是 [Border.CONSTANT、Border.EDGE、Border.REFLECT、Border.SYMMETRIC] 中的任何一个。
- **Border.CONSTANT** - 使用常量值进行填充。
- **Border.EDGE** - 使用各边的边界像素值进行填充。
- **Border.REFLECT** - 以各边的边界为轴进行镜像填充,忽略边界像素值。
- **Border.SYMMETRIC** - 以各边的边界为轴进行对称填充,包括边界像素值。
**异常:**
- **TypeError** - 如果 `size` 不是int或sequence类型或元素不为int类型。
- **TypeError** - 如果 `padding` 不是int或sequence类型或元素不为int类型。
- **TypeError** - 如果 `pad_if_needed` 不是bool类型。
- **TypeError** - 如果 `fill_value` 不是int或sequence类型或元素不为int类型。
- **TypeError** - 如果 `padding_mode` 不是 :class:`mindspore.dataset.vision.Border` 的类型。
- **ValueError** - 如果 `size` 不是正数。
- **ValueError** - 如果 `padding` 为负数。
- **ValueError** - 如果 `fill_value` 不在 [0, 255] 范围内。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,16 @@
mindspore.dataset.vision.c_transforms.RandomHorizontalFlip
==========================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomHorizontalFlip(prob=0.5)
以给定的概率水平随机翻转输入图像。
**参数:**
- **prob** (float, 可选) - 图像被翻转的概率,必须在 [0, 1] 范围内, 默认值0.5。
**异常:**
- **TypeError** - 如果 `prob` 不是float类型。
- **ValueError** - 如果 `prob` 不在 [0, 1] 范围内。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,16 @@
mindspore.dataset.vision.c_transforms.RandomHorizontalFlipWithBBox
==================================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomHorizontalFlipWithBBox(prob=0.5)
以给定的概率水平随机翻转输入图像并相应地调整边界框。
**参数:**
- **prob** (float, 可选) - 图像被翻转的概率,必须在 [0, 1] 范围内, 默认值0.5。
**异常:**
- **TypeError** - 如果 `prob` 不是float类型。
- **ValueError** - 如果 `prob` 不在 [0, 1] 范围内。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,17 @@
mindspore.dataset.vision.c_transforms.RandomPosterize
=====================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomPosterize(bits=(8, 8))
随机减少输入图像每个颜色通道的位数。
**参数:**
- **bits** (float, 可选) - 随机位数压缩的范围。位值必须在 [1,8] 范围内,并且在给定范围内至少包含一个整数值。它必须是 (min, max) 或整数格式。
如果min=max那么它是一个单一的位数压缩操作, 默认值:(8, 8)。
**异常:**
- **TypeError** - 如果 `bits` 不是int或整数序列类型。
- **ValueErro** - 如果 `bits` 不在 [1, 8] 范围内。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -0,0 +1,18 @@
mindspore.dataset.vision.c_transforms.RandomResize
==================================================
.. py:class:: mindspore.dataset.vision.c_transforms.RandomResize(size)
使用随机选择的插值模式调整输入图像的大小。
**参数:**
- **size** (Union[int, sequence]) - 调整后图像的输出大小。 大小值必须为正。
如果 size 是整数,则图像的较小边缘将调整为具有相同图像纵横比的该值。
如果 size 是一个长度为 2 的序列,它应该是 (高度, 宽度)。
**异常:**
- **TypeError** - 如果 `size` 不是int或sequence类型或元素不为int类型。
- **ValueError** - 如果 `size` 不是正数。
- **RuntimeError** - 如果输入图像的shape不是 <H, W> 或 <H, W, C>。

View File

@ -1,9 +1,11 @@
mindspore.dataset.vision
===================================
his module is to support vision augmentations. It includes two parts: c_transforms and py_transforms. C_transforms is a high performance image augmentation module which is developed with c++ opencv. Py_transforms provide more kinds of image augmentations which are developed with Python PIL.
此模块用于图像数据增强,包括 `c_transforms``py_transforms` 两个子模块。
`c_transforms` 是使用 C++ OpenCv 开发的高性能图像增强模块。
`py_transforms` 是使用 Python Pillow 开发的图像增强模块。
Common imported modules in corresponding API examples are as follows:
API样例中常用的导入模块如下
.. code-block::

View File

@ -285,13 +285,13 @@ class BoundingBoxAugment(ImageTensorOperation):
Apply a given image transform on a random selection of bounding box regions of a given image.
Args:
transform: C++ transformation operator to be applied on random selection
transform (TensorOperation): C++ transformation operator 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 ImageTensorOperation.
TypeError: If `transform` is not of type :class:`mindspore.dataset.vision.c_transforms.ImageTensorOperation`.
TypeError: If `ratio` is not of type float.
ValueError: If `ratio` is not in range [0, 1].
RuntimeError: If given bounding box is invalid.
@ -369,13 +369,13 @@ class ConvertColor(ImageTensorOperation):
Args:
convert_mode (ConvertMode): The mode of image channel conversion.
- ConvertMode.COLOR_BGR2BGRA, Add alpha channel to BGR image.
- ConvertMode.COLOR_BGR2BGRA, Convert BGR image to BGRA image.
- ConvertMode.COLOR_RGB2RGBA, Add alpha channel to RGB image.
- ConvertMode.COLOR_RGB2RGBA, Convert RGB image to RGBA image.
- ConvertMode.COLOR_BGRA2BGR, Remove alpha channel to BGR image.
- ConvertMode.COLOR_BGRA2BGR, Convert BGRA image to BGR image.
- ConvertMode.COLOR_RGBA2RGB, Remove alpha channel to RGB image.
- ConvertMode.COLOR_RGBA2RGB, Convert RGBA image to RGB image.
- ConvertMode.COLOR_BGR2RGBA, Convert BGR image to RGBA image.
@ -410,7 +410,7 @@ class ConvertColor(ImageTensorOperation):
- ConvertMode.COLOR_RGBA2GRAY, Convert RGBA image to GRAY image.
Raises:
TypeError: If `convert_mode` is not of type ConvertMode.
TypeError: If `convert_mode` is not of type :class:`mindspore.dataset.vision.c_transforms.ConvertMode`.
RuntimeError: If given tensor shape is not <H, W> or <H, W, C>.
Supported Platforms:
@ -489,7 +489,7 @@ class CutMixBatch(ImageTensorOperation):
prob (float, optional): The probability by which CutMix is applied to each image, range: [0, 1] (default = 1.0).
Raises:
TypeError: If `image_batch_format` is not of type ImageBatchFormat.
TypeError: If `image_batch_format` is not of type :class:`mindspore.dataset.vision.ImageBatchFormat`.
TypeError: If `alpha` is not of type float.
TypeError: If `prob` is not of type float.
ValueError: If `alpha` is less than or equal 0.
@ -555,11 +555,11 @@ class CutOut(ImageTensorOperation):
class Decode(ImageTensorOperation):
"""
Decode the input image in RGB mode(default) or BGR mode(deprecated).
Decode the input image in RGB mode(default) or BGR mode(option is deprecated).
Args:
rgb (bool, optional): Mode of decoding input image (default=True).
If True means format of decoded image is RGB else BGR(deprecated).
If True means format of decoded image is RGB else BGR(option is deprecated).
Raises:
RuntimeError: If `rgb` is False, since this option is deprecated.
@ -812,7 +812,7 @@ class NormalizePad(ImageTensorOperation):
The mean values must be in range (0.0, 255.0].
std (sequence): List or tuple of standard deviations for each channel, with respect to channel order.
The standard deviation values must be in range (0.0, 255.0].
dtype (str): Set the output data type of normalized image (default is "float32").
dtype (str, optional): Set the output data type of normalized image (default is "float32").
Raises:
TypeError: If `mean` is not of type sequence.
@ -876,7 +876,7 @@ class Pad(ImageTensorOperation):
Raises:
TypeError: If `padding` is not of type integer or sequence of integer.
TypeError: If `fill_value` is not of type integer or tuple of integer.
TypeError: If `padding_mode` is not of type Border.
TypeError: If `padding_mode` is not of type :class:`mindspore.dataset.vision.Border`.
ValueError: If `padding` is negative.
ValueError: If `fill_value` is not in range [0, 255].
RuntimeError: If given tensor shape is not <H, W> or <H, W, C>.
@ -944,7 +944,7 @@ class RandomAffine(ImageTensorOperation):
Apply Random affine transformation to the input image.
Args:
degrees (int or float or sequence): Range of the rotation degrees.
degrees (Union[int, float, sequence]): Range of the rotation degrees.
If `degrees` is a number, the range will be (-degrees, degrees).
If `degrees` is a sequence, it should be (min, max).
translate (sequence, optional): Sequence (tx_min, tx_max, ty_min, ty_max) of minimum/maximum translation in
@ -953,17 +953,17 @@ class RandomAffine(ImageTensorOperation):
(tx_min*width, tx_max*width) and (ty_min*height, ty_max*height), respectively.
If a tuple or list of size 2, then a translate parallel to the X axis in the range of
(translate[0], translate[1]) is applied.
If a tuple of list of size 4, then a translate parallel to the X axis in the range of
If a tuple or list of size 4, then a translate parallel to the X axis in the range of
(translate[0], translate[1]) and a translate parallel to the Y axis in the range of
(translate[2], translate[3]) are applied.
If None, no translation is applied.
scale (sequence, optional): Scaling factor interval, which must be non negative
(default=None, original scale is used).
shear (int or float or sequence, optional): Range of shear factor, which must be positive (default=None).
shear (Union[int, float, sequence], optional): Range of shear factor, which must be positive (default=None).
If a number, then a shear parallel to the X axis in the range of (-shear, +shear) is applied.
If a tuple or list of size 2, then a shear parallel to the X axis in the range of (shear[0], shear[1])
is applied.
If a tuple of list of size 4, then a shear parallel to X axis in the range of (shear[0], shear[1])
If a tuple or list of size 4, then a shear parallel to X axis in the range of (shear[0], shear[1])
and a shear parallel to Y axis in the range of (shear[2], shear[3]) is applied.
If None, no shear is applied.
resample (Inter, optional): An optional resampling filter (default=Inter.NEAREST).
@ -975,7 +975,7 @@ class RandomAffine(ImageTensorOperation):
- Inter.BICUBIC, means resample method is bicubic interpolation.
fill_value (tuple or int, optional): Optional fill_value to fill the area outside the transform
fill_value (Union[int, tuple], optional): Optional fill_value to fill the area outside the transform
in the output image. There must be three elements in tuple and the value of single element is [0, 255].
(default=0, filling is performed).
@ -984,7 +984,7 @@ class RandomAffine(ImageTensorOperation):
TypeError: If `translate` is not of type sequence.
TypeError: If `scale` is not of type sequence.
TypeError: If `shear` is not of type integer, float or sequence.
TypeError: If `resample` is not of type Inter.
TypeError: If `resample` is not of type :class:`mindspore.dataset.vision.Inter`.
TypeError: If `fill_value` is not of type integer or tuple of integer.
ValueError: If `degrees` is negative.
ValueError: If `translate` is not in range [-1.0, 1.0].
@ -1240,7 +1240,7 @@ class RandomCrop(ImageTensorOperation):
TypeError: If `padding` is not of type integer or sequence of integer.
TypeError: If `pad_if_needed` is not of type boolean.
TypeError: If `fill_value` is not of type integer or sequence of integer.
TypeError: If `padding_mode` is not of type Border.
TypeError: If `padding_mode` is not of type :class:`mindspore.dataset.vision.Border`.
ValueError: If `size` is not positive.
ValueError: If `padding` is negative.
ValueError: If `fill_value` is not in range [0, 255].
@ -1314,7 +1314,7 @@ class RandomCropDecodeResize(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.
@ -1401,7 +1401,7 @@ class RandomCropWithBBox(ImageTensorOperation):
TypeError: If `padding` is not of type integer or sequence of integer.
TypeError: If `pad_if_needed` is not of type boolean.
TypeError: If `fill_value` is not of type integer or sequence of integer.
TypeError: If `padding_mode` is not of type Border.
TypeError: If `padding_mode` is not of type :class:`mindspore.dataset.vision.Border`.
ValueError: If `size` is not positive.
ValueError: If `padding` is negative.
ValueError: If `fill_value` is not in range [0, 255].