主要内容

RandompatchExtractionDatastore

用于从图像或像素标签图像中提取随机2-D或3-D随机补丁的数据存储

描述

ARandompatchExtractionDatastore提取物来自两个基于图像的数据存储的相应随机贴合贴片。例如,输入数据存储可以是两个图像数据存储,其中包含网络输入和所需的网络响应,以训练图像到图像回归网络,或地面真相图像和用于培训语义分割网络的像素标签数据。

This object requires that you have Deep Learning Toolbox™.

Note

当您使用RandompatchExtractionDatastore作为训练数据的来源,数据存储在每个时期从每个图像中提取多个随机补丁,因此每个时期都使用略有不同的数据集。每个时期的训练补丁的实际数量是训练图像的数量乘以PatchesPerImage。这image patches are not stored in memory.

创建

描述

example

补丁= randomPatchExtractionDatastore(ds1,ds2,PatchSize)创建一个数据存储,以提取随机位置的大小贴片PatchSizefrom input data in datastoreds1和response data in datastoreds2

补丁= randomPatchExtractionDatastore(ds1,ds2,PatchSize,Name,Value)uses name-value pairs to set thePatchesPerImage,数据调整, 和dispatchinbackgroundproperties. You can specify multiple name-value pairs. Enclose each property name in quotes.

例如,RandompatchExtractionDatastore(IMDS1,IMDS2,50,“ PatchEsperimage”,40)创建一个数据存储,该数据存储从图像数据存储中的每个图像中随机生成40个大小50乘50像素的补丁imds1imds2

Input Arguments

展开全部

输入数据containing training input to the network, specified as anImageDatastore,PixelLabelDatastore(计算机视觉工具箱), 或者变换的达塔斯托尔

指定PixelLabelDatastorerequires Computer Vision Toolbox™.

Note

ImageDatastore允许使用预摘要对JPG或PNG图像文件进行批次阅读。如果您使用自定义功能读取图像,则不会发生预取。

Response data representing the desired network responses, specified as anImageDatastore,PixelLabelDatastore(计算机视觉工具箱), 或者变换的达塔斯托尔。如果指定变换的达塔斯托尔,那么基础数据存储必须是ImageDatastore或者aPixelLabelDatastore

指定PixelLabelDatastore需要计算机视觉工具箱。

Note

ImageDatastore允许使用预摘要对JPG或PNG图像文件进行批次阅读。如果您使用自定义功能读取图像,则不会发生预取。

特性

展开全部

此属性仅阅读。

补丁大小, specified as one of the following.

  • 2D斑块的正整数的2元素向量。PatchSize具有[rc] 在哪里r指定行的数量和c指定补丁中的列数。

  • A 3-element vector of positive integers for 3-D patches.PatchSize具有[rcp] 在哪里rspecifies the number of rows,cspecifies the number of columns, andp指定补丁中的平面数。

每个图像的随机补丁数, specified as a positive integer.

应用于输入图像的预处理,指定为imageDataAugmenter(深度学习工具箱)object or'none'。When数据调整is'none',没有预处理应用于输入图像。

增强具有随机转换的数据,例如调整,旋转和反射,以防止网络过度拟合和记住训练数据的确切细节。这RandompatchExtractionDatastoreapplies the same random transformation to both patches in each pair. The datastore augments data in real-time while training.

数据调整property is not supported for 3-D data. To preprocess 3-D data, use the转换功能。

Dispatch observations in the background during training, prediction, or classification, specified asfalse或者真的。要使用背景调度,您必须具有并行计算工具箱™。

Number of observations that are returned in each batch. You can change the value ofMiniBatchSizeonly after you create the datastore. For training, prediction, and classification, theMiniBatchSize属性设置为定义的迷你批量大小训练(深度学习工具箱)

此属性仅阅读。

Total number of observations in theRandompatchExtractionDatastore。观察的数量是一个训练时期的长度。

Object Functions

结合 Combine data from multiple datastores
hasdata Determine if data is available to read
数字 数据存储分区的数量
分割 分区数据存储
分割ByIndex 分割RandompatchExtractionDatastoreaccording to indices
预习 Preview subset of data in datastore
从中读取数据RandompatchExtractionDatastore
读all 在数据存储中读取所有数据
ReadByIndex Read data specified by index fromRandompatchExtractionDatastore
重置 将数据存储重置为初始状态
shuffle Shuffle data in datastore
转换 Transform datastore
可以分配 确定数据存储是否可以分区
isShuffleable Determine whether datastore is shuffleable

例子

collapse all

创建一个包含训练图像的图像数据存储。此示例中的数据存储包含JPEG颜色图像。

imageDir = fullfile(toolboxdir('图片'),'imdata');imds1 = imageDatastore(imageDir,“ fileextensions','.jpg');

创建一个second datastore that transforms the images inimds1通过应用高斯模糊。

imds2 = transform(imds1,@(x)imgaussfilt(x,2));

创建一个imageDataAugmenter在[0,90]度范围内以随机角度旋转图像,并水平反映图像数据。

增强器= iMagedataaugmenter('randrotation',[0 90],“ Randxfellection”,真的)
augmenter =属性属性:fillvalue:0 randxreflection:1 randyreflection:0 randrotation:[0 90] randscale:[1 1] randxscale:[1 1] randyscale:[1 1] [1 1] randxshear:[1] randxshear:[0] randyshear:[0] randyshear:[0] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00士面的人] randxtranslation:[0 0] randytranslation:[0 0]

创建一个RandompatchExtractionDatastore从未加工的训练图像和相应的平滑响应图像中提取大小100 x 100的随机斑块的对象。通过设置数据调整property.

patchds = randompatchextractiondatastore(imds1,imds2,[100 100],...'DataAugmentation',augmenter)
补丁= randomPatchExtractionDatastore with properties: PatchesPerImage: 128 PatchSize: [100 100] DataAugmentation: [1×1 imageDataAugmenter] MiniBatchSize: 128 NumObservations: [] DispatchInBackground: 0

Preview a set of augmented image patches and the corresponding smoothed image patches.

minibatch = preview(patchds); inputs = minibatch.InputImage; responses = minibatch.ResponseImage; test = cat(2,inputs,responses); montage(test','尺寸',[8 2]) title(“输入(左)和响应(右)”)

创建一个包含训练图像的图像数据存储。

datadir = fullfile(toolboxDir(工具箱)('vision'),'VisionData',“三角形图”);imageDir = fullfile(dataDir,'trainingImages');imds = imagedatastore(ImageDir);

定义类名称及其关联的标签ID。然后,创建一个包含训练图像的地面真象像素标签的像素标签数据存储。

classNames = [“三角形”,“背景”]; labelIDs = [255 0]; labelDir = fullfile(dataDir,“训练标签”);pxds = pixelLabelDatastore(labelDir,classNames,labelIDs);

创建一个随机的补丁提取数据存储,以从图像和相应的像素标签中提取大小32 x-32像素的随机补丁。设置可选PatchesPerImage从每个图像和像素标签对中提取512个随机补丁的属性。

patchds = randompatchextractiondatastore(imds,pxds,32,...“ patchesperimage',512);

创建一个用于语义细分的网络。

layers = [imageInputlayer([32 32 1])卷积2Dlayer(3,64,'填充',1)relulayer()maxpooling2dlayer(2,'Stride',2)卷积2Dlayer(3,64,,'填充',1)relulayer()transposedconv2dlayer(4,64,,'Stride',2,“种植”,1) convolution2dLayer(1,2) softmaxLayer() pixelClassificationLayer() ]
层= 10x1层阵列,带有层:1''图像输入32x32x1图像,带有“ zerecenter”归一化2''卷积64 3x3卷积,步幅[1 1]和填充[1 1 1 1] 3'''''relu 4''max'合并2x2 max plies [2 2]和填充[0 0 0 0] 5''卷积64 3x3卷积,步幅[1 1]和填充[1 1 1 1] 6'6''relu Relu 7''''''''''4x4跨步卷积[2 2]并输出裁剪[1 1] 8''卷积2 1x1卷积,步幅[1 1]和填充[0 0 0 0 0] 9''softmax softmax softmax 10''像素分类层交叉 -熵损失

设置培训选项。为了减少训练时间,请设置Maxepochsto 5.

选项=训练('sgdm',...'InitialLearnRate',1E-3,...“ maxepochs”,5,...“冗长”,错误的);

Train the network.

net = trainnetwork(patchds,layers,options);

提示

  • RandompatchExtractionDatastoreexpects that the output from the在输入数据存储上的操作返回相同大小的数组。

  • If the input datastore is anImageDatastore, then the values in its标签property are ignored by theRandompatchExtractionDatastore

  • 可视化2-D数据RandompatchExtractionDatastore,您可以使用预习函数,返回表中的数据子集。通过使用montage功能。例如,此代码显示图像补丁的预览RandompatchExtractionDatastorecalled补丁

    minibatch = preview(patchds); montage(minibatch.InputImage)

Version History

Introduced in R2018b