FastRCNNによる物体検出時のout of memory エラー

1 回表示 (過去 30 日間)
- Tei
- Tei 2017 年 12 月 13 日
回答済み: michio 2017 年 12 月 14 日
以下のプログラムでFastRCNNを用いた物体検出を行う際、detectでout of memoryエラーが起きてしまいます。
%%Load a pre-trained, deep, convolutional network
net = alexnet;
layersfirst = net.Layers
%%Delete Full Connected Layer
layersTransfer = layersfirst(1:end-3)
objectClasses = {'cars','truck','bus'};
numClassesPlusBackground = numel(objectClasses) + 1;
%%layers
layers = [layersTransfer
fullyConnectedLayer(numClassesPlusBackground,'WeightLearnRateFactor',20,'BiasLearnRateFactor',20)
softmaxLayer
classificationLayer]
%%RCNN
load ('CARSRCNN.mat')
opts = trainingOptions('sgdm', 'InitialLearnRate', 0.00001, 'MaxEpochs', 3, 'MiniBatchSize', 32);
rcnn = trainFastRCNNObjectDetector(CARSRCNN,layers,opts,'NegativeOverlapRange',[0 0.4],'SmallestImageDimension',600)
%%TEST
imDir = fullfile(matlabroot,'ImageData','rcnn1');
addpath(imDir);
img = imread('TEST.jpg');
[bboxes,score,label] = detect(rcnn,img);
detectedImg = insertObjectAnnotation(img, 'Rectangle', bboxes, cellstr(label));
figure
imshow(detectedImg)
rmpath(imDir);
matlabのバージョンはR2017a,GPUは GTX 1060 6GB,エラーメッセージは以下のようになります
エラー: visiongpuROIMaxPoolingForward
GPU 実装に失敗しました。
out of memory。
エラー: vision.internal.cnn.layer.util.ROIMaxPooling2DGPUStrategy/forward (line 16)
Z = visiongpuROIMaxPoolingForward(X, double(roiTransposed), gridSize(1), gridSize(2));
エラー: vision.internal.cnn.layer.ROIMaxPooling2DLayer/forward (line 48)
[Z, memory] = this.ExecutionStrategy.forward(X, roi, this.GridSize);
エラー: vision.internal.cnn.internalFastRCNNSeriesNetwork/activations (line 82)
roioutput = this.Layers{roiPoolingLayer}.forward( output, roi);
エラー: vision.cnn.FastRCNN/activations (line 250)
YChannelFormat = predictNetwork.activations(X, roi, layerID, inputLayerID);
エラー: fastRCNNObjectDetector/detect (line 462)
fmap = activations(this.Network, Iroi, scaledBBoxes, numel(this.Network.Layers), 1, ...
エラー: FastRCNN (line 35)
[bboxes,score,label] = detect(rcnn,img);
どうかよろしくお願いします

採用された回答

michio
michio 2017 年 12 月 14 日
Fast/Faster R-CNN は、画像全体から大きな Feature Map を生成するので、GPU のメモリを大量に消費します。もう既に使われていますが、SmallestImageDimension というパラメータを設定すると、学習時に画像のサイズをリサイズして、小さくするようにするので、メモリの消費を抑えることができます。
今回のエラーは detect の実行時ですね。メモリの問題はなかなか本質的な解決は難しいですが、、たとえば
img = imread('TEST.jpg');
で読み込まれている画像を、多少小さいサイズにして実行してみるといかがでしょうか。たとえば
img = imresize(img, 0.8);
を imread の後に実行して画像を小さくした上で detect を実行。
後、、効果があるかは未知数ではありますが、学習を完了した後に一旦 GPUのリセットを試してみたいですね。
reset(gpuDevice)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!