"Index exceeds the number of array elements" in YoloV2ObjectDetector detect function.
Show older comments
After running the following code, I complete the training for the YOLOV2 and obtain the detector object. When I try to use the detector, I obtain the following compile error:
THIS IS FOR RELEASE R2020a despite saying R2019b. R2020a is not a available option in drop down menu.
Index exceeds the number of array elements (2).
Error in yolov2ObjectDetector>iPredictUsingFeatureMap (line 868)
featureMap = reshape(featureMap,gridSize(1)*gridSize(2),gridSize(3),1,[]);
Error in yolov2ObjectDetector>iPostProcessActivations (line 982)
outputPrediction = iPredictUsingFeatureMap(featureMap, params.Threshold, info.PreprocessedImageSize,
anchorBoxes, params.FractionDownsampling, params.WH2HW);
Error in yolov2ObjectDetector>iPredictUsingDatastore (line 931)
iPostProcessActivations(fmap, batchInfo{ii}, anchorBoxes, params);
Error in yolov2ObjectDetector/detect (line 397)
varargout{1} = iPredictUsingDatastore(ds, this.Network, params, anchors, layerName);
Please help, thanks in advance.
%train set
imdsTrain = imageDatastore(table1{:,'imagefilename'},'ReadFcn',@fitsread);
bldsTrain = boxLabelDatastore(traintbl);
trainData = combine(imdsTrain, bldsTrain);
imdsTest = imageDatastore(table2{:,'imagefilename'},'ReadFcn',@fitsread);
bldsTest = boxLabelDatastore(testtbl);
testData = combine(imdsTest, bldsTest);
layers = [
imageInputLayer([2560 2560],"Name","imageinput")
convolution2dLayer([40 40],48,"Name","conv_1","Padding","same","Stride",[7 7])
batchNormalizationLayer("Name","batchnorm_1")
reluLayer("Name","relu_1")
maxPooling2dLayer([2 2],"Name","maxpool_1","Padding","same","Stride",[2 2])
convolution2dLayer([25 25],128,"Name","conv_2","Padding","same","Stride",[5 5])
batchNormalizationLayer("Name","batchnorm_2")
reluLayer("Name","relu_2")
convolution2dLayer([15 15],128,"Name","conv_4","Padding","same","Stride",[4 4])
batchNormalizationLayer("Name","batchnorm_4")
reluLayer("Name","relu_4")
maxPooling2dLayer([2 2],"Name",'maxpool_2',"Padding","same",'stride',[2 2])
convolution2dLayer([9 9],128,"Name","conv_6","Padding","same","Stride",[3 3])
batchNormalizationLayer("Name","batchnorm_6")
reluLayer("Name","relu_6")
convolution2dLayer([9 9],128,"Name","conv_5","Padding","same","Stride",[3 3])
batchNormalizationLayer("Name","batchnorm_5")
reluLayer("Name","relu_5")
maxPooling2dLayer([2 2],"Name","maxpool_3","Padding","same",'stride',[2 2])
convolution2dLayer([7 7],128,"Name","conv_9","Padding","same","Stride",[2 2])
batchNormalizationLayer("Name","batchnorm_9")
reluLayer("Name","relu_9")
convolution2dLayer([7 7],128,"Name","conv_8","Padding","same","Stride",[2 2])
batchNormalizationLayer("Name","batchnorm_8")
reluLayer("Name","relu_8")];
lgraph_homemade=layerGraph(layers);
%%%%%%%%%%make our own yolo from resnet50
numAnchors = 7;
[anchorBoxes,~] = estimateAnchorBoxes(trainData,numAnchors);
featureLayer = 'relu_8';
inputSize = [2560 2560];
numClasses = 1;
lgraph2 = yolov2Layers(inputSize,numClasses,anchorBoxes,lgraph_homemade,featureLayer);
options = trainingOptions('adam',...
'InitialLearnRate',0.005,...
'LearnRateSchedule','piecewise', ...
'LearnRateDropFactor',0.5, ...
'LearnRateDropPeriod',1, ...
'Verbose',true,...
'MiniBatchSize',8,...
'MaxEpochs',4,...
'Shuffle','never',...
'VerboseFrequency',1);
[detector,info] = trainYOLOv2ObjectDetector(trainData,lgraph2,options);
res=detect(detector,testData)
Accepted Answer
More Answers (0)
Categories
Find more on Object Detection in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!