Here is my code.
Please....
Thank you~!
inputLayer = imageInputLayer([227 227 3]);
middleLayers = [
convolution2dLayer([11 11], 96,'stride',4, 'Padding', 0, 'NumChannels',3 )
reluLayer()
crossChannelNormalizationLayer(5)
maxPooling2dLayer(3,'stride',2, 'Padding',0)
convolution2dLayer([5 5], 256,'stride',1, 'Padding', 2, 'NumChannels',96)
reluLayer()
crossChannelNormalizationLayer(5)
maxPooling2dLayer(3,'stride',2, 'Padding',0)
convolution2dLayer([3 3], 384,'stride',1, 'Padding', 1,'NumChannels',256)
reluLayer()
convolution2dLayer([3 3], 384,'stride',1, 'Padding', 1, 'NumChannels',384)
reluLayer()
convolution2dLayer([3 3], 256,'stride',1, 'Padding', 1,'NumChannels',384)
reluLayer()
maxPooling2dLayer(3,'stride',2, 'Padding',0)
];
finalLayers = [
% Add a fully connected layer with 64 output neurons. The output size
% of this layer will be an array with a length of 64.
fullyConnectedLayer(4096)
reluLayer()
dropoutLayer(0.5)
fullyConnectedLayer(4096)
reluLayer()
dropoutLayer(0.5)
fullyConnectedLayer(width(Dataset))
% Add the softmax loss layer and classification layer.
softmaxLayer()
classificationLayer()
];
layers = [
inputLayer
middleLayers
finalLayers
]
optionsStage1 = trainingOptions('sgdm', ...
'MiniBatchSize', 4, ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-5, ...
'CheckpointPath', tempdir);
% Options for step 2
optionsStage2 = trainingOptions('sgdm', ...
'MiniBatchSize', 4, ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-5, ...
'CheckpointPath', tempdir);
% Options for step 3.
optionsStage3 = trainingOptions('sgdm', ...
'MiniBatchSize', 4, ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-6, ...
'CheckpointPath', tempdir);
% Options for step 4.
optionsStage4 = trainingOptions('sgdm', ...
'MiniBatchSize', 4, ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-6, ...
'CheckpointPath', tempdir);
options = [
optionsStage1
optionsStage2
optionsStage3
optionsStage4
];
tic
% A trained network is loaded from disk to save time when running the
% example. Set this flag to true to train the network.
doTrainingAndEval = true %false;
if doTrainingAndEval
% Set random seed to ensure example training reproducibility.
rng(0);
% Train Faster R-CNN detector. Select a BoxPyramidScale of 1.2 to allow
% for finer resolution for multiscale object detection.
detector = trainFasterRCNNObjectDetector(trainingData, layers, options, ...
'NegativeOverlapRange', [0 0.3], ...
'PositiveOverlapRange', [0.6 1], ...
'SmallestImageDimension', [400], ...
'BoxPyramidScale', 1.2);
else
% 'NumStrongestRegions', 500, ...
% 'MinBoxSizes', [21 21], ...
% Load pretrained detector for the example.
detector = data.detector;
end
toc