MATLAB Answers

why my training yolov2 network can't work?

조회 수: 13(최근 30일)
cui 2 Aug 2019
댓글: cui 27 Mar 2020
I trained my data set according to the official documentation, detecting people in the image, only one category. The pre-training network also uses resnet50. The network structure is consistent with the example, but after many trainings, people are still not detected. During this time I tried to use the clustering algorithm to change the size or number of the achor box, the value of MaxEpochs, but still not working. Why is this?
I post my code and data here:
%% 利用resnet50预训练网络进行特征提取
% Define the image input size.
ImageWeight = 320;
ImageHeight = 320;
imageSize = [ImageWeight ImageHeight 3];
% Define the number of object classes to detect.
numClasses = 1;
anchorBoxes = [
176 67
150 52
113 42
271 99
99 34
]; % .*ImageWeight/1280
anchorBoxes = round(anchorBoxes);
baseNetwork = resnet50();
% Specify the feature extraction layer.
featureLayer = 'activation_40_relu'; % mobilenetv2 的是'global_average_pooling2d_1';
% Create the YOLO v2 object detection network.
lgraph = yolov2Layers(imageSize,numClasses,anchorBoxes,baseNetwork,featureLayer);
if doTraining
% Configure the training options.
% * Lower the learning rate to 1e-3 to stabilize training.
% * Set CheckpointPath to save detector checkpoints to a temporary
% location. If training is interrupted due to a system failure or
% power outage, you can resume training from the saved checkpoint.
options = trainingOptions('sgdm', ...
'MiniBatchSize', 24, ....
'InitialLearnRate',1e-3, ...
'Verbose',1, ...
'CheckpointPath', './save', ...
% Train YOLO v2 detector.
% pretrained = load('save/yolov2_checkpoint__45__2019_08_02__16_44_13.mat');
% detector = pretrained.detector;
[detector,info] = trainYOLOv2ObjectDetector(gTruthPerson,lgraph,options);
save yoloDetector.mat detector info
% Load pretrained detector for the example.
pretrained = load('yoloDetector.mat');
detector = pretrained.detector;
info =;
%% test
for i = 1:height(gTruthPerson)
I = imread(gTruthPerson.imageFilename{i});
% I = imresize(I,imageSize(1:2));
% Run the detector.
[bboxes,scores] = detect(detector,I);
% Annotate detections in the image.
if ~isempty(bboxes)
I = insertObjectAnnotation(I,'rectangle',bboxes,scores);
all images and annotation files is here: google drive

  댓글 수: 0

댓글을 달려면 로그인하십시오.


Song Decn
Song Decn 14 Mar 2020
I have same issue with the detector. any updates?

  댓글 수: 3

Soukali Khiereddine
Soukali Khiereddine 15 Mar 2020
Me to, I have similar problem
enrico campo
enrico campo 20 Mar 2020
same problem
cui 27 Mar 2020
From this example, it can be seen that for users, it is very inflexible to watch the internal network. There is a problem there and it is difficult to debug. The official just gives a "yolov2Layers" or "yolov2OutputLayer", so that users cannot understand the design in principle. !!!
The official example is a very common and simple scenario, which cannot be consistent with the actual application!

댓글을 달려면 로그인하십시오.




Community Treasure Hunt

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

Start Hunting!

Translated by