Problem in YOLOv2 training

조회 수: 8 (최근 30일)
Guilherme Franklin
Guilherme Franklin 2022년 5월 31일
답변: Vivek Akkala 2022년 6월 6일
I'm doing a YOLOv2 training and I came across the following error:
Error using
trainYOLOv2ObjectDetector>iParseInputsYolov2
(line 240)
Invalid network.
Error in
trainYOLOv2ObjectDetector
(line 174)
[trainingData, lgraph,
params, options] =
iParseInputsYolov2(...
Error in criando (line 13)
[detector,info] =
trainYOLOv2ObjectDetector(ds,lgraph,options);
Caused by:
Network: The input to
the YOLO v2 transform
layer must have 12
channels to support 2
anchor boxes and 1
classes. The number of
channels must equal
numAnchors * (5 +
numClasses). Update the
training data, the
number of anchor boxes
specified in the
yolov2Transform layer,
or the layers preceding
the transform layer.
My code:
clear, clc, close all;
vagem = load('RotulosVagem.mat');
lgraph = load('lgraph.mat');
lgraph = lgraph.lgraph;
gTruth = vagem.gTruth;
[imds, blds] = objectDetectorTrainingData(gTruth);
ds = combine(imds, blds);
options = trainingOptions('sgdm');
[detector,info] = trainYOLOv2ObjectDetector(ds,lgraph,options);
I will attach the files. Thanks in advance.

답변 (1개)

Vivek Akkala
Vivek Akkala 2022년 6월 6일
Hi,
There seems to be a mismatch between expected inputs and actual inputs to the yolov2TransformLayer. Based on the "RotulosVagem.mat" and "lgraph" provided by you, I assume you want to train a YOLO v2 network with 2 anchor boxes for 1 class.
For this, the last convolutional layer before yolov2TransformLayer in the "lgraph" must have 12 output filters but the current network is having 20 filters.
The issue can be resolved by updating the output filters of the last convolutional layer. You can try the following code:
lgraph = lgraph.lgraph;
[imds, blds] = objectDetectorTrainingData(gTruth);
ds = combine(imds, blds);
options = trainingOptions('sgdm');
% % Start of the code to be added %%
numClasses= size(vagem.gTruth.LabelData,2);
numAnchorBoxes = size(lgraph.Layers(end,1).AnchorBoxes,1);
outFilters = (5+numClasses).*numAnchorBoxes;
yolov2ConvLayer = convolution2dLayer(3,outFilters,'Name','yolov2ConvUpdated',...
'Padding', 'same',...
'WeightsInitializer',@(sz)randn(sz)*0.01);
yolov2ConvLayer.Bias = zeros(1,1,outFilters);
lgraph = replaceLayer(lgraph,'yolov2ClassConv',yolov2ConvLayer);
% % End of the code to be added %%
[detector,info] = trainYOLOv2ObjectDetector(ds,lgraph,options);

카테고리

Help CenterFile Exchange에서 Recognition, Object Detection, and Semantic Segmentation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by