Error, Detector in YOLO V4

Hello everyone, can you help me? I am using the example "Object Detection Using YOLO v4 Deep Learning" in the document Matlab help, but with a change in the dataset (customs data). when I reach to detector appear the error.
this code :-
detector = yolov4ObjectDetector("csp-darknet53-coco",className1,className2,anchorBoxes,InputSize=inputSize);
this error appear:-
Error using yolov4ObjectDetector/parsePretrainedDetectorInputs
Expected a string scalar or character vector for the parameter name.
Error in yolov4ObjectDetector (line 218)
params = yolov4ObjectDetector.parsePretrainedDetectorInputs(varargin{:});
Error in recognitionThree (line 113)
detector = yolov4ObjectDetector("csp-darknet53-coco",className1,className2,anchorBoxes,InputSize=inputSize);

回答 (2 件)

Walter Roberson
Walter Roberson 2023 年 3 月 6 日

1 投票

detector = yolov4ObjectDetector("csp-darknet53-coco",className1,className2,anchorBoxes,InputSize=inputSize);
So in your call, the name parameter is being passed as "csp-darknet53-coco" . The classes parameter is being passed as className1 . The aboxes parameter is being passed as className2 . Then you get to the anchorBoxes parameter in your call, and since the positional parameter locations have been filled, the code has to match the contents of anchorBoxes to one of the option names. But your anchorBoxes variable is not a character vector or a string array, so you get an error message.
The classes has to be passed as a single parameter, such as {className1, className2}

7 件のコメント

weam
weam 2023 年 3 月 6 日
thank you so much for your explanation, and I am trying to solve the problem with your advices
weam
weam 2023 年 3 月 10 日
when i try to solve the problem by this way yolov4ObjectDetector , Create Custom YOLO v4 Object Detector example.
this code :-
classNames = {'Tool', 'Workpiece'};
basenet = resnet50;
analyzeNetwork(basenet)
basenet.Layers(1)
imageSize = basenet.Layers(1).InputSize;
layerName = basenet.Layers(1).Name;
newinputLayer = imageInputLayer(imageSize,'Normalization','none','Name',layerName);
lgraph = layerGraph(basenet);
lgraph = removeLayers(lgraph,'ClassificationLayer_fc1000');
lgraph = replaceLayer(lgraph,layerName,newinputLayer);
dlnet = dlnetwork(lgraph);
featureExtractionLayers = ["activation_22_relu","activation_40_relu"];
detector = yolov4ObjectDetector(dlnet,classNames,anchorBoxes,DetectionNetworkSource=featureExtractionLayers);
the error :
Error using yolov4ObjectDetector>iConfigureDetector
Number of anchor boxes must match the number of output layers.
Error in yolov4ObjectDetector/parseDetectorInputs (line 917)
lgraph = iConfigureDetector(lgraph,numClasses,params.AnchorBoxes,params.DetectionNetworkSource);
Error in yolov4ObjectDetector (line 224)
params = yolov4ObjectDetector.parseDetectorInputs(varargin{:});
Error in recognitionThree (line 141)
detector = yolov4ObjectDetector(dlnet,classNames,anchorBoxes,DetectionNetworkSource=featureExtractionLayers);
Walter Roberson
Walter Roberson 2023 年 3 月 11 日
You do not show how you built anchorBoxes
weam
weam 2023 年 3 月 12 日
The anchorBoxes :-
anchors = anchors(idx,:);
anchorBoxes = {anchors(1:3,:)
anchors(4:6,:)
anchors(7:9,:)
};
but when i change the anchorBoxes to this, the previos error is disappear, and new error appear:-
anchors = anchors(idx,:);
anchorBoxes = {anchors(1:5,:)
anchors(6:9,:)
};
this new error
Invalid transform function defined on datastore.
The cause of the error was:
Unable to use a value of type cell as an index.
Error in recognitionThree>augmentData (line 231)
bboxes = A{ii,{1,1}};
Error in matlab.io.datastore.TransformedDatastore/applyTransforms (line 723)
data = ds.Transforms{ii}(data);
Error in matlab.io.datastore.TransformedDatastore/read (line 235)
[data, info] = ds.applyTransforms(data, info);
Error in recognitionThree (line 155)
data = read(augmentedTrainingData);
the augmentedTrainingData coded with supported function
augmentedTrainingData = transform(trainingData,@augmentData);
augmentedData = cell(4,1);
for k = 1:4
data = read(augmentedTrainingData);
augmentedData{k} = insertShape(data{1},"rectangle",data{2}, data{4});
reset(augmentedTrainingData);
end
figure
montage(augmentedData,BorderSize=10)
% Helper function for performing data augmentation.
function data = augmentData(A)
% Apply random horizontal flipping, and random X/Y scaling. Boxes that get
% scaled outside the bounds are clipped if the overlap is above 0.25. Also,
% jitter image color.
data = cell(size(A));
for ii = 1:size(A,1)
I = A{ii,1};
bboxes = A{ii,2};
labels = A{ii,3};
sz = size(I);
Walter Roberson
Walter Roberson 2023 年 3 月 12 日
We need to see your complete function augmentData
weam
weam 2023 年 3 月 12 日
編集済み: weam 2023 年 3 月 12 日
function data = augmentData(A);
data = cell(size(A)); for ii = 1:size(A,1) I = A{ii,1}; bboxes = A{ii,2}; labels = A{ii,3}; sz = size(I);
if numel(sz) == 3 && sz(3) == 3
I = jitterColorHSV(I,...
contrast=0.0,...
Hue=0.1,...
Saturation=0.2,...
Brightness=0.2);
end
% Randomly flip image.
tform = randomAffine2d(XReflection=true,Scale=[1 1.1]);
rout = affineOutputView(sz,tform,BoundsStyle="centerOutput");
I = imwarp(I,tform,OutputView=rout);
% Apply same transform to boxes.
[bboxes,indices] = bboxwarp(bboxes,tform,rout,OverlapThreshold=0.25);
labels = labels(indices);
% Return original data only when all boxes are removed by warping.
if isempty(indices)
data(ii,:) = A(ii,:);
else
data(ii,:) = {I,bboxes,labels};
end
end
end
Walter Roberson
Walter Roberson 2023 年 3 月 12 日
the error message says
Error in recognitionThree>augmentData (line 231)
bboxes = A{ii,{1,1}};
but that line does not exist in the augmentData function that you posted.

サインインしてコメントする。

Pritesh Shah
Pritesh Shah 2023 年 3 月 5 日

0 投票

Check input command of this function.

質問済み:

2023 年 3 月 4 日

コメント済み:

2023 年 3 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by