Poor performance of Yolov2 network

6 views (last 30 days)
Justus Rooker
Justus Rooker on 10 Nov 2020
I am training a yolov2 network two identify 2 images, built from the ground up and after training the network for 560 iterations, I have no detection when running
[bboxes,scores,labels] = detect(detectorYolo2,I);
The code I am using is below. Let me know if there is any particular reason for my useless network. I only have 120 images with about 50/50 labeled images of each catagory(2 catagories)
trainingData = gTruth;
imds = imageDatastore(trainingData.imageFilename);
blds = boxLabelDatastore(trainingData(:,2:end));
ds = combine(imds, blds);
inputLayer = imageInputLayer([329 500 1],'Name','input','Normalization','none');
filterSize = [3 3];
middleLayers = [
convolution2dLayer(filterSize, 16, 'Padding', 1,'Name','conv_1',...
maxPooling2dLayer(2, 'Stride',2,'Name','maxpool1')
convolution2dLayer(filterSize, 32, 'Padding', 1,'Name', 'conv_2',...
lgraph = layerGraph([inputLayer; middleLayers]);
numClasses = size(trainingData,2)-1
numClasses = 2;
Anchors = [16 12
32 12
60 32]
lgraph = yolov2Layers([329 500 1],numClasses,Anchors,lgraph,'relu_2');
doTraining = true;
% setting this flag to true will build and train a YOLOv2 detector
% false will load a pre-trained network
if doTraining
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.001, ...
'Shuffle','every-epoch','VerboseFrequency',50, ...
[detectorYolo2, info] = trainYOLOv2ObjectDetector(trainingData,lgraph,options);
load(fullfile("Utilities","detectorYoloV2.mat")); %pre-trained detector loaded from a MAT file
results = table('Size',[height(trainingData) 3],...
'VariableNames',{'Boxes','Scores', 'Labels'})
%Initialize a Deployable Videl Player to view the image stream
depVideoPlayer = vision.DeployableVideoPlayer;
%Loop through all the images in the Validation set
for i = 1:height(trainingData)
% Read the image
I = imread(trainingData.imageFilename{i});
% Run the detector.
[bboxes,scores,labels] = detect(detectorYolo2,I);
if ~isempty(bboxes)
I = insertObjectAnnotation(I,'Rectangle',bboxes,cellstr(labels));
% Collect the results in the results table
results.Boxes{i} = floor(bboxes);
results.Scores{i} = scores;
results.Labels{i} = labels;

Answers (2)

Aditya Patil
Aditya Patil on 16 Nov 2020
120 images is very low for neural networks. You can consider fine tuning/transfer learning on pretrained Yolov2. Alternately, consider using any of the other machine learning algorithms available in MATLAB.

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh on 30 Aug 2021
beside your insufficient dataset mentioned by Aditya Patil.
  • maybe try to set 'LearnRateSchedule' on 'piecewise', and drop LearnRate during training. i think 1e-3 isn't best choice for initial LearnRate in sgdm (matlab default is 1e-2). and as my experiences for good convergence you should at least endup 1e-4 for LearnRate. Initial LearnRate is very important here because you didn't use any pretrained network and network weights are just initialized irrelevant to your problem.
  • also if you don't mind, i recommend you to use adam instead of sgdm.
  • and of course your network is very shallow for learning hard phenomena, you just use 2 conv layer with 3x3 filter size
  • and finally if you can ,use pretrained model for fine-tunning. it really help for convergence of model. (as Aditya Patil suggest)
i add this answer to ensure you that however your dataset is inadequate for true usage of deep learning, i get relatively good answer from yolov2 in matlab even with fewer dataset!

Community Treasure Hunt

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

Start Hunting!

Translated by