Removing invalid bounding boxes from datastore

89 ビュー (過去 30 日間)
Kyle Peterson
Kyle Peterson 2019 年 9 月 25 日
コメント済み: wang Wang 2021 年 10 月 18 日
I am trying to use object detector training data create using the image data labeler to train a YOLOv2 model. I keep getting the 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.
All entries in the dataset have a corresponding bounding box in the correct format. Does anyone know how to do this as suggested?
% sort data
rng(0);
shuffledIndices = randperm(height(Data));
idx = floor(0.7 * length(shuffledIndices) );
trainingDataTbl = Data(shuffledIndices(1:idx),:);
testDataTbl = Data(shuffledIndices(idx+1:end),:);
% create image datastore
imdsTrain = imageDatastore(trainingDataTbl{:,'imageFilename'});
bldsTrain = boxLabelDatastore(trainingDataTbl(:,'Tip'));
imdsTest = imageDatastore(testDataTbl{:,'imageFilename'});
bldsTest = boxLabelDatastore(testDataTbl(:,'Tip'));
trainingData = combine(imdsTrain,bldsTrain);
testData = combine(imdsTest,bldsTest);
%% Create YOLOv2 network
% Input size for detector.
imageInputSize = [224 224 3];
% define classes
numClasses = width(Data)-1;
% estimate anchor boxes
numAnchors = 7;
trainingDataForEstimation = transform(trainingData,@(data)preprocessData(data,imageInputSize));
[anchorBoxes, meanIoU] = estimateAnchorBoxes(trainingDataForEstimation, numAnchors);
% define feature extraction network
featureExtractionNetwork = resnet50;
featureLayer = 'activation_40_relu';
lgraph = yolov2Layers(imageInputSize,numClasses,anchorBoxes,featureExtractionNetwork,featureLayer);
% train YOLOv2 object detector
options = trainingOptions('sgdm', ...
'MiniBatchSize', 16, ....
'InitialLearnRate',1e-3, ...
'MaxEpochs',12,...
'Shuffle','every-epoch');
% augment data
augmentedTrainingData = transform(trainingData,@augmentData);
% Train the YOLO v2 detector
[detector,info] = trainYOLOv2ObjectDetector(trainingData,lgraph,options);

回答 (3 件)

ahmed shahin
ahmed shahin 2020 年 3 月 19 日
please if you try to detect multi object and it is not necessary that each image have all classes
is this causes error?
i will appreciate your help
  1 件のコメント
wang Wang
wang Wang 2021 年 10 月 18 日
I encountered this problem when detecting multiple objects,does anyone know how to solve it?

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


Tunai Marques
Tunai Marques 2019 年 10 月 11 日
Hi Kyle, I am facing a very similar problem. In my case, I can see exactly what augmented samples/BBs are giving me trouble.
Try running the following code to check the transformed data. One of them should have a funky bounding box (in my case, one of them did not have a BB at all after the transform).
Change "25" by the number of samples you want to check. "trainingData" is the 1x1 TransformedDatastore.
Hope that helps.
augmentedData = cell(25,1);
k = 1;
while hasdata(trainingData)
T = read(trainingData);
I = T{1};
bbox = T{2};
augmentedData{k} = insertShape(I,'Rectangle',bbox);
k = k+1;
end
figure
montage(augmentedData,'BorderSize',2)
  1 件のコメント
Madura Meenakshi Ramamoorthi
Madura Meenakshi Ramamoorthi 2021 年 1 月 27 日
Hi Tunai Marques,
How did u remove that funky bounding box from trainingdata.

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


Cong Dong Ngoc Minh
Cong Dong Ngoc Minh 2020 年 7 月 30 日
編集済み: Cong Dong Ngoc Minh 2020 年 7 月 30 日
Hi Kyke,
Please check the bounding boxes whether it has '0' in coordinate. Due to MATLAB starts at '1' in the image, so that you can modify from '0' to '1' of the bounding box's coordinate. Scale it if it is larger than the image's size.
Thanks!
  1 件のコメント
Hamza Afzal
Hamza Afzal 2021 年 2 月 4 日
I think 0 in bboxes doesnot make an error, since also in matlab personal .mat files, there were empty sets

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

Community Treasure Hunt

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

Start Hunting!

Translated by