fixing an error about the number of channels in Yolov2

26 次查看(过去 30 天)
I got this code working with one class from imageLabeler. But, I got errors when I tried 2 or 3 classes. It says " Network: The input to the YOLO v2 transform layer must have 28 channels to support 4 anchor boxes and 2 classes."
vehicleDetector = load('yolov2VehicleDetector.mat');
lgraph = vehicleDetector.lgraph;
[imds,bxds] = objectDetectorTrainingData(gTruth);
cds = combine(imds,bxds);
options = trainingOptions('sgdm', ...
'InitialLearnRate', 0.001, ...
'Verbose',true, ...
'MiniBatchSize',2, ...
'MaxEpochs',30, ...
'Shuffle','every-epoch', ...
'VerboseFrequency',10);
[detector,info] = trainYOLOv2ObjectDetector(cds,lgraph,options);
Error using trainYOLOv2ObjectDetector>iParseInputsYolov2
Invalid network.
Error in trainYOLOv2ObjectDetector (line 209)
[trainingData, lgraph, params, options] = iParseInputsYolov2(...
Caused by:
Network: The input to the YOLO v2 transform layer must have 28 channels to support
4 anchor boxes and 2 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.
Could you let me know how to fix the error? I appreciate your help.

回答(1 个)

Vivek Akkala
Vivek Akkala 2022-6-9
Hi,
The error is due to a mismatch between expected inputs and actual inputs to the yolov2TransformLayer. Based on the error message, I assume you want to train a YOLO v2 network with 4 anchor boxes for 2 classes.
To do so, the last convolutional layer before yolov2TransformLayer in the "lgraph" must have 28 output filters.
The issue can be resolved by updating the output filters of the last convolutional layer. You can try the following code to resolve the issue:
numClasses= 2;
numAnchorBoxes = 4;
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);
  2 个评论
Mukesh Singh
Mukesh Singh 2023-6-11
Network: The input to the YOLO v2 transform layer must have 24 channels to support 4 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.
i am getting the same error . i have 4 class to detect. i have checked that in my previous layer it is passing 36 channels. still the error throughs like this
Vivek Akkala
Vivek Akkala 2023-6-12
Hi,
The error message says that you have 1 class to detect but you claim to have 4 classes. Enusre your groundTruth object/ groundTruth table has all the 4 classes. Update the numClasses in the above soultion to 4.
Also replce the existing yolov4TransformLayer in the network with a new yolov4TransformLayer if the yolov4TransformLayer.NumAnchorBoxes is not 4.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by