augmentedI​mageDatast​oreに格納した変数​にインデックスorプ​ロパティ(変数.la​bel)ができなくて​困っています。可能で​すか?

1 view (last 30 days)
imds = imageDatastore('機械学習500',"IncludeSubfolders",true,"LabelSource","foldernames");
[xtrain,xval] = splitEachLabel(imds,0.5,"randomized");
xtrainimg = augmentedImageDatastore([128 128 1],xtrain,"ColorPreprocessing","gray2rgb");
xvalimg = augmentedImageDatastore([128 128 1],xval,"ColorPreprocessing","gray2rgb");
whos xval
whos imds
T = imshow(readimage(imds,1))
whos T
Dt= zeros(128,128,1,2500);
Dv = zeros(128,128,1,2500);
for i=1:numel(xtrainimg.Files)
ytraining = xtrainimg.label(i); <ー%質問箇所.labelをつけたい!ができないので他のアイデアをご教授してほ                             しいです!
yval = xvalimg.label(i)
I = imread (xtrainimg.Files{i});
Dt(:,:,:,i) = I;
II = imread (xvalimg.Files{i});
Dv(:,:,:,i) = II;
end
Dt(:,:,:,3)
[Dt,~,ytraining] = digitTrain4DArrayData;
[Dv,~,yval] = digitTest4DArrayData;
したいことは画像の名前と画像を紐づけしたいということです。 

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 1 Jul 2022
Edited: Atsushi Ueno on 2 Jul 2022
imds = imageDatastore(fullfile(matlabroot,"toolbox","matlab"),"IncludeSubfolders",true,"FileExtensions",".tif","LabelSource","foldernames");
xtrainimg = augmentedImageDatastore([128 128],imds,'ColorPreprocessing','rgb2gray'); % サンプルのimageDatastoreデータ
%[data,info] = read(xtrainimg) % 【追加】予めaugmentedImageDatastoreのオブジェクト関数read()を実行し出力を得る【コメントを受けコメントアウト】
data = readall(xtrainimg) % 【コメント受け追記】予めaugmentedImageDatastoreのオブジェクト関数readall()を実行し出力を得る
data = 2×2 table
input response _______________ ________ {128×128 uint8} demos {128×128 uint8} imagesci
for i=1:numel(xtrainimg.Files)
ytraining = data.response(i) % <ー%質問箇所.labelをつけたい!ができないので他のアイデアをご教授してほしいです!
% ytraining = info.Label(i) % 【コメントを受けコメントアウト】
end % data.responseもinfo.Labelも同じデータの様です
ytraining = categorical
demos
ytraining = categorical
imagesci
  4 Comments
Atsushi Ueno
Atsushi Ueno on 2 Jul 2022
ミニバッチサイズ? なにそれ? おいしいの? ⇒ なるほどわかりました (キリッ)
  • readall関数:augmentedImageDatastore から全てのデータを読み取る
  • read関数:augmentedImageDatastore からMiniBatchSize分のデータを読み取る
MiniBatchSize をNumObservationsと同じ数にしてread関数を使うのはreadall関数を使うのと同じ事で、データ数が膨大な場合エラーになる事が想定されます。その為のread関数で分割するんですね。その際、読み込んだブロック数を管理するhasdata関数を使います。
imds = imageDatastore(fullfile(matlabroot,"toolbox","matlab"),"IncludeSubfolders",true,"FileExtensions",".tif","LabelSource","foldernames");
xtrainimg = augmentedImageDatastore([128 128],imds,'ColorPreprocessing','rgb2gray'); % サンプルのimageDatastoreデータ
ytraining = [];
while hasdata(xtrainimg)
data = read(xtrainimg);
ytraining = [ytraining; data.response];
end
ytraining
ytraining = 2×1 categorical array
demos imagesci
Atsushi Ueno
Atsushi Ueno on 2 Jul 2022
>ミニバッチサイズを変更したら解決しますか?
NOの方が適する回答だと思います。ミニバッチサイズを十分に大きくすればread関数でも全てのデータを読み取る事が出来ますが、readall関数があるのでその必要はありません。それに、全ての情報を一度に読み込むとメモリ不足でエラーになる事が想定されます。その為のデータストアなのですから。
>正しいミニバッチサイズの変更の仕方をご教授してほしいです。
単にxtrainimg.MiniBatchSize = ***とすれば変更可能です。MiniBatchSize に記載があるように「学習、予測、および分類では、trainingOptions で定義された MiniBatchSize に設定なる」様です。
imds = imageDatastore(fullfile(matlabroot,"toolbox","matlab"),"IncludeSubfolders",true,"FileExtensions",".tif","LabelSource","foldernames");
xtrainimg = augmentedImageDatastore([128 128],imds,'ColorPreprocessing','rgb2gray'); % サンプルのimageDatastoreデータ
xtrainimg.MiniBatchSize = 1
xtrainimg =
augmentedImageDatastore with properties: NumObservations: 2 Files: {2×1 cell} AlternateFileSystemRoots: {} MiniBatchSize: 1 DataAugmentation: 'none' ColorPreprocessing: 'rgb2gray' OutputSize: [128 128] OutputSizeMode: 'resize' DispatchInBackground: 0

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!