params = load("C:\Users\namit\MATLAB Drive\Individualproject\params_2023_02_13__20_34_32.mat");
digitDatasetPath = fullfile('Tomato - Copy/');
imds = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
labelCount = countEachLabel(imds)
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomize');
augimdsTrain = augmentedImageDatastore([227 227 3],imdsValidation);
augimdsValidation = augmentedImageDatastore([227 227 3],imdsTrain);
dsTrain = transform(augimdsTrain,@preprocessForTraining, IncludeInfo=true);
dsValidation = transform(augimdsValidation,@preprocessForTraining, IncludeInfo=true);
imageInputLayer([227 227 3],"Name","data","Mean",params.data.Mean)
convolution2dLayer([11 11],96,"Name","conv1","BiasLearnRateFactor",2,"Stride",[4 4],"Bias",params.conv1.Bias,"Weights",params.conv1.Weights)
reluLayer("Name","relu1")
crossChannelNormalizationLayer(5,"Name","norm1","K",1)
maxPooling2dLayer([3 3],"Name","pool1","Stride",[2 2])
groupedConvolution2dLayer([5 5],128,2,"Name","conv2","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"Bias",params.conv2.Bias,"Weights",params.conv2.Weights)
reluLayer("Name","relu2")
crossChannelNormalizationLayer(5,"Name","norm2","K",1)
maxPooling2dLayer([3 3],"Name","pool2","Stride",[2 2])
convolution2dLayer([3 3],384,"Name","conv3","BiasLearnRateFactor",2,"Padding",[1 1 1 1],"Bias",params.conv3.Bias,"Weights",params.conv3.Weights)
reluLayer("Name","relu3")
groupedConvolution2dLayer([3 3],192,2,"Name","conv4","BiasLearnRateFactor",2,"Padding",[1 1 1 1],"Bias",params.conv4.Bias,"Weights",params.conv4.Weights)
reluLayer("Name","relu4")
groupedConvolution2dLayer([3 3],128,2,"Name","conv5","BiasLearnRateFactor",2,"Padding",[1 1 1 1],"Bias",params.conv5.Bias,"Weights",params.conv5.Weights)
reluLayer("Name","relu5")
maxPooling2dLayer([3 3],"Name","pool5","Stride",[2 2])
fullyConnectedLayer(4096,"Name","fc6")
reluLayer("Name","relu6")
dropoutLayer(0.5,"Name","drop6")
fullyConnectedLayer(4096,"Name","fc7")
reluLayer("Name","relu7")
dropoutLayer(0.5,"Name","drop7")
fullyConnectedLayer(6,"Name","fc8")
softmaxLayer("Name","prob")
classificationLayer("Name","classoutput")];
options = trainingOptions("sgdm",...
"ExecutionEnvironment","auto",...
"InitialLearnRate",0.001,...
"Shuffle","every-epoch",...
"Plots","training-progress",...
"ValidationData",dsValidation);
net = trainNetwork(dsTrain,layers,options);
function dataOut = preprocessForTraining(data)
dataOut{idx} = imnoise(data{idx},'salt & pepper');