Filter löschen
Filter löschen

Problem in YOLOv2 training

8 Ansichten (letzte 30 Tage)
Guilherme Franklin
Guilherme Franklin am 31 Mai 2022
Kommentiert: Abhilasha am 3 Mai 2024
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.

Antworten (1)

Vivek Akkala
Vivek Akkala am 6 Jun. 2022
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);
  1 Kommentar
Abhilasha
Abhilasha am 3 Mai 2024
I am writing this code:
data = load('annotated_img.mat');
trainingData = gTruth1;
dataDir = fullfile("Filtered_Combined_Images");
trainingData.imageFilename = fullfile(trainingData.imageFilename);
rng(0); % Set random seed for reproducibility
shuffledIdx = randperm(height(trainingData));
trainingData = trainingData(shuffledIdx,:);
imds = imageDatastore(trainingData.imageFilename);
blds = boxLabelDatastore(trainingData(:,2:end))
dp = combine(imds, blds);
net = load('lgraph.mat');
lgraph = net.lgraph;
analyzeNetwork(lgraph);
lgraph.Layers
options = trainingOptions('sgdm', ...
'InitialLearnRate', 0.001, ...
'Verbose', true, ...
'MiniBatchSize', 16, ...
'MaxEpochs', 200,...
'Shuffle', 'never', ...
'VerboseFrequency', 20, ...
'CheckpointPath', tempdir);
[detector, info] = trainYOLOv2ObjectDetector(dp, lgraph, options);
and I am getting this error:
Network: The input to the YOLO v2 transform layer must have 168 channels to support 8 anchor boxes and 16 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Recognition, Object Detection, and Semantic Segmentation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by