Problem in YOLOv2 training
    조회 수: 9 (최근 30일)
  
       이전 댓글 표시
    
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.
댓글 수: 0
답변 (1개)
  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);
댓글 수: 1
  Abhilasha
 2024년 5월 3일
				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.
참고 항목
카테고리
				Help Center 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


