[XTrain,~,YTrain] = digitTrain4DArrayData; [XValidation,~,YValidation] = digitTest4DArrayData; %Loading in training and validation images layers = [ imageInputLayer([153 365 3]) convolution2dLayer(3,8,'Padding','same') %8 filters of size 3x3 with 'same' padding (also 3x3), no size batchNormalizationLayer %Normalising each input between [0,1] reluLayer %Rectified Linear Unit (ReLu), threshold operation to each element of input, where any value less than zero is set to zero averagePooling2dLayer(2,'Stride',1) %Pool size 2x2 with Stride/step of 1 convolution2dLayer(3,16,'Padding','same') batchNormalizationLayer reluLayer averagePooling2dLayer(2,'Stride',1) convolution2dLayer(3,32,'Padding','same') batchNormalizationLayer reluLayer convolution2dLayer(3,32 ,'Padding','same') batchNormalizationLayer reluLayer dropoutLayer(0.2) fullyConnectedLayer(32) %Regression problem, FC layer must precede the regression layer at the end. Here at size 1 regressionLayer]; %Creating layer networks: 4 pairs of convoluting and pooling operations. miniBatchSize = 128; validationFrequency = floor(numel(YTrain)/miniBatchSize); options = trainingOptions('sgdm', ... 'MiniBatchSize',miniBatchSize, ... 'MaxEpochs',30, ... %Trained for 30 epochs 'InitialLearnRate',1e-3, ... %Setting inital learn rate to 0.001 'LearnRateSchedule','piecewise', ... 'LearnRateDropFactor',0.1, ... 'LearnRateDropPeriod',20, ... %Lowering the learn rate by 0.1 after 20 epochs 'Shuffle','every-epoch', ... 'ValidationData',{XValidation,YValidation}, ... 'ValidationFrequency',validationFrequency, ... 'Plots','training-progress', ... 'Verbose',false); %Training the network net = trainNetwork(XTrain,YTrain,layers,options); %Creating the network; this command uses a compatible GPU if possible. YPredicted = predict(net,XValidation); %Test the performance of the network by evaluating the accuracy on the validation data predictionError = YValidation - YPredicted; %Evaluating performance of the model by calculating: %1. Ther percentage of predictions within an acceptatble error margin %2. The RMSE of the predicted and actual thr = 10; %setting threshold to 10 numCorrect = sum(abs(predictionError) < thr); numValidationImages = numel(YValidation); %calculating no. predictions within acceptable error margin accuracy = numCorrect/numValidationImages; %accuracy as a % squares = predictionError.^2; rmse = sqrt(mean(squares)); %Calculating RSME
inputSize = [153 365 3]; numSamples = 128; numClasses = 4; responseSize = 32; %% Generate random data for training the network. trainData = randn([inputSize numSamples]); trainLabels = randn([numSamples responseSize]); %% Create a network. layers = [ imageInputLayer(inputSize) convolution2dLayer(3,8,'Padding','same') reluLayer averagePooling2dLayer(2,'Stride',1) convolution2dLayer(3,16,'Padding','same') batchNormalizationLayer reluLayer averagePooling2dLayer(2,'Stride',1) convolution2dLayer(3,32,'Padding','same') batchNormalizationLayer reluLayer convolution2dLayer(3,32 ,'Padding','same') batchNormalizationLayer reluLayer dropoutLayer(0.2) fullyConnectedLayer(responseSize) regressionLayer]; analyzeNetwork(layers); %% Define training options. options = trainingOptions('adam', ... 'InitialLearnRate',0.005, ... 'LearnRateSchedule','piecewise',... 'MaxEpochs',1, ... 'MiniBatchSize',4, ... 'Verbose',1, ... 'Plots','training-progress',.... 'ExecutionEnvironment','cpu'); %% Train the network. net = trainNetwork(trainData,trainLabels,layers,options);
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.