Poor performance of Yolov2 network
3 次查看(过去 30 天)
显示 更早的评论
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',...
'WeightsInitializer','narrow-normal')
batchNormalizationLayer('Name','BN1')
reluLayer('Name','relu_1')
maxPooling2dLayer(2, 'Stride',2,'Name','maxpool1')
convolution2dLayer(filterSize, 32, 'Padding', 1,'Name', 'conv_2',...
'WeightsInitializer','narrow-normal')
batchNormalizationLayer('Name','BN2')
reluLayer('Name','relu_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');
analyzeNetwork(lgraph);
doTraining = true;
% setting this flag to true will build and train a YOLOv2 detector
% false will load a pre-trained network
if doTraining
rng(0);
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.001, ...
'Verbose',true,'MiniBatchSize',16,'MaxEpochs',80,...
'Shuffle','every-epoch','VerboseFrequency',50, ...
'DispatchInBackground',false,...
'ExecutionEnvironment','auto');
[detectorYolo2, info] = trainYOLOv2ObjectDetector(trainingData,lgraph,options);
else
load(fullfile("Utilities","detectorYoloV2.mat")); %pre-trained detector loaded from a MAT file
end
%%
results = table('Size',[height(trainingData) 3],...
'VariableTypes',{'cell','cell','cell'},...
'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)
disp(i)
% 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));
depVideoPlayer(I);
pause(0.1);
end
% Collect the results in the results table
results.Boxes{i} = floor(bboxes);
results.Scores{i} = scores;
results.Labels{i} = labels;
end
0 个评论
回答(2 个)
Aditya Patil
2020-11-16
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.
0 个评论
Abolfazl Chaman Motlagh
2021-8-30
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!