- Verify the dimensions of the images in the imageDatastore are consistent.
- Check the bounding box annotations in the boxLabelDatastore and make sure they are in the correct format.
- Ensure that the combined datastores (trainingData, validationData, testData) have the correct structure.
Error when training Fast R-CNN network with roi input
5 次查看(过去 30 天)
显示 更早的评论
When I begin to train a fast R-CNN network with the trainingData input datastore I receive an error
my network is:
I am only detecting one class, and all my ~6000 training images contain that class and I have marked it with a bounding box.
my code is:
clear
create_fast_RCNN_network_with_parameters_simpler_network;
load("ribeye_groundtruth_table.mat");
rng(1);
shuffledIndices = randperm(height(gTruth));
idx = floor(0.65 * height(gTruth));
trainingIdx = 1:idx;
trainingDataTbl = gTruth(shuffledIndices(trainingIdx),:);
validationIdx = idx+1 : idx + 1 + floor(0.25 * length(shuffledIndices) );
validationDataTbl = gTruth(shuffledIndices(validationIdx),:);
testIdx = validationIdx(end)+1 : length(shuffledIndices);
testDataTbl = gTruth(shuffledIndices(testIdx),:);
imdsTrain = imageDatastore(trainingDataTbl{:,'imageFilename'});
bldsTrain = boxLabelDatastore(trainingDataTbl(:,'RibEye'));
imdsValidation = imageDatastore(validationDataTbl{:,'imageFilename'});
bldsValidation = boxLabelDatastore(validationDataTbl(:,'RibEye'));
imdsTest = imageDatastore(testDataTbl{:,'imageFilename'});
bldsTest = boxLabelDatastore(testDataTbl(:,'RibEye'));
miniBatchSize = 14;
trainingData = combine(imdsTrain,bldsTrain);
validationData = combine(imdsValidation,bldsValidation);
testData = combine(imdsTest,bldsTest);
%this shows the first training data correctly!
data = read(trainingData);
I = data{1};
bbox = data{2};
annotatedImage = insertShape(I,'rectangle',bbox);
annotatedImage = imresize(annotatedImage,2);
figure
imshow(annotatedImage)
options = trainingOptions('sgdm',...
'MaxEpochs',10,...
'Momentum',0.9,...
'MiniBatchSize', miniBatchSize,...
'InitialLearnRate',1e-3,...
'LearnRateDropFactor', 0.1, ...
'LearnRateDropPeriod', 2, ...
'L2Regularization', 1e-5, ...
'CheckpointPath',tempdir,...
'ValidationData',validationData,...
'Shuffle','every-epoch', ...
'ValidationFrequency',220, ...
'Plots', 'training-progress');
[trainedDetector, info] = trainFastRCNNObjectDetector(trainingData, lgraph, options);
% after extracting region proposals from training datastore I receve the below error output:
testing trainingData with read yields:
data = read(trainingData)
data =
1×3 cell array
{576×720×3 uint8} {[73 43 486 277]} {[RibEye]}
Which seems correct.
I have also tested it with readall and I can see no problems.
but straight after training starts I receive this error:
*******************************************************************
Training a Fast R-CNN Object Detector for the following object classes:
* RibEye
--> Extracting region proposals from training datastore...done.
Input datastore returned more than one observation per row for network input 2.
Error in nnet.internal.cnn.dispatcher.GeneralDatastoreDispatcher>iAssertDataContainsOneObservationPerRow (line 631)
iAssertExpectedMiniBatchSize(i, numObservations, expectedBatchSize);
Error in nnet.internal.cnn.dispatcher.GeneralDatastoreDispatcher>iGetDataResponseSizesForMISO (line 540)
iAssertDataContainsOneObservationPerRow(i, numObservations, inputSize);
[this.DataSize, this.ResponseSize] = iGetDataResponseSizesForMISO(exampleData, ...
nnet.internal.cnn.dispatcher.GeneralDatastoreDispatcher( ...
dispatcher = nnet.internal.cnn.dispatcher.DispatcherFactory.createDispatcherMIMO( ...
trainingDispatcher = iCreateTrainingDataDispatcher(ds, mapping, trainedNet,...
[network, info] = vision.internal.cnn.trainNetwork(...
[detector, ~, info] = fastRCNNObjectDetector.train(trainingData, lgraph, options, executionSettings, params, checkpointSaver);
What could be causing this error?
I was able to train this network with a minibatchsize of 8. However after I modified some of my convolutional layers it no longer works with minibatchsize of 8.
0 个评论
采纳的回答
LeoAiE
2023-5-11
The error message suggests that the input datastore is returning more than one observation per row for network input 2. This might be due to incorrect data preparation, or the network architecture not being compatible with the prepared data.
To troubleshoot the issue, I suggest you double-check your data preparation steps and verify if the input data and labels are correctly combined. Also, make sure the modified convolutional layers in the network architecture are compatible with the input data format.
Here are a few steps to check your data preparation:
If the data preparation steps are correct, it's possible that the modifications in the convolutional layers have changed the way the network expects input data. In this case, you may need to update the input data format or modify the network architecture to match the input data format.
If you still encounter issues, please provide more information about the modifications you made to the convolutional layers and any other changes you made to the network architecture. This will help to identify the root cause of the problem and provide a more accurate solution.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!