Error: Out of memory

2 次查看(过去 30 天)
Monika Zikmundová
Hello,
I am writing a faster r-cnn network script to search for craters. When you run the script, matlab generates an out-of-memory error message. Can someone please advise me how to solve this problem?
My matlab code:
clear all
close all
clc
format long g
data=load('matlab_V21_ROI_11_3_2021.mat')
gTruth=data.gTruth;
gTruth.DataSource
gTruth.LabelDefinitions;
replaceimds=imageDatastore('C:\monika\vse\kratery')
replaceDataSource=groundTruthDataSource(replaceimds)
gTruth.DataSource=replaceDataSource
%objectdetector
trainingDataTable=objectDetectorTrainingData(gTruth);
% [imds,blds]=objectDetectorTrainingData(gTruth);
% cds=combine(imds,blds)
% read(cds)
% counts=countEachLabel(cds)
filenamesImages=trainingDataTable.imageFilename
tblBoxes=trainingDataTable(:,'krater')
imds=imageDatastore(filenamesImages, 'LabelSource','foldernames')
blds=boxLabelDatastore(tblBoxes)
cds=combine(imds,blds)
%prevod na RGB
numberofImages=length(imds.Files)
for k=1:numberofImages
inputFileName=imds.Files{k};
fprintf('Checking %s\n', inputFileName);
grayImage=imread(inputFileName);
[rows,columns,numberofColorChannels]=size(grayImage);
if numberofColorChannels == 1
rgbImage=cat(3,grayImage, grayImage, grayImage);
imshow(rgbImage);
else
imshow(rgbImage);
end
axis('on','image');
%pause(0.1);
end
% anchor boxes I
network = resnet50;%squeezenet; % resnet50
inputImageSize =[224 224 3]; %network.Layers(1).InputSize;
% image augmenter
imageAugmenter=imageDataAugmenter(...
'RandRotation',[0 90],...
'RandScale',[0.5 1]);
augmentedImdsTrain=augmentedImageDatastore(inputImageSize,imds,'DataAugmentation',imageAugmenter,'OutputSizeMode','randcrop'); % ořiznutí z náhodného umístění ve vstupním obrázku
%preprocessedTrainingData=transform(cds,@(data)preprocessData(data,inputImageSize));
numClasses = 1;
featureLayer = 'activation_40_relu';%'fire5-concat' %'activation_40_relu';
%estimate anchor boxes
numAnchors = 3
[anchorBoxes,meanIoU] = estimateAnchorBoxes(cds,numAnchors);
anchorBoxes
meanIoU
maxNumAnchors = 3;
meanIoU = zeros([maxNumAnchors,1]);
anchorBoxes = cell(maxNumAnchors, 1);
for k = 1:maxNumAnchors
% Estimate anchors and mean IoU.
[anchorBoxes{k},meanIoU(k)] = estimateAnchorBoxes(cds,k);
end
figure
plot(1:maxNumAnchors,meanIoU,'-o')
ylabel("Mean IoU")
xlabel("Number of Anchors")
title("Number of Anchors vs. Mean IoU")
% anchor boxes - pokracovani
anchorBoxes = [72,70; 99,96; 53,51];
lgraph = fasterRCNNLayers(inputImageSize,numClasses,anchorBoxes, ...
network,featureLayer);
analyzeNetwork(lgraph);
options = trainingOptions ( 'sgdm' , ...
'MiniBatchSize' , 1, ...
'InitialLearnRate' , 1e-3, ...
'MaxEpochs' , 5);
detector = trainFasterRCNNObjectDetector (cds, lgraph, options, ...
'NegativeOverlapRange' , [0 0.3], ...
'PositiveOverlapRange' , [0.6 1]);

回答(1 个)

Srivardhan Gadila
If your network is being trained on GPU then it seems that the gpu memory is not sufficient and you can set the 'ExecutionEnvironment' to 'cpu' in the trainingOptions and try training the network. Alternatively you can also check the Tips section of the trainFasterRCNNObjectDetector about the possible workarounds suggested for "out-of-memory" issues.
You can refer to the following MATLAB Answer as well: Why do I run into 'Out of memory' error using Faster R-CNN method?
If neither of the above suggestions work then you can contact Mathworks Support.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by