How to randomize the order of training images of a CNN?
5 次查看(过去 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/362020/image.png)
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
0 个评论
采纳的回答
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');
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!