How to set the number of iterations in RCNN, Fast RCNN or Faster RCNN?

时间:2017-08-05 10:53:10

标签: matlab neural-network deep-learning object-detection

I have trained R-CNN network models on a custom dataset and got the results as expected in the end. But I couldn't find where to set the number of iterations before starting the train process and the training continues without any sign of when it's going to stop. Is there a way to set the number of iterations beforehand, so it would stop after specified steps?

This is the code of training the rcnn:

%%%%%%%%%%%%%%%%%%%%%% Define Inputs

imagePath = 'D:\Thesis\Data\VEDAI\vedai\train_images\';
sampleImage = '00000000.png';
objectClasses = {'car','truck','tractor','campingcar','van','other', 'pickup', 'boat', 'plane'};
imageTable = vedaiTrain;
smallestObjectSize = [32, 32, 3];

%%%%%%%%%%%%%%%%%%%%%% Calculations

numClassesPlusBackground = numel(objectClasses) + 1;

t = num2cell(smallestObjectSize);
[height, width, numChannels] = deal(t{:});
imageSize = [height width numChannels];

%%%%%%%%%%%%%%%%%%%%%% Network Layers

%%%%% inputLayer
inputLayer = imageInputLayer(imageSize);

%%%%% middleLayer
filterSize = [5 5];
numFilters = 32;

middleLayers = [

convolution2dLayer(filterSize, numFilters, 'Padding', 2)

reluLayer()

maxPooling2dLayer(3, 'Stride', 2)

convolution2dLayer(filterSize, numFilters, 'Padding', 2)
reluLayer()
maxPooling2dLayer(3, 'Stride',2)

convolution2dLayer(filterSize, 2 * numFilters, 'Padding', 2)
reluLayer()
maxPooling2dLayer(3, 'Stride',2)

]

%%%%% finalLayer
finalLayers = [

fullyConnectedLayer(64)

reluLayer

fullyConnectedLayer(numClassesPlusBackground)

softmaxLayer
classificationLayer
]

Layers = [
    inputLayer
    middleLayers
    finalLayers
    ]

layers(2).Weights = 0.0001 * randn([filterSize numChannels numFilters]);

%%%%%%%%%%%%%%%%%%%%%% training options
options = trainingOptions('sgdm', ...
    'Momentum', 0.9, ...
    'InitialLearnRate', 0.001, ...
    'LearnRateSchedule', 'piecewise', ...
    'LearnRateDropFactor', 0.1, ...
    'LearnRateDropPeriod', 8, ...
    'L2Regularization', 0.004, ...
    'MaxEpochs', 40, ...
    'MiniBatchSize', 128, ...
    'Verbose', true);

%%%%%%%%%%%%%%%%%%%%%% Train an R-CNN object detector
rcnn = trainRCNNObjectDetector(imageTable,Layers, options, ...
'NegativeOverlapRange', [0 0.3], 'PositiveOverlapRange',[0.5 1]);

It keeps training for iterations until some time, which I don't know how it decides.

1 个答案:

答案 0 :(得分:1)

在文件train_faster_rcnn_alt_opt.py文件中,将max_iters = [80000, 40000, 80000, 40000]参数设置为每个阶段所需的迭代次数。