我正在使用转移学习(使用更快的RCNN预训练的alexnet)对COCO数据集进行对象类别检测 . 但是,我收到了这个错误 .
警告:使用@(x)d.propose(x,minBoxSize,'MiniBatchSize',miniBatchSize)处理/train2014/COCO_train2014_000000256230.jpg时发生错误:?预期输入数字2,得分,大小为Mx1,但大小为0x0 . 此图片中的区域不会用于培训 . 在fastRCNNObjectDetector.invokeRegionProposalFcn(第268行)中fastRCNNObjectDetector> @(x,filename)fastRCNNObjectDetector.invokeRegionProposalFcn(fcnCopy,x,filename)(第158行)在fastRCNNObjectDetector.extractRegionProposals(第218行)中fastRCNNObjectDetector.train(第168行)在trainFasterRCNNObjectDetector中(第359行)检测中(第75行)
Can you please help me? Please have a look at the code, and let me know if there is any mistake? Thank you very much for your help and time in advance
附:训练数据(注释)存储在表中,其中第一列包含图像的路径和文件名 . 其余列包含与相应图像相关的边界框 . 每列代表一个对象类,例如人,自行车,汽车......等,如https://uk.mathworks.com/help/vision/ref/trainfasterrcnnobjectdetector.html所述 .
这是我的代码:
‘clear all
close all
clc
Train_data= load('************.mat'); %Load vehicle data set
addpath('************'); % path of the training images
numClasses = width(Train_data);
Train_data(1:3,:)% Display first few rows of the data set.
I = imread(Train_data.imageFilename{6}); % display one of the images with the bbox,
I = insertShape(I, 'Rectangle', Train_data.person{6});
I = imresize(I, 3);
figure
imshow(I)
net = alexnet; % loading pre-trained model (alexnet in this case)
net.Layers
layersTransfer = net.Layers(1:end-3);
layers = [
layersTransfer
fullyConnectedLayer(numClasses,'WeightLearnRateFactor',20,'BiasLearnRateFactor',20)
softmaxLayer
classificationLayer];
optionsStage1 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-5);% Options for step 1.
optionsStage2 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-5);% Options for step 2.
optionsStage3 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-6); % Options for step 3.
optionsStage4 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-6);% Options for step 4.
options = [
optionsStage1
optionsStage2
optionsStage3
optionsStage4
];
doTrainingAndEval = true; % Training network
if doTrainingAndEval
rng(0);
detector = trainFasterRCNNObjectDetector(Train_data, layers, options, ...
'NegativeOverlapRange', [0 0.3], ...
'PositiveOverlapRange', [0.6 1], ...
'BoxPyramidScale', 1.2);
else
detector=load('*********.mat').
end
Test_data= load('************.mat');% tesing and evaluation
addpath('************'); % path of the testing image
Test_data.imageFilename =Test_data.imageFilename;
I = imread(Test_data.imageFilename{452}); % Read one of the images.
[bboxes, scores,label] = detect(detector, I);% Run the detector.
I = insertObjectAnnotation(I, 'rectangle', bboxes, scores);% Annotate detections in the image.
figure
imshow(I)
if doTrainingAndEval
resultsStruct = struct([]); % Run detector on each image in the test set and collect results.
for i = 1:height(Test_data)
I = imread(Test_data.imageFilename{i}); % Read the image.
[bboxes, scores, labels] = detect(detector, I); % Run the detector.
resultsStruct(i).Boxes = bboxes; % Collect the results.
resultsStruct(i).Scores = scores;
resultsStruct(i).Labels = labels;
end
results = struct2table(resultsStruct); % Convert the results into a table.
else
results = data.results; % Load results from disk.
end
expectedResults = testData(:, 2:end); % Extract expected bounding box locations from test data.
[ap, recall, precision] = evaluateDetectionPrecision(results, expectedResults);% Evaluate the object detector using Average Precision metric.
figure;% Plot precision/recall curve
plot(recall, precision)
xlabel('Recall')
ylabel('Precision')
grid on
title(sprintf('Average Precision = %.1f', ap))’