필터 지우기
필터 지우기

fixing an error about the number of channels in Yolov2

조회 수: 26 (최근 30일)
Sunghwan Jung
Sunghwan Jung 2022년 3월 29일
댓글: Vivek Akkala 2023년 6월 12일
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