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

3 ビュー (過去 30 日間)
takmakome
takmakome 2022 年 7 月 1 日
コメント済み: Atsushi Ueno 2022 年 7 月 2 日
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;
したいことは画像の名前と画像を紐づけしたいということです。 

採用された回答

Atsushi Ueno
Atsushi Ueno 2022 年 7 月 1 日
編集済み: Atsushi Ueno 2022 年 7 月 2 日
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 件のコメント
Atsushi Ueno
Atsushi Ueno 2022 年 7 月 2 日
ミニバッチサイズ? なにそれ? おいしいの? ⇒ なるほどわかりました (キリッ)
  • 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 2022 年 7 月 2 日
>ミニバッチサイズを変更したら解決しますか?
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!