I am trying to create Fast-R-CNN for Object Detection, but I am taking error. I have 1 class on the dataset 90 sample.
imds = imageDatastore('C:\Users\', 'IncludeSubfolders',...
true, 'FileExtensions','.jpg','LabelSource','foldernames');
rng(0)
shuffledIndices = randperm(height(gTruthTBL));
idx = floor(0.6 * height(gTruthTBL));
trainingIdx = 1:idx;
trainingDataTbl = gTruthTBL(shuffledIndices(trainingIdx),:);
validationIdx = idx+1 : idx + 1 + floor(0.1 * length(shuffledIndices) );
validationDataTbl = gTruthTBL(shuffledIndices(validationIdx),:);
testIdx = validationIdx(end)+1 : length(shuffledIndices);
testDataTbl = gTruthTBL(shuffledIndices(testIdx),:);
imdsTrain = imageDatastore(trainingDataTbl{:,'imageFilename'});
bldsTrain = boxLabelDatastore(trainingDataTbl(:,'Unviable'));
imdsValidation = imageDatastore(validationDataTbl{:,'imageFilename'});
bldsValidation = boxLabelDatastore(validationDataTbl(:,'Unviable'));
imdsTest = imageDatastore(testDataTbl{:,'imageFilename'});
bldsTest = boxLabelDatastore(testDataTbl(:,'Unviable'));
trainingData = combine(imdsTrain,bldsTrain);
validationData = combine(imdsValidation,bldsValidation);
testData = combine(imdsTest,bldsTest);
data = read(trainingData);
inputSize = [224 224 3];
preprocessedTrainingData = transform(trainingData, @(data) preprocessData(data,inputSize));
net = resnet50;
lgraph = layerGraph(net);
layersToRemove = {
'fc1000'
'fc1000_softmax'
'ClassificationLayer_fc1000'
};
lgraph = removeLayers(lgraph, layersToRemove);
numClasses = 1;
numClassesPlusBackground = numClasses + 1;
newLayers = [
fullyConnectedLayer(numClassesPlusBackground, 'Name', 'rcnnFC')
softmaxLayer('Name', 'rcnnSoftmax')
classificationLayer('Name', 'rcnnClassification')
];
lgraph = addLayers(lgraph, newLayers);
lgraph = connectLayers(lgraph, 'avg_pool', 'rcnnFC');
numOutputs = 4 * numClasses;
boxRegressionLayers = [
fullyConnectedLayer(numOutputs,'Name','rcnnBoxFC')
rcnnBoxRegressionLayer('Name','rcnnBoxDeltas')
];
lgraph = addLayers(lgraph, boxRegressionLayers);
lgraph = connectLayers(lgraph,'avg_pool','rcnnBoxFC');
lgraph = disconnectLayers(lgraph, featureExtractionLayer,'res5a_branch2a');
lgraph = disconnectLayers(lgraph, featureExtractionLayer,'res5a_branch1');
outputSize = [14 14]
roiPool = roiMaxPooling2dLayer(outputSize,'Name','roiPool');
lgraph = addLayers(lgraph, roiPool);
lgraph = connectLayers(lgraph, 'activation_40_relu','roiPool/in');
lgraph = connectLayers(lgraph, 'roiPool','res5a_branch2a');
lgraph = connectLayers(lgraph, 'roiPool','res5a_branch1');
roiInput = roiInputLayer('Name','roiInput');
lgraph = addLayers(lgraph, roiInput);
lgraph = connectLayers(lgraph, 'roiInput','roiPool/roi');
netOptions = trainingOptions('sgdm', ...
'MaxEpochs',10,...
'InitialLearnRate',1e-3,...
'MaxEpochs',50, ...
'CheckpointPath',tempdir,...
'ValidationData',validationData,...
'MiniBatchSize',64, ...
'Plots','training-progress')
detector = trainFasterRCNNObjectDetector(trainingData,lgraph,netOptions, ...
'NegativeOverlapRange',[0 0.3], ...
'PositiveOverlapRange',[0.6 1]);
Error using vision.internal.cnn.validation.checkGroundTruthDatastore (line 32)
The read method of the training input datastore must return an M-by-3 cell or table.
Error in trainFasterRCNNObjectDetector>iParseInputs (line 1037)
params.ClassNames = vision.internal.cnn.validation.checkGroundTruthDatastore(trainingDs);
Error in trainFasterRCNNObjectDetector (line 408)
[trainingData, options, params] = iParseInputs(...
Caused by:
Error using checkGroundTruthDatastore
Expected input number 1, Read output of training datastore input, to be an array with number of
columns equal to 3.