clear;clc;
load('gTruth.mat'); %标记的gTruth
trainingfiles = gTruth.DataSource.Source; %图像位置
traininglabel = gTruth.LabelData; %图像标签
Combine the datastores.
imagefile = imageDatastore(trainingfiles);
imagelabel = boxLabelDatastore(traininglabel);
trainingData = combine(imgfiles, imglabel);
Load a preinitialized YOLO v2 object detection network.
inputImageSize = [227 227 3];
numClasses = 1;
anchorBoxes = [8,8; 12,12; 24 24];
network = 'resnet50';
featureLayer = 'activation_40_relu';
lgraph = fasterRCNNLayers(inputImageSize, numClasses, anchorBoxes,network,featureLayer);
augmentedTrainingData = transform(trainingData,@augmentData);
augmentedData = cell(6,1);
for k = 1:6
data = read(augmentedTrainingData);
augmentedData{k} = insertShape(data{1},"rectangle",data{2},"LineWidth",3);
reset(augmentedTrainingData);
end
figure
montage(augmentedData,BorderSize=10)
options = trainingOptions('sgdm',...
'InitialLearnRate',0.001,...
'Verbose',true,...
'MiniBatchSize',10,...
'MaxEpochs',20,...
'Shuffle','never',...
'VerboseFrequency',10,...
'CheckpointPath',tempdir);
[detector,info] = trainFasterRCNNObjectDetector(augmentedTrainingData,lgraph,options);
错误使用 visiongpuROIMaxPoolingForward
Maximum variable size allowed on the device is exceeded.
出错 trainFasterRCNNObjectDetector (第 462 行)
[detector, info] = iTrainEndToEnd(trainingData, fastRCNN, options, params, executionSettings, imageInfo);