trainYOLOv4ObjectDetector>iParseInputsYOLOv4 The class names specified in the detector must match the class names in training data.
Hi.When I try to train a YOLOv4,he said that Error using trainYOLOv4ObjectDetector>iParseInputsYOLOv4
The class names specified in the detector must match the class names in training data.
But I checked the content of the label and it’s the same as the detector.And I didn’t have this problem when training FasterrCNN.Here is my code:
load(‘training_data.mat’)
>> trainingData = objectDetectorTrainingData(gTruth);
% Create a partition of the data into a 70/30 train/test split
cvp = cvpartition(size(trainingData, 1), ‘HoldOut’, 0.2);
% Get the indices of the training and testing sets
trainIdx = cvp.training;
testIdx = cvp.test;
% Extract the training and testing data using the indices
trainData = trainingData(trainIdx, :);
testData = trainingData(testIdx, :);
imdsTrain = imageDatastore(trainData.imageFilename);
imdsTest = imageDatastore(testData.imageFilename);
bldsTrain = boxLabelDatastore(trainData(:, 2:end));
bldsTest = boxLabelDatastore(testData(:, 2:end));
%imdsValidationData = imageDatastore(validationData.imageFilename);
%bldsValidationData = boxLabelDatastore(validationData(:, 2:end));
ds = combine(imdsTrain,bldsTrain);
inputSize = [2880 2880 3];
trainingDataForEstimation = transform(ds,@(data)preprocessData(data,inputSize));
numAnchors = 6;
[anchors, meanIoU] = estimateAnchorBoxes(trainingDataForEstimation,numAnchors);
area = anchors(:,1).*anchors(:,2);
[~,idx] = sort(area,"descend");
anchors = anchors(idx,:);
anchorBoxes = {anchors(1:3,:);anchors(4:6,:)};
classes =gTruth.LabelDefinitions.Name’;
detector = yolov4ObjectDetector("tiny-yolov4-coco",classes,anchorBoxes,InputSize=inputSize);
options = trainingOptions("sgdm", …
InitialLearnRate=0.001, …
MiniBatchSize=16,…
MaxEpochs=40, …
BatchNormalizationStatistics="moving",…
ResetInputNormalization=false,…
VerboseFrequency=30);
trainedDetector = trainYOLOv4ObjectDetector(ds,detector,options);
Error using trainYOLOv4ObjectDetector>iParseInputsYOLOv4
The class names specified in the detector must match the class names in training data.
Error in trainYOLOv4ObjectDetector (line 119)
[trainingData, params] = iParseInputsYOLOv4(trainingData,detector,options,mfilename,varargin{:});
detector.ClassNames
ans =
12×1 cell array
{‘lozenge’ }
{‘hexagon’ }
{‘trapezium’ }
{‘heart’ }
{‘semicircle’}
{‘pentagon’ }
{‘star’ }
{‘elliptical’}
{‘rectangle’ }
{‘square’ }
{‘triangle’ }
{‘circle’ }
gTruth.LabelDefinitions.Name
ans =
12×1 cell array
{‘lozenge’ }
{‘hexagon’ }
{‘trapezium’ }
{‘heart’ }
{‘semicircle’}
{‘pentagon’ }
{‘star’ }
{‘elliptical’}
{‘rectangle’ }
{‘square’ }
{‘triangle’ }
{‘circle’ }Hi.When I try to train a YOLOv4,he said that Error using trainYOLOv4ObjectDetector>iParseInputsYOLOv4
The class names specified in the detector must match the class names in training data.
But I checked the content of the label and it’s the same as the detector.And I didn’t have this problem when training FasterrCNN.Here is my code:
load(‘training_data.mat’)
>> trainingData = objectDetectorTrainingData(gTruth);
% Create a partition of the data into a 70/30 train/test split
cvp = cvpartition(size(trainingData, 1), ‘HoldOut’, 0.2);
% Get the indices of the training and testing sets
trainIdx = cvp.training;
testIdx = cvp.test;
% Extract the training and testing data using the indices
trainData = trainingData(trainIdx, :);
testData = trainingData(testIdx, :);
imdsTrain = imageDatastore(trainData.imageFilename);
imdsTest = imageDatastore(testData.imageFilename);
bldsTrain = boxLabelDatastore(trainData(:, 2:end));
bldsTest = boxLabelDatastore(testData(:, 2:end));
%imdsValidationData = imageDatastore(validationData.imageFilename);
%bldsValidationData = boxLabelDatastore(validationData(:, 2:end));
ds = combine(imdsTrain,bldsTrain);
inputSize = [2880 2880 3];
trainingDataForEstimation = transform(ds,@(data)preprocessData(data,inputSize));
numAnchors = 6;
[anchors, meanIoU] = estimateAnchorBoxes(trainingDataForEstimation,numAnchors);
area = anchors(:,1).*anchors(:,2);
[~,idx] = sort(area,"descend");
anchors = anchors(idx,:);
anchorBoxes = {anchors(1:3,:);anchors(4:6,:)};
classes =gTruth.LabelDefinitions.Name’;
detector = yolov4ObjectDetector("tiny-yolov4-coco",classes,anchorBoxes,InputSize=inputSize);
options = trainingOptions("sgdm", …
InitialLearnRate=0.001, …
MiniBatchSize=16,…
MaxEpochs=40, …
BatchNormalizationStatistics="moving",…
ResetInputNormalization=false,…
VerboseFrequency=30);
trainedDetector = trainYOLOv4ObjectDetector(ds,detector,options);
Error using trainYOLOv4ObjectDetector>iParseInputsYOLOv4
The class names specified in the detector must match the class names in training data.
Error in trainYOLOv4ObjectDetector (line 119)
[trainingData, params] = iParseInputsYOLOv4(trainingData,detector,options,mfilename,varargin{:});
detector.ClassNames
ans =
12×1 cell array
{‘lozenge’ }
{‘hexagon’ }
{‘trapezium’ }
{‘heart’ }
{‘semicircle’}
{‘pentagon’ }
{‘star’ }
{‘elliptical’}
{‘rectangle’ }
{‘square’ }
{‘triangle’ }
{‘circle’ }
gTruth.LabelDefinitions.Name
ans =
12×1 cell array
{‘lozenge’ }
{‘hexagon’ }
{‘trapezium’ }
{‘heart’ }
{‘semicircle’}
{‘pentagon’ }
{‘star’ }
{‘elliptical’}
{‘rectangle’ }
{‘square’ }
{‘triangle’ }
{‘circle’ } Hi.When I try to train a YOLOv4,he said that Error using trainYOLOv4ObjectDetector>iParseInputsYOLOv4
The class names specified in the detector must match the class names in training data.
But I checked the content of the label and it’s the same as the detector.And I didn’t have this problem when training FasterrCNN.Here is my code:
load(‘training_data.mat’)
>> trainingData = objectDetectorTrainingData(gTruth);
% Create a partition of the data into a 70/30 train/test split
cvp = cvpartition(size(trainingData, 1), ‘HoldOut’, 0.2);
% Get the indices of the training and testing sets
trainIdx = cvp.training;
testIdx = cvp.test;
% Extract the training and testing data using the indices
trainData = trainingData(trainIdx, :);
testData = trainingData(testIdx, :);
imdsTrain = imageDatastore(trainData.imageFilename);
imdsTest = imageDatastore(testData.imageFilename);
bldsTrain = boxLabelDatastore(trainData(:, 2:end));
bldsTest = boxLabelDatastore(testData(:, 2:end));
%imdsValidationData = imageDatastore(validationData.imageFilename);
%bldsValidationData = boxLabelDatastore(validationData(:, 2:end));
ds = combine(imdsTrain,bldsTrain);
inputSize = [2880 2880 3];
trainingDataForEstimation = transform(ds,@(data)preprocessData(data,inputSize));
numAnchors = 6;
[anchors, meanIoU] = estimateAnchorBoxes(trainingDataForEstimation,numAnchors);
area = anchors(:,1).*anchors(:,2);
[~,idx] = sort(area,"descend");
anchors = anchors(idx,:);
anchorBoxes = {anchors(1:3,:);anchors(4:6,:)};
classes =gTruth.LabelDefinitions.Name’;
detector = yolov4ObjectDetector("tiny-yolov4-coco",classes,anchorBoxes,InputSize=inputSize);
options = trainingOptions("sgdm", …
InitialLearnRate=0.001, …
MiniBatchSize=16,…
MaxEpochs=40, …
BatchNormalizationStatistics="moving",…
ResetInputNormalization=false,…
VerboseFrequency=30);
trainedDetector = trainYOLOv4ObjectDetector(ds,detector,options);
Error using trainYOLOv4ObjectDetector>iParseInputsYOLOv4
The class names specified in the detector must match the class names in training data.
Error in trainYOLOv4ObjectDetector (line 119)
[trainingData, params] = iParseInputsYOLOv4(trainingData,detector,options,mfilename,varargin{:});
detector.ClassNames
ans =
12×1 cell array
{‘lozenge’ }
{‘hexagon’ }
{‘trapezium’ }
{‘heart’ }
{‘semicircle’}
{‘pentagon’ }
{‘star’ }
{‘elliptical’}
{‘rectangle’ }
{‘square’ }
{‘triangle’ }
{‘circle’ }
gTruth.LabelDefinitions.Name
ans =
12×1 cell array
{‘lozenge’ }
{‘hexagon’ }
{‘trapezium’ }
{‘heart’ }
{‘semicircle’}
{‘pentagon’ }
{‘star’ }
{‘elliptical’}
{‘rectangle’ }
{‘square’ }
{‘triangle’ }
{‘circle’ } yolov4, classnames MATLAB Answers — New Questions