How to randomize the order of training images of a CNN?

조회 수: 2 (최근 30일)
Dear masters of Matlab,
I am training a Convolutional Neural Network (CNN). and I cannot change the order of the images in the training set. Let's see if I can explain the problem.
  • 1. About the training set
The training set is given so that the folders are the classes to be used:
Train_imds = imageDatastore(fullfile(TrainFolder, categories), ...
'LabelSource', 'foldernames');
It gives the next structure:
I have 56341 images to train 10 classes.
The images are order by each class. All the images of class "A" are in first position, secondly the images of class "B" all together, etc. I would like to randomize these order.
  • 2. Effect of this order in the training
When I run trainNetwork, each iteration takes part of these images until every image has "passed through" the net. Some iterations will be training only one class before the next class begins. I would like to randomize this order so that becomes more probable that every class trains each iteration.
  • 3. Failed attempts
If I change Folders{} , the Labels{} change to empty.
If I make a copy so that I can change the structure, both structures change.
Any help will be welcomed. Thanks a lot

채택된 답변

Mohammad Sami
Mohammad Sami 2020년 9월 18일
편집: Mohammad Sami 2020년 9월 18일
if isShuffleable(Train_imds)
newds = shuffle(Train_imds);
disp('Shuffling successful.')
else
disp('Datastore is not shuffleable.')
end
A second option is to enable shuffling in the training options.
solverName = 'sgdm'; % choose your solver
options = trainingOptions(solverName,'Shuffle','every-epoch');
  댓글 수: 1
Jaime Almonacid-Caballer
Jaime Almonacid-Caballer 2020년 9월 18일
Thanks a lot,
It was in front of me and I did not see it.
Kind regards,

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

추가 답변 (0개)

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by