You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
augmentedImageDatastore内のプロパティについて
1 view (last 30 days)
Show older comments
Ren Okumura
on 31 Oct 2022
-
-
Direct link to this question
⋮
-
-
Direct link to this question
Commented: Ren Okumura
on 2 Nov 2022
ラベル付きのイメージデータストアをaugmentedImageDatastoreを使用してoutputSizeを変更しました。
その拡張イメージデータストアのプロパティを確認すると、元のイメージデータストアに付いていたラベルが確認できません。
この拡張イメージデータストアに、ラベルの情報は含まれているのでしょうか。
教えていただけると幸いです。よろしくお願いいたします。
3 Comments
Atsushi Ueno
on 31 Oct 2022
Moved: Atsushi Ueno
on 1 Nov 2022
>この拡張イメージデータストアに、ラベルの情報は含まれているのでしょうか
含まれていませんね。
上記質問でも同様の事が質問されています。元のイメージデータストアのラベルを参照する事が出来ます。
Ren Okumura
on 1 Nov 2022
Moved: Atsushi Ueno
on 1 Nov 2022
教えていただきありがとうございます。
分からず悩んでいた点だったため、大変助かりました!
Atsushi Ueno
on 1 Nov 2022
先の回答は誤り(でもないが不的確な回答)なので、コメントに移動しました。
Accepted Answer
Atsushi Ueno
on 1 Nov 2022
-
-
Direct link to this answer
⋮
-
-
Direct link to this answer
>この拡張イメージデータストアに、ラベルの情報は含まれているのでしょうか。
⇒はい、augmentedImageDatastore に ラベル情報は存在します。それはprivate属性の為ワークスペースに表示されません。augmentedImageDatastore の read 関数により取得する事が出来ます。
[XTrain,YTrain] = digitTrain4DArrayData; % XTrainは手書き文字5000枚、YTrainはラベル情報
augimds = augmentedImageDatastore([28 28 1],XTrain,YTrain) % augimdsのプロパティにラベル情報は無い(見えない)
augimds =
augmentedImageDatastore with properties:
NumObservations: 5000
MiniBatchSize: 128
DataAugmentation: 'none'
ColorPreprocessing: 'none'
OutputSize: [28 28]
OutputSizeMode: 'resize'
DispatchInBackground: 0
read(augimds) % Read関数でラベル情報(response:この例は手書き文字画像の種類)が得られた
ans = 128×2 table
input response
______________ ________
{28×28 double} 3
{28×28 double} 3
{28×28 double} 7
{28×28 double} 7
{28×28 double} 7
{28×28 double} 7
{28×28 double} 9
{28×28 double} 9
{28×28 double} 7
{28×28 double} 7
{28×28 double} 3
{28×28 double} 9
{28×28 double} 9
{28×28 double} 7
{28×28 double} 3
{28×28 double} 7
3 Comments
Atsushi Ueno
on 1 Nov 2022
% s = struct(obj) は、obj のプロパティに対応するフィールド名と値をもつスカラー構造体を作成します。
% 関数 struct は、obj を変換するのではなく、新しい構造体として s を作成します。
% この構造体はクラス情報を保持せず、プライベート プロパティ、保護プロパティおよび非表示プロパティは
% s 内のパブリック フィールドになります。この構文を使用すると、関数 struct が警告を発行します。
augmentedImageDatastoreを構造体として定義すればprivateプロパティがpublicになるんですね。
[XTrain,YTrain] = digitTrain4DArrayData; % XTrainは手書き文字5000枚、YTrainはラベル情報
augimds = augmentedImageDatastore([28 28 1],XTrain,YTrain)
augimds =
augmentedImageDatastore with properties:
NumObservations: 5000
MiniBatchSize: 128
DataAugmentation: 'none'
ColorPreprocessing: 'none'
OutputSize: [28 28]
OutputSizeMode: 'resize'
DispatchInBackground: 0
strct_augimds = struct(augimds) % クラスから構造体に変更
Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be avoided. Use DISP or DISPLAY to see the visible public details of an object. See 'help struct' for more information.
strct_augimds = struct with fields:
NumObservations: 5000
Files: {}
AlternateFileSystemRoots: {}
MiniBatchSize: 128
DatastoreInternal: [1×1 nnet.internal.cnn.datastore.FourDArrayMiniBatchDatastore]
ImageAugmenter: 'none'
DataAugmentation: 'none'
ColorPreprocessing: 'none'
OutputSize: [28 28]
OutputSizeMode: 'resize'
OutputRowsColsChannels: []
DispatchInBackground: 0
見えなかったprivateプロパティも見えるようになりましたが、まだラベル情報には辿り着けません。DatastoreInternalというプロパティの中にあるそうで、
temp = struct(strct_augimds.DatastoreInternal)
Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be avoided. Use DISP or DISPLAY to see the visible public details of an object. See 'help struct' for more information.
temp = struct with fields:
MiniBatchSize: 128
NumObservations: 5000
Input: [28×28×1×5000 double]
Response: [5000×1 categorical]
StartIndexOfCurrentMiniBatch: 1
OrderedIndices: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 … ]
ResponseSize: [28 28 1]
DataFormat: "matrix"
DispatchInBackground: 0
UsesInternalReadInterface: 1
手書き文字5000枚のラベル情報Responseに辿り着きました。
temp.Response'
ans = 1×5000 categorical array
Columns 1 through 1428
3 3 7 7 7 7 9 9 7 7 3 9 9 7 3 7 9 9 3 3 9 7 3 7 9 3 9 3 3 5 5 5 3 5 3 7 7 3 5 3 9 9 9 9 9 5 9 9 8 7 7 7 9 7 9 5 3 8 9 7 3 3 5 8 5 8 9 3 5 8 7 8 7 3 3 3 5 3 9 9 8 8 3 9 7 9 3 8 3 5 8 7 5 3 8 9 8 5 8 5 5 8 3 3 9 8 3 7 8 7 5 9 8 3 7 7 7 8 9 9 1 9 9 7 8 8 8 1 9 7 7 0 3 0 9 1 8 7 3 3 5 5 9 9 3 9 9 8 8 9 5 5 1 7 0 3 0 3 0 1 0 8 9 9 3 8 5 3 0 9 3 0 0 5 1 3 1 7 9 5 3 8 0 9 8 1 5 0 9 5 0 0 1 1 3 1 9 5 3 1 5 7 7 5 9 8 4 1 1 1 3 1 4 7 5 7 9 7 8 0 3 0 5 9 3 3 7 1 7 0 8 7 5 4 8 0 0 9 5 0 9 1 7 7 1 7 0 5 5 4 1 5 4 1 9 4 3 4 9 1 4 0 3 3 1 0 3 9 9 9 4 1 1 1 1 3 3 4 5 4 1 5 8 3 7 3 0 7 9 9 9 3 0 8 1 7 4 3 9 3 3 8 8 4 5 5 9 5 5 3 9 1 0 3 1 8 2 6 3 4 0 8 6 6 5 0 3 8 6 2 4 2 8 6 6 4 2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 7 1 9 5 2 6 9 5 6 0 2 0 8 4 3 4 8 4 1 6 1 6 9 5 1 5 5 7 8 8 3 0 0 8 8 5 5 4 8 0 5 4 5 1 6 4 7 3 1 9 6 2 5 6 6 4 7 2 9 9 4 6 0 2 2 3 9 9 8 9 8 9 3
Atsushi Ueno
on 1 Nov 2022
定義元のソースコードを読むのが一番ですが、場合によっては隠ぺいされていて読めなかったり、読めても無茶苦茶長くて挫折するので、上記の「構造体にコピー」する方法は有用だと思います。
type augmentedImageDatastore.m
% augmentedImageDatastore Generate batches of augmented image data
%
% ds = augmentedImageDatastore(outputSize,imds) returns an
% augmentedImageDatastore. outputSize is a two element vector which
% specifies the output image size in the form [outputWidth,
% outputHeight]. imds is an imageDatastore.
%
% ds = augmentedImageDatastore(outputSize,X,Y) returns an
% augmentedImageDatastore given arrays X and Y that define examples and
% corresponding responses.
%
% ds = augmentedImageDatastore(outputSize,X) returns an augmentedImageDatastore
% given an input array X that defines examples.
%
% ds = augmentedImageDatastore(outputSize,tbl) returns a
% an augmentedImageDatastore given a tbl which contains predictors in the
% first column as either absolute or relative image paths or images.
% If responses are specified, responses must be in the second column as
% categorical labels for the images. In a regression problem, responses
% must be in the second column as either vectors or cell arrays containing
% 3-D arrays or in multiple columns as scalars.
%
% ds = augmentedImageDatastore(outputSize,tbl, responseName,___)
% returns an augmentedImageDatastore which yields predictors and responses.
% tbl is a MATLAB table. responseName is a character vector specifying
% the name of the variable in tbl that contains the responses.
%
% ds = augmentedImageDatastore(outputSize,tbl,responseNames,___) returns
% an augmentedImageDatastore for use in multi-output regression problems.
% tbl is a MATLAB table. responseNames is a cell array of character
% vectors specifying the names of the variables in tbl that contain the
% responses.
%
% ds = augmentedImageDatastore(___,Name,Value) returns an
% augmentedImageDatastore using Name/Value pairs to configure
% image-preprocessing options.
%
% Parameters include:
%
% 'ColorPreprocessing' A scalar string or character vector specifying
% color channel pre-processing. This option can
% be used when you have a training set that
% contains both color and grayscale image data
% and you need data created by the datastore to
% be strictly color or grayscale. Options are:
% 'gray2rgb','rgb2gray','none'. For example, if
% you need to train a network that expects color
% images but some of the images in your training
% set are grayscale, then specifying the option
% 'gray2rgb' will replicate the color channels of
% the grayscale images in the input image set to
% create MxNx3 output images.
%
% Default: 'none'
%
% 'DataAugmentation' A scalar imageDataAugmenter object, string, or
% character array that specifies
% the kinds of image data augmentation that will
% be applied to generated images.
%
% Default: 'none'
%
% 'DispatchInBackground' Accelerate image augmentation by asyncronously
% reading, augmenting, and queueing augmented
% images for use in training. Requires Parallel
% Computing Toolbox.
%
% Default: false
%
% 'OutputSizeMode' A scalar string or character vector specifying the
% technique used to adjust image sizes to the
% specified 'OutputSize'. Options are: 'resize',
% 'centercrop', 'randcrop'.
%
% Default: 'resize'
%
% augmentedImageDatastore Properties:
%
% ColorPreprocessing - Defines color channel manipulation
% DataAugmentation - Defines data augmentation used
% DispatchInBackground - Whether background dispatch is used
% MiniBatchSize - Number of images returned in each read
% NumObservations - Total number of images in an epoch
% OutputSize - Vector of [width,height] of output images
% OutputSizeMode - Method used to resize output images
%
% augmentedImageDatastore Methods:
%
% augmentedImageDatastore - Construct an augmentedImageDatastore
% hasdata - Returns true if there is more data in the datastore
% partitionByIndex - Partitions an augmentedImageDatastore given indices
% partition - Returns a new datastore that represents a single
% partitioned portion of the original datastore
% numpartitions - Returns an estimate for a reasonable number of
% partitions to use with the partition function,
% according to the total data size
% subset - Subsets the datastore according to the specified
% file indices
% preview - Reads the first image from the datastore
% read - Reads a MiniBatch of data from the datastore
% readall - Reads all observations from the datastore
% readByIndex - Random access read from datastore given indices
% reset - Resets datastore to the start of the data
% shuffle - Shuffles the observations in the datastore
% transform - Create an altered form of the current datastore by
% specifying a function handle that will execute
% after read on the current datastore.
% combine - Create a new datastore that horizontally
% concatenates the result of read from two or more
% input datastores.
%
% Example 1
% ---------
% Train a convolutional neural network on some synthetic images of
% handwritten digits. Apply random rotations during training to add
% rotation invariance to trained network.
%
% [XTrain, YTrain] = digitTrain4DArrayData;
%
% imageSize = [28 28 1];
%
% layers = [ ...
% imageInputLayer(imageSize, 'Normalization', 'none');
% convolution2dLayer(5,20);
% reluLayer();
% maxPooling2dLayer(2,'Stride',2);
% fullyConnectedLayer(10);
% softmaxLayer();
% classificationLayer()];
%
% opts = trainingOptions('sgdm', 'Plots', 'training-progress');
%
% imageAugmenter = imageDataAugmenter('RandRotation',[-10 10]);
%
% ds = augmentedImageDatastore(imageSize,XTrain,YTrain,'DataAugmentation',imageAugmenter);
%
% net = trainNetwork(ds, layers, opts);
%
% Example 2
% ---------
% Resize all images in imageDatastore during inference to the required
% size of the inputImageLayer of alexnet.
%
% net = alexnet;
% imds = imageDatastore(fullfile(matlabroot,'toolbox','matlab','imagesci','peppers.png'));
% imds.Files = repelem(imds.Files,5,1);
% ds = augmentedImageDatastore(net.Layers(1).InputSize(1:2),imds);
% Ypred = classify(net,ds)
% See also imageDataAugmenter, imageInputLayer, trainNetwork
% Copyright 2017-2022 The MathWorks, Inc.
classdef augmentedImageDatastore <...
matlab.io.Datastore &...
matlab.io.datastore.MiniBatchable &...
matlab.io.datastore.BackgroundDispatchable &...
matlab.io.datastore.PartitionableByIndex &...
matlab.io.datastore.internal.RandomizedReadable &...
matlab.io.datastore.mixin.Subsettable &...
matlab.mixin.CustomDisplay &...
matlab.mixin.Copyable
properties (SetAccess = protected, Dependent)
%NumObservations - Number of observations
%
% The number of observations in the datastore.
NumObservations
%Files - Contained files in Datastore
%
% Cell array of character vectors of image files.
Files
end
properties (Dependent)
%AlternativeFileSystemRoots
%
% Alternate file system root paths for the Files.
AlternateFileSystemRoots
%MiniBatchSize - MiniBatch Size
%
% The number of observations returned as rows in the table
% returned by the read method.
MiniBatchSize
end
properties (Access = private)
DatastoreInternal
ImageAugmenter
end
properties (SetAccess = private)
%DataAugmentation - Augmentation applied to input images
%
% DataAugmentation is a scalar imageDataAugmenter object or a
% character vector or string. When DataAugmentation is 'none'
% no augmentation is applied to input images.
DataAugmentation
%ColorPreprocessing - Pre-processing of input image color channels
%
% ColorPreprocessing is a character vector or string specifying
% pre-proprocessing operations performed on color channels of
% input images. This property is used to ensure that all output
% images from the datastore have the number of color channels
% required by inputImageLayer. Valid values are
% 'gray2rgb','rgb2gray', and 'none'. If an input images already
% has the desired number of color channels, no operation is
% performed. For example, if 'gray2rgb' is specified and an
% input image already has 3 channels, no operation is performed.
ColorPreprocessing
%OutputSize - Size of output images
%
% OutputSize is a two element numeric vector of the form
% [numRows, numColumns] that specifies the size of output images
% returned by augmentedImageDatastore.
OutputSize
%OutputSizeMode - Method used to resize output images.
%
% OutputSizeMode is a character vector or string specifying the
% method used to resize output images to the requested
% OutputSize. Valid values are 'centercrop', 'randcrop', and
% 'resize' (default).
OutputSizeMode
end
properties (Access = private)
OutputRowsColsChannels % The expected output image size [numRows, numCols, numChannels].
end
methods(Access = protected)
% Override copyElement method:
function cpObj = copyElement(obj)
cpObj = copyElement@matlab.mixin.Copyable(obj);
% Make a deep copy of the underlying Datastore
cpObj.DatastoreInternal = copy(obj.DatastoreInternal);
end
end
methods
function self = augmentedImageDatastore(varargin)
narginchk(2,inf)
inputs = self.parseInputs(varargin{:});
if self.NumObservations > 0
self.ImageAugmenter = inputs.DataAugmentation;
self.DispatchInBackground = inputs.DispatchInBackground;
reset(self.DatastoreInternal);
end
end
function set.MiniBatchSize(self,batchSize)
self.DatastoreInternal.MiniBatchSize = batchSize;
end
function batchSize = get.MiniBatchSize(self)
batchSize = self.DatastoreInternal.MiniBatchSize;
end
function files = get.Files(self)
if isa(self.DatastoreInternal,'nnet.internal.cnn.datastore.ImageDatastoreMiniBatchDatastore')
files = self.DatastoreInternal.imds.Files;
else
files = {};
end
end
function altRoots = get.AlternateFileSystemRoots(self)
if isa(self.DatastoreInternal,'nnet.internal.cnn.datastore.ImageDatastoreMiniBatchDatastore')
altRoots = self.DatastoreInternal.imds.AlternateFileSystemRoots;
else
altRoots = {};
end
end
function set.AlternateFileSystemRoots(self,newRoots)
if isa(self.DatastoreInternal,'nnet.internal.cnn.datastore.ImageDatastoreMiniBatchDatastore')
self.DatastoreInternal.imds.AlternateFileSystemRoots = newRoots;
else
error(message('nnet_cnn:augmentedImageDatastore:invalidSetAltRoot'));
end
end
function numObs = get.NumObservations(self)
numObs = self.DatastoreInternal.NumObservations;
end
end
methods
function reset(self)
self.DatastoreInternal.reset();
end
function [data,info] = readByIndex(self,indices)
[input,info] = self.DatastoreInternal.readByIndex(indices);
input = self.applyAugmentationPipelineToBatch(input);
[data,info] = iConvertDatastoreOutputToTable(input,info);
end
function [data,info] = read(self)
if ~self.hasdata()
error(message('nnet_cnn:augmentedImageDatastore:outOfData'));
end
[input,info] = self.DatastoreInternal.read();
input = self.applyAugmentationPipelineToBatch(input);
[data,info] = iConvertDatastoreOutputToTable(input,info);
end
function TF = hasdata(self)
TF = hasdata(self.DatastoreInternal);
end
function newds = partitionByIndex(self,indices)
newds = copy(self);
newds.DatastoreInternal = partitionByIndex(self.DatastoreInternal,indices);
end
function newds = subset(self,indices)
newds = partitionByIndex(self,indices);
end
function n = numobservations(self)
n = self.NumObservations;
end
end
methods (Hidden)
% Reorder is an undocumented interface for doing in place shuffling
% without a copy.
function reorder(self,indices)
self.DatastoreInternal.reorder(indices);
end
function frac = progress(self)
frac = progress(self.DatastoreInternal);
end
end
methods (Access = private)
function determineExpectedOutputSize(self,X)
% If a user specifies a ColorPreprocessing option, we know the
% number of channels to expect in each mini-batch. If they
% don't specify a ColorPreprocessing option, we need to look at
% an example from the underlying datastore and assume all
% images will have a consistent number of channels when forming
% mini-batches.
if strcmp(self.ColorPreprocessing,'rgb2gray')
self.OutputRowsColsChannels = [self.OutputSize,1];
elseif strcmp(self.ColorPreprocessing,'gray2rgb')
self.OutputRowsColsChannels = [self.OutputSize,3];
elseif strcmp(self.ColorPreprocessing,'none')
if iscell(X)
X = X{1};
end
exampleNumChannels = size(X,3);
self.OutputRowsColsChannels = [self.OutputSize,exampleNumChannels];
else
assert(false,'Unexpected ColorPreprocessing option.');
end
end
function Xout = applyAugmentationPipelineToBatch(self,X)
if iscell(X)
Xout = cellfun(@(c) self.applyAugmentationPipeline(c),X,'UniformOutput',false);
else
batchSize = size(X,4);
Xout = cell(batchSize,1);
for obs = 1:batchSize
temp = self.preprocessColor(X(:,:,:,obs));
temp = self.augmentData(temp);
Xout{obs} = self.resizeData(temp);
end
end
end
function Xout = applyAugmentationPipeline(self,X)
if isempty(self.OutputRowsColsChannels)
self.determineExpectedOutputSize(X);
end
if isequal(self.ColorPreprocessing,'none') && (size(X,3) ~= self.OutputRowsColsChannels(3))
error(message('nnet_cnn:augmentedImageDatastore:mismatchedNumberOfChannels','''ColorPreprocessing'''));
end
temp = self.preprocessColor(X);
temp = self.augmentData(temp);
Xout = self.resizeData(temp);
end
function miniBatchData = augmentData(self,miniBatchData)
if ~strcmp(self.DataAugmentation,'none')
miniBatchData = self.ImageAugmenter.augment(miniBatchData);
end
end
function Xout = resizeData(self,X)
inputSize = size(X);
if isequal(inputSize(1:2),self.OutputSize)
Xout = X; % no-op if X is already desired Outputsize
return
end
if strcmp(self.OutputSizeMode,'resize')
Xout = augmentedImageDatastore.resizeImage(X,self.OutputSize);
elseif strcmp(self.OutputSizeMode,'centercrop')
Xout = augmentedImageDatastore.centerCrop(X,self.OutputSize);
elseif strcmp(self.OutputSizeMode,'randcrop')
Xout = augmentedImageDatastore.randCrop(X,self.OutputSize);
end
end
function Xout = preprocessColor(self,X)
if strcmp(self.ColorPreprocessing,'rgb2gray')
Xout = convertRGBToGrayscale(X);
elseif strcmp(self.ColorPreprocessing,'gray2rgb')
Xout = convertGrayscaleToRGB(X);
elseif strcmp(self.ColorPreprocessing,'none')
Xout = X;
end
end
end
methods (Access = 'protected')
function groups = getPropertyGroups(self)
groups = getPropertyGroups@matlab.mixin.CustomDisplay(self);
if ~isa(self.DatastoreInternal,'nnet.internal.cnn.datastore.ImageDatastoreMiniBatchDatastore')
% Don't display Files or AlternativeFileSystemRoots if the
% underlying data was not specified as an ImageDatastore.
currentStruct = groups.PropertyList;
newStruct = rmfield(currentStruct,'Files');
newStruct = rmfield(newStruct,'AlternateFileSystemRoots');
groups = matlab.mixin.util.PropertyGroup(newStruct);
end
end
end
methods (Access = 'private')
function inputStruct = parseInputs(self,varargin)
p = inputParser();
p.addRequired('outputSize',@outputSizeValidator);
p.addRequired('X');
p.addOptional('Y',[]);
p.addParameter('DataAugmentation','none',@augmentationValidator);
colorPreprocessing = 'none';
p.addParameter('ColorPreprocessing','none',@colorPreprocessingValidator);
outputSizeMode = 'resize';
p.addParameter('OutputSizeMode','resize',@outputSizeModeValidator);
backgroundExecutionValidator = @(TF) validateattributes(TF,...
{'numeric','logical'},{'scalar','real'},mfilename,'BackgroundExecution');
p.addParameter('DispatchInBackground',false,backgroundExecutionValidator);
p.addParameter('BackgroundExecution',false,backgroundExecutionValidator);
responseNames = [];
if (istable(varargin{2}) && ~isempty(varargin{2}))
tbl = varargin{2};
if (length(varargin) > 2) && (ischar(varargin{3}) || isstring(varargin{3}) || iscellstr(varargin{3}))
if checkValidResponseNames(varargin{3},tbl)
responseNames = varargin{3};
varargin(3) = [];
end
end
end
p.parse(varargin{:});
inputStruct = manageDispatchInBackgroundNameValue(p);
self.DataAugmentation = inputStruct.DataAugmentation;
self.OutputSize = inputStruct.outputSize(1:2);
self.OutputSizeMode = outputSizeMode;
self.ColorPreprocessing = colorPreprocessing;
% Check if Y was specified for table or imageDatastore inputs.
propertiesWithDefaultValues = string(p.UsingDefaults);
if (isa(inputStruct.X,'matlab.io.datastore.ImageDatastore') || isa(inputStruct.X,'table')) && ~any(propertiesWithDefaultValues == "Y")
error(message('nnet_cnn:augmentedImageDatastore:invalidYSpecification',class(inputStruct.X)));
end
if ~isempty(responseNames)
inputStruct.X = selectResponsesFromTable(inputStruct.X,responseNames);
inputStruct.Y = responseNames;
end
% Validate numeric inputs
if isnumeric(inputStruct.X) || iscategorical(inputStruct.X) || islogical(inputStruct.X)
validateattributes(inputStruct.X,{'single','double','logical','categorical','uint8','int8','uint16','int16','uint32','int32'},...
{'nonsparse','real'},mfilename,'X');
validateattributes(inputStruct.Y,{'single','double','logical','categorical','uint8','int8','uint16','int16','uint32','int32','categorical'},...
{'nonsparse'},mfilename,'Y');
if ~isempty(inputStruct.Y)
if iscategorical(inputStruct.Y)
if ~isvector(inputStruct.Y)
error(message('nnet_cnn:augmentedImageDatastore:InvalidClassificationResponse'))
else
% Make sure responses are stored as column
% vectors
inputStruct.Y = inputStruct.Y(:);
end
end
end
end
try
self.DatastoreInternal = nnet.internal.cnn.datastore.MiniBatchDatastoreFactory.createMiniBatchDatastore(...
inputStruct.X ,inputStruct.Y, inputStruct.outputSize);
catch ME
throwAsCaller(ME);
end
function TF = colorPreprocessingValidator(sIn)
colorPreprocessing = validatestring(sIn,{'none','rgb2gray','gray2rgb'},...
mfilename,'ColorPreprocessing');
TF = true;
end
function TF = outputSizeModeValidator(sIn)
outputSizeMode = validatestring(sIn,...
{'resize','centercrop','randcrop'},mfilename,'OutputSizeMode');
TF = true;
end
function TF = outputSizeValidator(sizeIn)
validateattributes(sizeIn,...
{'numeric'},{'vector','integer','finite','nonsparse','real','positive'},mfilename,'OutputSize');
if (numel(sizeIn) ~= 2) && (numel(sizeIn) ~=3)
error(message('nnet_cnn:augmentedImageDatastore:invalidOutputSize'));
end
TF = true;
end
end
end
methods(Static, Hidden = true)
function self = loadobj(S)
self = augmentedImageDatastore(S.OutputSize,S.DatasourceInternal,...
'DispatchInBackground',S.BackgroundExecution,...
'ColorPreprocessing',S.ColorPreprocessing,...
'DataAugmentation',S.DataAugmentation,...
'OutputSizeMode',S.OutputSizeMode);
if isfield(S,'MiniBatchSize')
self.MiniBatchSize = S.MiniBatchSize;
else
self.MiniBatchSize = 128;
end
end
end
methods (Hidden)
function S = saveobj(self)
S = struct('BackgroundExecution',self.DispatchInBackground,...
'ColorPreprocessing',self.ColorPreprocessing,...
'DataAugmentation',self.DataAugmentation,...
'OutputSize',self.OutputSize,...
'OutputSizeMode',self.OutputSizeMode,...
'DatasourceInternal',self.DatastoreInternal,...
'MiniBatchSize',self.MiniBatchSize);
end
end
methods (Hidden, Static)
function imOut = resizeImage(im,outputSize)
classIn = class(im);
interpMethod = 'linear';
if isa(im,'categorical')
cats = categories(im);
im = single(im);
interpMethod = 'nearest';
elseif islogical(im)
im = uint8(im);
interpMethod = 'nearest';
end
ippResizeSupportedWithCast = isa(im,'int8') || isa(im,'uint16') || isa(im,'int16');
ippResizeSupportedForType = isa(im,'uint8') || isa(im,'single');
ippResizeSupported = ippResizeSupportedWithCast || ippResizeSupportedForType;
if ippResizeSupportedWithCast
im = single(im);
end
if ippResizeSupported
imOut = nnet.internal.cnnhost.resizeImage2D(im,outputSize,interpMethod,true);
else
if string(interpMethod) == "linear"
interpMethod = 'bilinear';
end
imOut = imresize(single(im),'OutputSize',outputSize,'Method',interpMethod);
end
classIn = string(classIn);
if classIn == "categorical"
imOut = categorical(imOut,1:numel(cats),cats);
elseif classIn == "logical"
imOut = logical(imOut);
end
end
function im = centerCrop(im,outputSize)
sizeInput = size(im);
if any(sizeInput(1:2) < outputSize)
error(message('nnet_cnn:augmentedImageDatastore:invalidCropOutputSize','''OutputSizeMode''',mfilename, '''centercrop''','''OutputSize'''));
end
x = (size(im,2) - outputSize(2)) / 2;
y = (size(im,1) - outputSize(1)) / 2;
im = augmentedImageDatastore.crop(im,...
[x y, outputSize(2), outputSize(1)]);
end
function rect = randCropRect(im,outputSize)
x = randi([1, min(size(im,2),max(1,size(im,2)-outputSize(2)))]);
y = randi([1, min(size(im,1),max(1,size(im,1)-outputSize(1)))]);
rect = [x y outputSize(2), outputSize(1)];
end
function rect = randCropCuboid(im,outputSize)
x = randi([1, min(size(im,2),max(1,size(im,2)-outputSize(2)))]);
y = randi([1, min(size(im,1),max(1,size(im,1)-outputSize(1)))]);
z = randi([1, min(size(im,3),max(1,size(im,3)-outputSize(3)))]);
rect = [x y z outputSize(2), outputSize(1), outputSize(3)];
end
function im = randCrop(im,outputSize)
sizeInput = size(im);
if any(sizeInput(1:2) < outputSize)
error(message('nnet_cnn:augmentedImageDatastore:invalidCropOutputSize','''OutputSizeMode''',mfilename, '''randcrop''','''OutputSize'''));
end
rect = augmentedImageDatastore.randCropRect(im,outputSize);
im = augmentedImageDatastore.cropGivenDiscreteValuedRect(im,rect);
end
function B = cropGivenDiscreteValuedRect(A,rect)
rowStart = rect(2);
rowEnd = rowStart + rect(4) - 1;
colStart = rect(1);
colEnd = colStart + rect(3) - 1;
B = A(rowStart:rowEnd,colStart:colEnd,:);
end
function B = cropGivenDiscreteValuedCuboid(A,cuboid)
rowStart = cuboid(2);
rowEnd = rowStart + cuboid(5) - 1;
colStart = cuboid(1);
colEnd = colStart + cuboid(4) - 1;
depthStart = cuboid(3);
depthEnd = depthStart + cuboid(6) - 1;
B = A(rowStart:rowEnd,colStart:colEnd,depthStart:depthEnd,:);
end
function B = crop(A,rect)
% rect is [x y width height] in floating point.
% Convert from (x,y) real coordinates to [m,n] indices.
rect = floor(rect);
m1 = rect(2) + 1;
m2 = rect(2) + rect(4);
n1 = rect(1) + 1;
n2 = rect(1) + rect(3);
m1 = min(size(A,1),max(1,m1));
m2 = min(size(A,1),max(1,m2));
n1 = min(size(A,2),max(1,n1));
n2 = min(size(A,2),max(1,n2));
B = A(m1:m2, n1:n2, :, :);
end
end
end
function TF = checkValidResponseNames(responseNames, tbl)
% iAssertValidResponseNames Assert that the response names are variables
% of the table and they do not refer to the first column.
variableNames = tbl.Properties.VariableNames;
refersToFirstColumn = ismember( variableNames(1), responseNames );
responseNamesAreAllVariables = all( ismember(responseNames,variableNames) );
TF = ~(refersToFirstColumn || ~responseNamesAreAllVariables);
end
function resTbl = selectResponsesFromTable(tbl, responseNames)
% iSelectResponsesFromTable Return a new table with only the first column
% (predictors) and the variables specified in responseNames.
variableNames = tbl.Properties.VariableNames;
varTF = ismember(variableNames, responseNames);
% Make sure to select predictors (first column) as well
varTF(1) = 1;
resTbl = tbl(:,varTF);
end
function TF = augmentationValidator(valIn)
if ischar(valIn) || isstring(valIn)
TF = string('none').contains(lower(valIn)); %#ok<STRQUOT>
elseif isa(valIn,'imageDataAugmenter') && isscalar(valIn)
TF = true;
else
TF = false;
end
end
function im = convertRGBToGrayscale(im)
if (ndims(im) == 3 && size(im,3) == 3)
im = rgb2gray(im);
end
end
function im = convertGrayscaleToRGB(im)
if size(im,3) == 1
im = repmat(im,[1 1 3]);
end
end
function c = iFormatResponse(X)
% Format the responses. If the responses were numeric, return as a cell
% array with each observation in a cell.
if isnumeric(X)
if isvector(X)
% Put each element in a cell
c = num2cell(X);
else
% Always assume that the observation dimension is 4
obsDim = 4;
% Put each observation in a cell
c = num2cell(X,1:(obsDim-1));
end
% Force c as column.
c = c(:);
else
% Response is already a cell or categorical.
c = X;
end
end
function [data,info] = iConvertDatastoreOutputToTable(input,info)
% Process the output of the datastore and create the table returned when
% calling "read".
response = info.Response;
info = rmfield(info,'Response');
if isempty(response)
data = table(input);
else
response = iFormatResponse(response);
data = table(input,response);
end
end
function resultsStruct = manageDispatchInBackgroundNameValue(p)
resultsStruct = p.Results;
DispatchInBackgroundSpecified = ~any(strncmp('DispatchInBackground',p.UsingDefaults,length('DispatchInBackground')));
BackgroundExecutionSpecified = ~any(strncmp('BackgroundExecution',p.UsingDefaults,length('BackgroundExecution')));
% In R2017b, BackgroundExecution was name used to control
% DispatchInBackground. Allow either to be specified.
if BackgroundExecutionSpecified && ~DispatchInBackgroundSpecified
resultsStruct.DispatchInBackground = resultsStruct.BackgroundExecution;
end
end
Ren Okumura
on 2 Nov 2022
同じ方法で行わせていただいたところ、私も元のイメージデータストアとそのラベル情報まで辿り着くことができました!
ご丁寧に教えていただきありがとうございました。大変お世話になりました!
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)