Problem in datastore for training using yolo v2
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
i created the ground truth table from my own dataset. I follow this tutorial https://www.mathworks.com/help/vision/ref/objectdetectortrainingdata.html?searchHighlight=objectDetectorTrainingData&s_tid=doc_srchtitle; however, in stead of using ACF, i intend to use yolo v2 as the following tutorial https://www.mathworks.com/help/deeplearning/examples/object-detection-using-yolo-v2.html. The code is below.
clc
tic
[imds,bxds] = objectDetectorTrainingData(gTruth);
toc
tic
trainingData = combine(imds,bxds);
toc
data = read(trainingData);
I = data{1};
bbox = data{2};
annotatedImage = insertShape(I,'Rectangle',bbox);
annotatedImage = imresize(annotatedImage,2);
figure
imshow(annotatedImage)
display('create YOLO network');
inputSize = [224 224 3];
numClasses = 100;
trainingDataForEstimation = transform(trainingData,@(data)preprocessData(data,inputSize));
numAnchors = 5;
[anchorBoxes, meanIoU] = estimateAnchorBoxes(trainingDataForEstimation, numAnchors);
display('featureExtraction');
featureExtractionNetwork = resnet50;
featureLayer = 'activation_40_relu';
lgraph = yolov2Layers(inputSize,numClasses,anchorBoxes,featureExtractionNetwork,featureLayer);
display('Data augmentation');
augmentedTrainingData = transform(trainingData,@augmentData);
% Visualize the augmented images.
augmentedData = cell(4,1);
for k = 1:4
data = read(augmentedTrainingData);
augmentedData{k} = insertShape(data{1},'Rectangle',data{2});
reset(augmentedTrainingData);
end
figure
montage(augmentedData,'BorderSize',10)
display('preprocessing data');
preprocessedTrainingData = transform(augmentedTrainingData,@(data)preprocessData(data,inputSize));
data = read(preprocessedTrainingData);
I = data{1};
bbox = data{2};
annotatedImage = insertShape(I,'Rectangle',bbox);
annotatedImage = imresize(annotatedImage,2);
figure
imshow(annotatedImage)
display('train yolo network');
options = trainingOptions('sgdm', ...
'InitialLearnRate', 0.001, ...
'Verbose',true, ...
'MiniBatchSize',5, ...
'MaxEpochs',10, ...
'Shuffle','every-epoch', ...
'VerboseFrequency',10);
% Train the YOLO v2 detector.
[detector,info] = trainYOLOv2ObjectDetector(preprocessedTrainingData,lgraph,options);
After a couple of minutes, i receive this error.
Error using vision.internal.cnn.validation.checkTrainingBoxes (line 12)
Training data from a read of the input datastore contains invalid bounding boxes. Bounding boxes must be
non-empty, fully contained within their associated image and must have positive width and height. Use datastore
transform method and remove invalid bounding boxes.
Error in vision.internal.cnn.yolo.validateImagesAndBoxesTransform (line 22)
vision.internal.cnn.validation.checkTrainingBoxes(images, boxes);
Error in
trainYOLOv2ObjectDetector>@(data)vision.internal.cnn.yolo.validateImagesAndBoxesTransform(data,params.InputSize)
(line 262)
@(data)vision.internal.cnn.yolo.validateImagesAndBoxesTransform(data,params.InputSize));
Error in matlab.io.datastore.TransformedDatastore/read (line 148)
data = self.Transforms{ii}(data);
Error in nnet.internal.cnn.DataLoader/manageReadQueue (line 161)
data = read(self.Datastore);
Error in nnet.internal.cnn.DataLoader/nextBatch (line 88)
manageReadQueue(self);
Error in nnet.internal.cnn.GeneralDatastoreDispatcher/readNextBatchIntoCache (line 350)
data = nextBatch(this.DataLoader);
Error in nnet.internal.cnn.GeneralDatastoreDispatcher/next (line 307)
this.readNextBatchIntoCache();
Error in nnet.internal.cnn.Trainer/doComputeStatistics (line 213)
X = data.next();
Error in nnet.internal.cnn.Trainer/computeInputStatisticsInEnvironment (line 205)
stats = doComputeStatistics(this, data, stats, net);
Error in nnet.internal.cnn.Trainer/initializeNetwork (line 70)
stats = this.computeInputStatisticsInEnvironment(data,stats,net);
Error in vision.internal.cnn.trainNetwork (line 82)
trainedNet = trainer.initializeNetwork(trainedNet, inputStatsDispatcher);
Error in trainYOLOv2ObjectDetector>iTrainYOLOv2 (line 391)
[yolov2Net, info] = vision.internal.cnn.trainNetwork(...
Error in trainYOLOv2ObjectDetector (line 187)
[net, info] = iTrainYOLOv2(ds, lgraph, params, mapping, options, checkpointSaver);
Error in test_yolo_food_detection (line 61)
[detector,info] = trainYOLOv2ObjectDetector(preprocessedTrainingData,lgraph,options);
My ground truth table is some kind like that.
gTruth =
groundTruth with properties:
DataSource: [1×1 groundTruthDataSource]
LabelDefinitions: [100×4 table]
LabelData: [8768×100 table]
gTruth.LabelData
rice eelsonrice pilaf chickenAndEggonrice porkcutletonrice
____________ ____________ ____________ ___________________ ________________
{1×4 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{1×4 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{1×4 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{1×4 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{1×4 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
There are some images in the datasource do not have the presence of some category; therefore, i assign their lableData is empty.
Does this make the error above? How to fix it?
Thank you.
1 Kommentar
Zheng Yuan
am 24 Apr. 2021
hallo, i am faced with the same problem now when training my YOLOv2 model.
Have you already solved it?
Thank you
Antworten (2)
ahmed shahin
am 19 Mär. 2020
Dear AnH
if yoy please solve this error , let's me know how you did that?
Thanks
Ahmed
0 Kommentare
Vivek Akkala
am 16 Feb. 2023
Having empty bounding boxes in the datasource will cause the error. As mentioned in the error message you can either remove the empty bounding boxes manually or use a datastore transform method to remove these empty bounding boxes.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Recognition, Object Detection, and Semantic Segmentation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!