error during calculating precision recall curve in Faster RCNN

3 views (last 30 days)
hi everyone
i encounter this problem while finding recall precision curev how can i resolve it.error is below
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in vision.internal.cnn.fastrcnn.detectUsingDatastore>iFindNumFiles (line 39)
numFiles = numFiles + bboxes{ii}(end,5);
Error in vision.internal.cnn.fastrcnn.detectUsingDatastore (line 28)
numFiles = iFindNumFiles(proposals);
Error in fasterRCNNObjectDetector/detect (line 552)
varargout{1} = vision.internal.cnn.fastrcnn.detectUsingDatastore(ds, this.Network, dataMap, layerOut, params);
Error in fasterRCNNtestdetect (line 39)
detectionResults = detect(detector,testData,'MinibatchSize',1,'Threshold', 0.1);
where my code is
clear
load('C:\Users\ZBook\OneDrive\Desktop\detector\detectorFasterRCNN50.mat');
dataRoad = load("D:\seg\pothole.mat");
dataRoad.gTruth
dataRoad.gTruth.LabelDefinitions
img = imageDatastore(dataRoad.gTruth.DataSource.Source);
labeldata = dataRoad.gTruth.LabelData;
blds = boxLabelDatastore(labeldata);
cds = combine(img, blds);
preview(cds)
tbl = countEachLabel(blds);
% Define the split ratios (e.g., 70% training, 15% validation, 15% testing)
trainRatio = 0.7;
valRatio = 0.10;
testRatio = 0.2;
% Count the total number of images
numImages = numel(img.Files);
% Calculate the number of images for each split
numTrain = round(trainRatio * numImages);
numVal = round(valRatio * numImages);
numTest = numImages - numTrain - numVal;
% Shuffle the datastore
cds = shuffle(cds);
inputSize = [224 224 3];
% Split the datastore into training, validation, and testing sets
trainingData = subset(cds, 1:numTrain);
validationData = subset(cds, numTrain+1:numTrain+numVal);
testData = subset(cds, numTrain+numVal+1:numTrain+numVal+numTest);
testdata = transform(testData, @(data) preprocessData(data, inputSize));
% Make predictions
detectionResults = detect(detector,testData,'MinibatchSize',1,'Threshold', 0.1);
classID = 1;
metrics = evaluateObjectDetection(detectionResults,testData);
precision = metrics.ClassMetrics.Precision{classID};
recall = metrics.ClassMetrics.Recall{classID};
figure
plot(recall,precision)
xlabel('Recall')
ylabel('Precision')
grid on
title(sprintf('Average Precision = %.2f', metrics.ClassMetrics.mAP(classID)))
function data = preprocessData(data, targetSize)
% Resize image and bounding boxes to the targetSize.
sz = size(data{1}, [1, 2]);
scale = targetSize(1:2) ./ sz;
data{1} = imresize(data{1}, targetSize(1:2));
% Pass imageSize to helperSanitizeBoxes
imageSize = targetSize; % You may adjust this based on your needs
data{2} = helperSanitizeBoxes(data{2}, imageSize);
% Resize boxes to new image size.
data{2} = bboxresize(data{2}, scale);
end

Answers (1)

Gagan Agarwal
Gagan Agarwal on 30 Jan 2024
Hi Ahmad,
The error message you are encountering suggests that the problem is related to indexing.
To address this issue, consider the following steps:
  1. Verfiy the data format of the dataset and ensure that the data is correctly formatted.
  2. Check for NaN values as there might be a case that NaN values are present in the data set.
  3. Verify the ouput of the 'preprocess' data function to ensure that it is producing the expected results.
I hope it helps!

Community Treasure Hunt

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

Start Hunting!