Bounding boxes must be non-empty, fully contained within their associated image and must have positive width and height.
13 次查看(过去 30 天)
显示 更早的评论
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:
Invalid transform function defined on datastore.
The cause of the error was:
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 285)
transformFcn = @(data)vision.internal.cnn.yolo.validateImagesAndBoxesTransform(data,params.InputSize);
Error in matlab.io.datastore.TransformedDatastore/applyTransforms (line 619)
data = ds.Transforms{ii}(data);
Error in matlab.io.datastore.TransformedDatastore/read (line 222)
[data, info] = ds.applyTransforms(data, info);
Error in nnet.internal.cnn.DataLoader/manageReadQueue (line 182)
data = read(self.Datastore);
Error in nnet.internal.cnn.DataLoader/readAhead (line 213)
manageReadQueue(self);
Error in nnet.internal.cnn.DataLoader (line 81)
readAhead(self);
Error in nnet.internal.cnn.GeneralDatastoreDispatcher (line 275)
this.DataLoader = nnet.internal.cnn.DataLoader(ds,...
Error in nnet.internal.cnn.DataDispatcherFactory.createDataDispatcherMIMO (line 186)
nnet.internal.cnn.GeneralDatastoreDispatcher( ...
Error in vision.internal.cnn.trainNetwork>iCreateTrainingDataDispatcher (line 200)
dispatcher = nnet.internal.cnn.DataDispatcherFactory.createDataDispatcherMIMO( ...
Error in vision.internal.cnn.trainNetwork (line 40)
trainingDispatcher = iCreateTrainingDataDispatcher(ds, mapping, trainedNet,...
Error in trainYOLOv2ObjectDetector>iTrainYOLOv2 (line 435)
[yolov2Net, info] = vision.internal.cnn.trainNetwork(...
Error in trainYOLOv2ObjectDetector (line 198)
[net, info] = iTrainYOLOv2(ds, lgraph, params, mapping, options, checkpointSaver);
my code
load bedlabels.mat;
trainingDataTable = objectDetectorTrainingData(gTruth)
% Display first few rows of the data set.
trainingDataTable(1:4,:);
rng(0);
shuffledIndices = randperm(height(trainingDataTable));
idx = floor(0.6 * length(shuffledIndices) )
trainingIdx = 1:idx;
trainingDataTbl = trainingDataTable(shuffledIndices(trainingIdx),:);
validationIdx = idx+1 : idx + 1 + floor(0.1 * length(shuffledIndices) );
validationDataTbl = trainingDataTable(shuffledIndices(validationIdx),:);
testIdx = validationIdx(end)+1 : length(shuffledIndices);
testDataTbl = trainingDataTable(shuffledIndices(testIdx),:);
imdsTrain = imageDatastore(trainingDataTbl{:,'imageFilename'});
bldsTrain = boxLabelDatastore(trainingDataTbl(:,'bed'));
imdsValidation = imageDatastore(validationDataTbl{:,'imageFilename'});
bldsValidation = boxLabelDatastore(validationDataTbl(:,'bed'));
imdsTest = imageDatastore(testDataTbl{:,'imageFilename'});
bldsTest = boxLabelDatastore(testDataTbl(:,'bed'));
trainingData = combine(imdsTrain,bldsTrain);
validationData = combine(imdsValidation,bldsValidation);
testData = combine(imdsTest,bldsTest);
data = read(trainingData);
I = data{1};
bbox = data{2};
annotatedImage = insertShape(I,'Rectangle',bbox);
annotatedImage = imresize(annotatedImage,2);
figure
imshow(annotatedImage)
% Create a YOLO v2 Object Detection Network
net = resnet50();
lgraph = layerGraph(net);
imageInputSize = [512 1024 3];
imgLayer = imageInputLayer(imageInputSize,"Name","input_1");
lgraph = replaceLayer(lgraph,"input_1",imgLayer);
numClasses = width(trainingDataTable)-1;
numAnchors = 7;
[anchorBoxes, meanIoU] = estimateAnchorBoxes(trainingData, numAnchors)
featureLayer = 'activation_40_relu';
lgraph = yolov2Layers(imageInputSize,numClasses,anchorBoxes,net,featureLayer);
% data = read(trainingData);
% I = data{1};
% bbox = data{2};
% annotatedImage = insertShape(I,'Rectangle',bbox);
% annotatedImage = imresize(annotatedImage,2);
% figure
% imshow(annotatedImage)
options = trainingOptions('sgdm','MiniBatchSize',16,'InitialLearnRate',1e-3,'MaxEpochs',20,'ValidationData',validationData);
[detector,info] = trainYOLOv2ObjectDetector(trainingData,lgraph,options);
4 个评论
Ashley Cook
2021-8-2
I'm also having this error and don't see anything obvious wrong with my bounding boxes. Also is there a way to identify the problem boxes?
回答(2 个)
Vivek Akkala
2022-6-9
编辑:Vivek Akkala
2022-6-9
Hi,
The groundtruth here might have either empty bounding boxes or there is a possibility of having bounding boxes with size greater than the image size. Although this might not be the case in the original groundtruth, you might end up in this scenario while using data augmentation techniques.
0 个评论
Vidip
2024-3-26
编辑:Vidip
2024-3-26
In the case of valid bounding boxes, they must be non-empty, fully contained within their associated image and must have positive width and height.
The function 'helperSanitizeBoxes' is used to clean up invalid bounding box data. Boxes with values <=0 are removed, and fractional values are rounded to integers. If none of the boxes are valid, this function passes the data through to enable downstream processing to issue proper errors.
You can refer to this MATLAB Answer for more information related to this function:
1 个评论
Image Analyst
2024-3-26
Instead of "In the case of invalid bounding boxes," did you mean "In the case of valid bounding boxes,". Valid boxes must have those attributes while invalid boxes could have any crazy, nonsensical values.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!