Manually Plotting the graph from R-CNN training parameters

Hi Guys
I have a problem when i want to make a graph for the training phase like between Epoch & Mini-batch Loss
Herein the code
load('gTruth.mat')
smokedetection = selectLabels(gTruth,'car');
if isfolder(fullfile('TrainingData'))
cd TrainingData
else
mkdir TrainingData
end
addpath('TrainingData');
options = trainingOptions('sgdm', ...
'MiniBatchSize', 32, ...
'InitialLearnRate', 1e-6, ...
'MaxEpochs', 10);
layers = [
imageInputLayer([32 32 3],"Name","imageinput")
convolution2dLayer([5 5],32,"Name","conv","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
maxPooling2dLayer([3 3],"Name","maxpool","Stride",[2 2])
reluLayer("Name","relu")
averagePooling2dLayer([3 3],"Name","avgpool","Stride",[2 2])
fullyConnectedLayer(2,"Name","fc_rcnn","BiasL2Factor",1,"BiasLearnRateFactor",10,"WeightLearnRateFactor",20,"WeightsInitializer","narrow-normal")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
trainingData = objectDetectorTrainingData(smokedetection,'SamplingFactor',1,...
'WriteLocation','TrainingData');
detector = trainRCNNObjectDetector(trainingData, layers, options, ...
'NegativeOverlapRange', [0 0.3]);
save('Detector.mat','detector');
[detector,info] = trainRCNNObjectDetector('Epoch','Mini-batch Loss','Training Accuracy','Base Learning Rate','Mini-batch Accuracy');
x = ('Epoch');
y = ('Mini-batch Loss');
figure
plot(x,y)
title('Training Phase')
xlabel('Number of Epochs')
ylabel('Training Loss')
Error
Error using trainRCNNObjectDetector
Expected input number 1, trainingData, to be one of these types:
table
Error in vision.internal.cnn.validation.checkGroundTruth (line 2)
validateattributes(gt, {'table'},{'nonempty'}, name, 'trainingData',1);
Error in trainRCNNObjectDetector>parseInputs (line 311)
vision.internal.cnn.validation.checkGroundTruth(trainingData, fname);
Error in trainRCNNObjectDetector (line 248)
[network, params] = parseInputs(trainingData, network, options, mfilename, varargin{:});
Error in TrainingSmokeDetectionwithRCNN (line 29)
[detector,info] = trainRCNNObjectDetector('Epoch','Mini-batch Loss','Training Accuracy','Base
Learning Rate','Mini-batch Accuracy');

 Risposta accettata

Hi,
The trainingOptions for trainRCNNObjectDetector does not support plotting the train-progress while the training is going on, but the training parameters are returned at the end of training if trainRCNNObjectDetector is used with following arguments.
[detector,info] = trainRCNNObjectDetector(___)
In the script from the question following command looks incorrect,
[detector,info] = trainRCNNObjectDetector('Epoch','Mini-batch Loss','Training Accuracy','Base Learning Rate','Mini-batch Accuracy');
instead the above can be replaced by
[detector,info] = trainRCNNObjectDetector(trainingData, layers, options, 'NegativeOverlapRange', [0 0.3]);
Here info will be returned as a structure which contains the ‘Training Accuracy’, ‘Training Loss’ and ‘Base Learning Rate’ for each iteration. These can be then plotted as per required. The error was there because correct input arguments weren’t passed.

7 Commenti

Hi Raunak Gupta Thanks for your reply just to confirm after i will make [detector,info] = trainRCNNObjectDetector(trainingData, layers, options, 'NegativeOverlapRange', [0 0.3]); can i make plot functrion in the same script / code to plot the required parameters Best
Hi,
Sure, the info object will be a structure that contain fields as I named in above answer. These can be extracted as info.TrainingLoss , info.TrainingAccuracy and can be plotted against iteration number in the same script.
I made this following code but i am still getting error
load('gTruth.mat')
smokedetection = selectLabels(gTruth,'car');
if isfolder(fullfile('TrainingData'))
cd TrainingData
else
mkdir TrainingData
end
addpath('TrainingData');
options = trainingOptions('sgdm', ...
'MiniBatchSize', 32, ...
'InitialLearnRate', 1e-6, ...
'MaxEpochs', 10);
layers = [
imageInputLayer([32 32 3],"Name","imageinput")
convolution2dLayer([5 5],32,"Name","conv","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
maxPooling2dLayer([3 3],"Name","maxpool","Stride",[2 2])
reluLayer("Name","relu")
averagePooling2dLayer([3 3],"Name","avgpool","Stride",[2 2])
fullyConnectedLayer(2,"Name","fc_rcnn","BiasL2Factor",1,"BiasLearnRateFactor",10,"WeightLearnRateFactor",20,"WeightsInitializer","narrow-normal")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
trainingData = objectDetectorTrainingData(smokedetection,'SamplingFactor',1,...
'WriteLocation','TrainingData');
[detector,info] = trainRCNNObjectDetector(trainingData, layers, options, ...
'NegativeOverlapRange', [0 0.3]);
save('Detector.mat','detector');
x = ('Epoch');
y = ('Mini-batch Loss');
figure
plot(x,y)
title('Training Phase')
xlabel('Number of Epochs')
ylabel('Training Loss')
Error using plot
Invalid first data argument.
Error in TrainingSmokeDetectionwithRCNN (line 33)
plot(x,y)
Hi,
You may replace the code from x,y to the following. It will work.
% For Training Loss
x = 1:size(info.TrainingLoss,2);
y = info.TrainingLoss;
figure
plot(x,y)
title('Training Phase')
xlabel('Iteration')
ylabel('Mini Batch Training Loss')
% Similarly for Training Accuracy
x = 1:size(info.TrainingAccuracy,2);
y = info.TrainingAccuracy;
figure
plot(x,y)
title('Training Phase')
xlabel('Iteration')
ylabel('Mini Batch Training Accuracy')
Thanks Raunak Gupta
it works successfully much appreciated
Best,
reference to this issue i already plot many graphs even for the example using the RCNN for stop sign by Matlab but i got fluactuation AS SHOWN IN IMAGE is it possible to improve it for the given code?
Training Loss.jpg
Hi,
The loss is calculated for each mini batch that is why the fluctuation is there. You may use smooth to remove too many fluctuations.

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by