Why my bounding boxes are empty?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello
I'm trying to run a faster rcnn model on my data. This data was created using image labelar. Matlab creates this 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.
Can anyone help me?
This is my code:
clear all
close all
clc
format long g
data=load('matlab_V21_ROI_15_7_2021_slozka.mat') %matlab_V21_ROI_11_3_2021.mat
gTruth=data.gTruth
gTruth.DataSource
gTruth.LabelDefinitions
trainingDataTable=objectDetectorTrainingData(gTruth)
blds=boxLabelDatastore(trainingDataTable(:,2))
datasetCount=countEachLabel(blds)
bim=blockedImage(data.gTruth.DataSource.Source)
bls=selectBlockLocations(bim, "BlockSize",[256, 256])
bimds=blockedImageDatastore(bim, "BlockLocationSet", bls); % BlockLocationSet seznam bloků v obrazku
cds=combine(bimds,blds)
read(cds)
network = resnet50;%squeezenet; % resnet50
inputImageSize =[224 224 3]; %network.Layers(1).InputSize;
numClasses = 1;
featureLayer = 'activation_40_relu';%'fire5-concat' %'activation_40_relu';
%estimate anchor boxes
numAnchors = 3
[anchorBoxes,meanIoU] = estimateAnchorBoxes(cds,numAnchors);
anchorBoxes
meanIoU
maxNumAnchors = 3;
meanIoU = zeros([maxNumAnchors,1]);
anchorBoxes = cell(maxNumAnchors, 1);
for k = 1:maxNumAnchors
% Estimate anchors and mean IoU.
[anchorBoxes{k},meanIoU(k)] = estimateAnchorBoxes(cds,k);
end
figure
plot(1:maxNumAnchors,meanIoU,'-o')
ylabel("Mean IoU")
xlabel("Number of Anchors")
title("Number of Anchors vs. Mean IoU")
% anchor boxes - pokracovani
anchorBoxes = [ 72,70; 99,96; 53,51]; %72,70; 99,96; 53,51
lgraph = fasterRCNNLayers(inputImageSize,numClasses,anchorBoxes, ...
network,featureLayer);
analyzeNetwork(lgraph);
options = trainingOptions ( 'sgdm' , ...
'MiniBatchSize' , 1, ...
'InitialLearnRate' , 1e-1, ...
'ExecutionEnvironment','cpu',...
'MaxEpochs' , 5);
detector = trainFasterRCNNObjectDetector (cds, lgraph, options, ...
'NegativeOverlapRange' , [0 0.3], ...
'PositiveOverlapRange' , [0.6 1]);
7 Kommentare
Antworten (1)
T.Nikhil kumar
am 13 Okt. 2023
Hello Monika,
As per my understanding, you want to train a Faster RCNN network on your own dataset and are facing an invalid bounding box error.
The error message informs that the datastore contains inputs with invalid bounding boxes. The values of valid bounding boxes should be finite, positive, non-fractional, non-NaN and should be within the image boundary with a positive height and width.
All the invalid instances of bounding boxes in the dataset need to be deleted or modified to valid values.
You can apply the ‘transform’ function on the datastore and define your own transformation function to remove/modify such invalid bounding boxes. You can refer to the ‘@fcn’ input argument section in the following documentation to understand more about implementation of custom transformation function.
You can refer to a similar implementation of a custom dataset validation function ‘validateInputData.m’ in the ‘Object Detection using YOLOv3 network’ example attached below. (Open the example using ‘Copy Command’ to view the definition of the function)
I also suggest you not to hardcode the ‘anchorBoxes’ value but to calculate them using the ‘estimateAnchorBoxes’ function since it may add to better accuracy to the network.
Hope this resolves your query.
0 Kommentare
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!