主要内容

imageDataAugmenter

配置图像数据增强

描述

图像数据增强器配置图像增强的一组预处理选项,例如调整大小,旋转和反射。

TheimageDataAugmenter是used by anAugmentedimageGedataStore.生成批次的增强图像。有关更多信息,请参阅使用随机几何变换的培训增强图像.

Creation

描述

八月= ImagedataAugmenter.creates animageDataAugmenter具有默认属性值的对象与Identity转换一致。

example

八月= ImagedataAugmenter.(名称,价值)使用要设置的名称值对配置一组图像增强选项properties. You can specify multiple name-value pairs. Enclose each property name in quotes.

特性

展开全部

填充值用于在重新采样时定义界限点,指定为数字标量或数字矢量。

  • If the augmented images are single channel, thenfillvalue.必须是标量。

  • If the augmented images are multichannel, thenfillvalue.可以是标量或长度等于输入图像的信道数的矢量。例如,如果输入图像是RGB图像,则fillvalue.can be a vector of length 3.

对于灰度和彩色图像,默认填充值是0. For categorical images, the default fill value is an'<未定义>'标签和Trainnetwork.ignores filled pixels when training.

例子:128

左右方向的随机反射,指定为逻辑标量。什么时候RandXReflection真的(1),每个图像都以50%的概率水平反射。什么时候RandXReflection错误的(0),没有反映图像。

随机反射in the top-bottom direction, specified as a logical scalar. WhenRandYReflection真的(1),每个图像垂直反射,概率为50%。什么时候RandYReflection错误的(0),没有反映图像。

Range of rotation, in degrees, applied to the input image, specified as one of the following.

  • 2-element数值向量。第二个元素必须大于或等于第一元素。从指定间隔内随机从连续均匀分布中随机拾取旋转角度。

  • 功能手柄。The function must accept no input arguments and return the rotation angle as a numeric scalar. Use a function handle to pick rotation angles from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see创建功能句柄.

默认情况下,增强图像re not rotated.

例子:[-45 45]

Range of uniform (isotropic) scaling applied to the input image, specified as one of the following.

  • 2-element数值向量。第二个元素必须大于或等于第一元素。从指定间隔内的连续均匀分布随机挑选比例因子。

  • 功能手柄。函数必须接受否输入参数并将比例因子返回为数字标量。使用函数句柄来从不相交的间隔或使用不均匀的概率分布来选择比例因子。有关功能句柄的更多信息,请参阅创建功能句柄.

默认情况下,未缩放增强图像。

例子:[0.5 4]

应用于输入图像的水平缩放范围,指定为以下之一。

  • 2-element数值向量。第二个元素必须大于或等于第一元素。从指定间隔内的连续均匀分布随机拾取水平刻度系数。

  • 功能手柄。The function must accept no input arguments and return the horizontal scale factor as a numeric scalar. Use a function handle to pick horizontal scale factors from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see创建功能句柄.

默认情况下,增强图像未在水平方向上缩放。

Note

如果您指定RandScale, thenimageDataAugmenter忽略了价值randxscale.when scaling images.

例子:[0.5 4]

应用于输入图像的垂直缩放范围,指定为以下之一。

  • 2-element数值向量。第二个元素必须大于或等于第一元素。从指定间隔内的连续均匀分布随机拾取垂直比例因子。

  • 功能手柄。该函数必须接受否输入参数并将垂直比例因子返回为数字标量。使用功能手柄从不相交的间隔或使用不均匀的概率分布选择垂直缩放因子。有关功能句柄的更多信息,请参阅创建功能句柄.

默认情况下,增强图像未在垂直方向上缩放。

Note

如果您指定RandScale, thenimageDataAugmenter忽略了价值RandYScalewhen scaling images.

例子:[0.5 4]

施加到输入图像的水平剪切范围,指定为以下之一。剪切以度为单位测量角度,并且在范围内(-90,90)。

  • 2-element数值向量。第二个元素必须大于或等于第一元素。从指定间隔内的连续均匀分布随机拾取水平剪切角。

  • 功能手柄。The function must accept no input arguments and return the horizontal shear angle as a numeric scalar. Use a function handle to pick horizontal shear angles from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see创建功能句柄.

默认情况下,增强图像re not sheared in the horizontal direction.

例子:[0 45]

应用于输入图像的垂直剪切范围,指定为以下之一。剪切以度为单位测量角度,并且在范围内(-90,90)。

  • 2-element数值向量。第二个元素必须大于或等于第一元素。从指定间隔内的连续均匀分布随机拾取垂直剪切角。

  • 功能手柄。The function must accept no input arguments and return the vertical shear angle as a numeric scalar. Use a function handle to pick vertical shear angles from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see创建功能句柄.

默认情况下,增强图像re not sheared in the vertical direction.

例子:[0 45]

水平平移范围应用于输入图像,指定为以下之一。翻译距离以像素为单位测量。

  • 2-element数值向量。第二个元素必须大于或等于第一元素。水平平移距离从指定间隔内的连续均匀分布随机拾取。

  • 功能手柄。该函数必须接受否输入参数并将水平的翻译距离返回为数字标量。使用函数手柄从不相交的间隔或使用非均匀概率分布挑选水平平移距离。有关功能句柄的更多信息,请参阅创建功能句柄.

默认情况下,增强图像未在水平方向上翻译。

例子:[-5 5]

垂直平移范围应用于输入图像,指定为以下之一。翻译距离以像素为单位测量。

  • 2-element数值向量。第二个元素必须大于或等于第一元素。The vertical translation distance is picked randomly from a continuous uniform distribution within the specified interval.

  • 功能手柄。The function must accept no input arguments and return the vertical translation distance as a numeric scalar. Use a function handle to pick vertical translation distances from a disjoint interval or using a nonuniform probability distribution. For more information about function handles, see创建功能句柄.

默认情况下,增强图像re not translated in the vertical direction.

例子:[-5 5]

对象功能

augment 对多个图像应用相同的随机转换

例子

全部收缩

Create an image data augmenter that preprocesses images before training. This augmenter rotates images by random angles in the range [0, 360] degrees and resizes images by random scale factors in the range [0.5, 1].

augmenter = imageDataAugmenter(...'randroatation',[0 360],...'RandScale',[0.5 1])
Augmenter = ImagedataAugmenter具有属性:Filevalue:0 RandXreflection:0 Randyreflection:0 RandRotation:[0 360] RANDSCALE:[0.5000 1] RANDXSCALE:[1] RANCYSCALE:[1] RANDXSHEAR:[0] RANDXSHEAR:[0 0]] randXtranslation:[0] RandyTranslation:[0 0]

Create an augmented image datastore using the image data augmenter. The augmented image datastore also requires sample data, labels, and an output image size.

[XTrain,YTrain] = digitTrain4DArrayData; imageSize = [56 56 1]; auimds = augmentedImageDatastore(imageSize,XTrain,YTrain,'DataAugmentation',augmenter)
auimds = augmentedimageageataStore with属性:numobservations:5000 minibatchsize:128 dataAugment:[1x1 imagedataAugmenter] colorpreprocessing:'无'输出大小:[56 56] OuthtsizeMode:'调整大小'Dispatchinbackground:0

预览应用于图像数据存储中的前八个图像的随机转换。

minibatch = preview(auimds);imshow(Imtile(minibatch.input));

图包含轴。轴包含类型图像的对象。

Preview different random transformations applied to the same set of images.

minibatch = preview(auimds);imshow(Imtile(minibatch.input));

图包含轴。轴包含类型图像的对象。

使用增强图像数据列车卷积神经网络。数据增强有助于防止网络过度接收和记忆培训图像的确切细节。

Load the sample data, which consists of synthetic images of handwritten digits.

[XTrain,YTrain] = digitTrain4DArrayData;

digittrain4darraydata.将设置为4-D阵列数据的数字训练加载。XTrain是a 28-by-28-by-1-by-5000 array, where:

  • 28 is the height and width of the images.

  • 1是通道的数量。

  • 5000是手写数字的合成图像数量。

ytrain.是一个包含每个观察标签的分类矢量。

留出1000个图像以进行网络验证。

idx = randperm(size(XTrain,4),1000); XValidation = XTrain(:,:,:,idx); XTrain(:,:,:,idx) = []; YValidation = YTrain(idx); YTrain(idx) = [];

Create animageDataAugmenter指定图像增强的预处理选项的对象,例如调整大小,旋转,翻译和反射。随水平和垂直随机将图像随机转换为三个像素,并将相对于20度的角度旋转。

imageAugmenter = imageDataAugmenter(...'randroatation',[-20,20],...'randxtranslation',[ -  3 3],...'randytranslation',[ -  3 3])
Imageaugmenter = ImagedataAugmenter具有属性:FileValue:0 RandXreflection:0 Randyreflection:0 RandRotation:[-20 20] RANDSCALE:[1] RANDXSCALE:[1] RANDYSCALE:[1] RANDXSHEAR:[0] RANDYSHEAR:[00] RandXTranslation:[-3 3] RandyTranslation:[-3 3]

Create anAugmentedimageGedataStore.用于网络训练的对象并指定图像输出大小。在培训期间,数据存储区执行图像增强并调整图像大小。数据存储区增强了图像而不将任何图像保存到内存。Trainnetwork.updates the network parameters and then discards the augmented images.

图像= [28 28 1];Augimds = AugmentedimageDataStore(图像化,Xtrain,Ytrain,'DataAugmentation',imageaugmender);

指定卷积神经网络架构。

图层= [imageInputlayer(iconageize)卷积2dlayer(3,8,'填充','相同的')BatchnormalizationLayer Ruilulayer MaxPooling2dlayer(2,'Stride',2)卷积2dlayer(3,16,'填充','相同的')BatchnormalizationLayer Ruilulayer MaxPooling2dlayer(2,'Stride',2)卷积2dlayer(3,32,'填充','相同的')BatchnormalizationLayer Rublayer全连接列(10)SoftMaxLayer分类层];

用动量指定随机梯度下降的培训选项。

opts = trainingOptions('sgdm',...“MaxEpochs”15,...'洗牌','每个时代',...“阴谋”,'training-progress',...'verbose',错误的,...'vightationdata',{XValidation,YValidation});

Train the network. Because the validation images are not augmented, the validation accuracy is higher than the training accuracy.

net = trainNetwork(augimds,layers,opts);

尖端

  • 要预览应用于样本图像的转换,请使用augment功能。

  • 要在培训期间执行图像增强,请创建一个AugmentedimageGedataStore.并通过使用使用的预处理选项'DataAugmentation'名称 - 值对与一个imageDataAugmenter. The augmented image datastore automatically applies random transformations to the training data.

Introduced in R2017b