Out of memory while training

조회 수: 5(최근 30일)
Ömer Faruk Kurular
Ömer Faruk Kurular 2019년 11월 17일
답변: Gaurav Garg 2019년 11월 20일
layers = [ ...
imageInputLayer([768 1024 3])
options = trainingOptions('sgdm', ...
'InitialLearnRate',1e-4, ...
'Verbose',false, ...
imds = imageDatastore('datasets/train', ...
'IncludeSubfolders',true, ...
inputSize = [768 1024];
imds.ReadFcn = @(loc)imresize(imread(loc),inputSize);
numTrainingFiles = 51;
[imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles,'randomize');
net = trainNetwork(imdsTrain,layers,options);
I have the code above train a model using set of images. I give file location "train" and it contains two subfile which include training images. Problem is that when I start training, it gives out of memory error and it just has 100 image in it. When I train one subfile only, it does it flawlessly. Error may happen because of the following line.
inputSize = [768 1024];
imds.ReadFcn = @(loc)imresize(imread(loc),inputSize);


Gaurav Garg
Gaurav Garg 2019년 11월 20일
Consider using MiniBatchSize and 'ExecutionEnvironment' as arguments in trainingOptions.
Using MiniBatchSize, you can specify the size of mini-batch you wish to use for training. You can try using size as 10 in your case.
Using 'ExecutionEnvironment', you can set the environment to CPU or GPU or auto (to train on a GPU, if available).
You can go through the documentation as well for more information on the trainingOptions function.

Community Treasure Hunt

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

Start Hunting!

Translated by