Calling the set of images in subfolder from augmented image datastore

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월 3일
편집: Rd 2020년 11월 3일
Thank you for your response. But i need to store first 60 images from all the subfolders to XTrain1. Totally XTrain should contain 600 images.
I thought to put for loop.
But i dont know how to call the subfolders. my subfolder names are 001, 002,...,010.
kindly help me to do that.
I wonder you need the ten folders representing the categories, right?
I didn't go through my idea of approach, but why don't you create two parent folders: trainingSet and testingSet.
Then you put your respectively set of 10 folders for each category on each parent folder, and create imds with the parent instance?
Then you do splichEachlabel by using 'LabelSource', 'folderName'.
You will have all your training images splited as you wish.
Let me know if it works.
Cheers
Rd
Rd 2020년 11월 5일
편집: Rd 2020년 11월 5일
Dear drummer,
I have tried as you tell. Also i have included the code that i have used.
close all; clear;
clc;
imagefolder = 'C:\Users\manjurama\Desktop\study\PG\PROJECT\Finger vein database multiple copy\database_10';
imds = imageDatastore(imagefolder,'IncludeSubfolders',true,'LabelSource','foldernames');
numTrainingFiles = 18;
[imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles);
[XTrain11, XTrain21, XTrain31] = splitEachLabel(imdsTrain, 0.333, 0.333, 0.333);
XTrain1 = augmentedImageDatastore([227 227],XTrain11);
XTrain2 = augmentedImageDatastore([227 227],XTrain21);
XTrain3 = augmentedImageDatastore([227 227],XTrain31);
classes = XTrain11.Labels; % retrieve the class information
%classes = categories(YTrain);
numClasses = numel(classes);
But it wont work.
Is there any option to use Exclude the specific files for training in
[imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles,"Exclude", abs(imds.Files)=0);
also let me know how to find the class information. (i.e) i need to store class information in classes.
Kindly help me to do this. Thanks.
So how did you instance your training and testing sets within database_10?
What I had in mind was like this:
yourPath/database_10/trainingSetFolder
and
yourPath/database_10/testing_SetFolder
Both folders would contain your 10 classes classification, respectively for training and testing of course.
So
trainingSetFolder/class1
trainingSetFolder/class2
.
.
.
trainingSetFolder/class10
Then, you would call imds
yourIMDS = imageDataStore(yourPath, 'IncludeSubfolders', true, ...
'LabelSource', 'foldernames');
This way, you wouldn't mind about 1:60; 61:120 and 121: 180 as you have already mannualy separated the training set by the instance aforementioned.
See if it works.
----
Is there any option to use Exclude the specific files for training in
[imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles,"Exclude",(imds.Files)%10==0);
also let me know how to find the class information. (i.e) i need to store class information in classes.
There's always a workaround to do what you want in MATLAB.
Notice that the property Files is a cell array type, and you can call them by using indexes:
imds.Files(1)
imds.Files(2) % and so on...
You can play with the indexes if it is reasonable to work with them. You know your data better than anyone else. You could tell if it is reasonable to approach this way.
Otherwise, if the filename is relevant, than you have to play with the cell arrays. Perhaps transforming them to strings and then, perform strcmp to attend your criteria.
Cheers
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.
Use this code:
YTrain=XTrain.Labels;

댓글을 달려면 로그인하십시오.

질문:

Rd
2020년 10월 30일

댓글:

2022년 9월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by