load 'D:\Documents\MATLAB\bridgeLabels.mat', 'gTruth'; %these are the labels I made in the image labeler app trainingData = objectDetectorTrainingData(gTruth); %this apparently makes the training data for me layers = [imageInputLayer([2160 3840 3]) convolution2dLayer([5 5],10) reluLayer() fullyConnectedLayer(10) softmaxLayer() classificationLayer()]; %I understand what all these things do, kind of. %I just copied this code from the demonstration in the reference %I'm getting some error with the classification layer I don't know how to fix options = trainingOptions('sgdm',... 'LearnRateSchedule','piecewise',... 'LearnRateDropFactor',0.2,... 'LearnRateDropPeriod',5,... 'MaxEpochs',20,... 'MiniBatchSize',64,... 'Plots','training-progress'); %again, most of this makes sense to me detector = trainRCNNObjectDetector(trainingData, layers, options); %ok so now the network is made apparently image = imread('D:\Documents\MATLAB\clubroot_shots\lcbo1.png'); %this is my testing image wid = 10; rois = zeros(1, (image.width/wid)*(image.height/wid)); for i=1:image.width/wid for j=1:image.height/wid rois(i+j*width) = [1+(i-1)*wid, 1+(j-1)*wid, wid, wid]; end end %I believe this code will split up the image into 10x10 regions of interest. %I wrote this block myself. classifyRegions(detector, image, rois) %and here the regions get classified. Semicolon off because i want to see what happens
When I run this code, I get the following errors:
Error using vision.internal.cnn.validation.checkNetworkClassificationLayer (line 9) The number object classes in the network classification layer must be equal to the number of classes defined in the input trainingData plus 1 for the "Background" class. Error in vision.internal.rcnn.parseInputs (line 35) vision.internal.cnn.validation.checkNetworkClassificationLayer(network, trainingData); Error in trainRCNNObjectDetector (line 185) params = vision.internal.rcnn.parseInputs(trainingData, network, options, mfilename, varargin{:}); Error in imagenn (line 20) detector = trainRCNNObjectDetector(trainingData, layers, options); Error in run (line 91) evalin('caller', strcat(script, ';'));
As given here, you are improperly initializing the fullyConnectedLayer. Instead of using fullyConnectedLayer(10) try something like this.
classes = {'first', 'second'} outputs = 1+numel(classes); % +1 for background class layers = [imageInputLayer([2160 3840 3]) convolution2dLayer([5 5],10) reluLayer() fullyConnectedLayer(outputs) softmaxLayer() classificationLayer()];
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.