split Each Data store

3 次查看(过去 30 天)
shehryar shuaib
shehryar shuaib 2019-12-9
回答: Lokesh 2024-4-25
How we can Split Each data store while training neural network with not disturbing the sequence of Images and labels so that it can train images and corresponding labels accordingly.
Thanks in advance.

回答(1 个)

Lokesh
Lokesh 2024-4-25
Hi shehryar,
It is my understanding that you would like to split datastore maintaining the alignment of images and their corresponding labels.
This can be efficiently achieved in MATLAB using the 'splitEachLabel' method. This method ensures that the split is done maintaining the correspondence between images and labels, and allows you to specify the proportion of data you want in each set. To split the datastore into training and validation sets, where 70% is designated for training and 30% for validation, you can use the following code:
[imdsTrain, imdsValidation] = splitEachLabel(imds, 0.7);
For sequential data where the order and sequence are crucial, consider manually dividing the dataset while keeping track of indices. You can then create new imageDatastore objects for training and validation sets using subsets of the original datastore:
% Calculate the number of images for training
numTrainFiles = floor(0.7 * numel(imds.Files));
% Manually create training and validation datastores
imdsTrain = imageDatastore(imds.Files(1:numTrainFiles), 'Labels', imds.Labels(1:numTrainFiles));
imdsValidation = imageDatastore(imds.Files(numTrainFiles+1:end), 'Labels', imds.Labels(numTrainFiles+1:end));
Refer to the following documentation for more information on 'splitEachLabel':

Community Treasure Hunt

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

Start Hunting!

Translated by