Calling the set of images in subfolder from augmented image datastore

3 ビュー (過去 30 日間)
Rd
Rd 2020 年 10 月 30 日
コメント済み: Manoj Kumar Sharma 2022 年 9 月 16 日
I have the database contain 180 images in per subfolder. I have 10 subfolder. I have to assign first 60 images in each subfolder to XTrain1, next 60 images in each subfolder to XTrain2, next 60 images in each subfolder to XTrain3.
i have included my code here. Kindly help me to loop the folders.
imagefolder = 'C:\Users\manjurama\Desktop\study\PG\PROJECT\Finger vein database multiple copy\database_10';
imds = imageDatastore(imagefolder,'IncludeSubfolders',true,'LabelSource','foldernames');
numTrainFiles = 0.75;
imageSize = [227 227];
[XTrain,YTrain] = splitEachLabel(imds, numTrainFiles,'randomize');
XTrain = augmentedImageDatastore(imageSize,XTrain);
YTrain = augmentedImageDatastore(imageSize,YTrain);
XTrain1=XTrain(1:60);
XTrain2=XTrain(61:120);
XTrain3=XTrain(121:180);

回答 (1 件)

drummer
drummer 2020 年 10 月 30 日
編集済み: drummer 2020 年 10 月 30 日
By your last three lines, you can do the following:
Xtrain1 = XTrain.Files(1:60);
XTrain2 = XTrain.Files(61:120);
XTrain3 = XTrain.Files(121:160);
As you see, you're taking advantage of the augmentedImageDataStore properties. The Files, specifically. You can check them by typing your augmented variable in the command window:
>> XTrain
This is a workaround. You should work on getting each of your training files from different folders at different indexes as you mentioned.
Cheers
  6 件のコメント
Rd
Rd 2020 年 11 月 11 日
Dear drummer,
As you mentioned before, i split my imagefolder into training and testing image like
trainingSetFolder/class1
trainingSetFolder/class2
.
.
.
trainingSetFolder/class10
This is the code i have used
imagefolder = 'C:\Users\manjurama\Desktop\training and testing\Training';
XTrain = imageDatastore(imagefolder,'IncludeSubfolders',true,'LabelSource','foldernames');
[XTrain1,XTrain2,XTrain3] = splitEachLabel(XTrain, 0.33,0.33, 0.33, "randomized");
YTrain = XTrain1.Labels;
the database is splitted. But the issue is i couldn't assign the folder name as label.
While using the above code, file name as assigned as labels. hence it shows 180 labels.
i need to the labels(=YTrain) as class1, class2,....class10.
Kindly help me to solve this issue. Thanks.
Manoj Kumar Sharma
Manoj Kumar Sharma 2022 年 9 月 16 日
Use this code:
YTrain=XTrain.Labels;

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

Community Treasure Hunt

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

Start Hunting!

Translated by