Hi Olalekan
Fine tuning a pre-trained model can improve the model performance, and your code achieves the requested problem effectively.
You have correctly split dataset using `splitEachLabel`.
I would suggest you to load both the models AlexNet and GoogleNet within the same script, or use a .mat file to use the same dataset across both files.
Train the fine tuned models using the same train dataset. And as you have the test set, you can use it for testing both models.
Sample code:
imds = imageDatastore(datasetFolder, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
trainRatio = 0.7;
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomize');
alexNet = alexnet;
googleNet = googlenet;
% Training Code similar to your current code.
% Validate both trained models with imdsValidation
[YPredAlexNet, scoresAlexNet] = classify(alexNet, imdsValidation);
accuracyAlexNet = mean(YPredAlexNet == imdsValidation.Labels);
disp(['AlexNet Validation Accuracy: ' num2str(accuracyAlexNet * 100) '%']);
[YPredGoogleNet, scoresGoogleNet] = classify(googleNet, imdsValidation);
accuracyGoogleNet = mean(YPredGoogleNet == imdsValidation.Labels);
disp(['GoogleNet Validation Accuracy: ' num2str(accuracyGoogleNet * 100) '%']);
You may refer to the following docs on `spliteachlabel`
Also refer to this article to discover more on Transfer Learning with MATLAB: