Step 6:  

Set options for tramsfer learning

clear;
clc;
close all;

mydata = imageDatastore('MerchData', ...   % load data from folder named 'MerchData'
'IncludeSubfolders',true, ...                           % Also include the subfolders (there are 5 of these for the 5 objects, cap, cube, ...)
'LabelSource','foldernames');                       % The name of the subfolders supply the "correct answer" labels
 
[mydataTrain,mydataValidation] = splitEachLabel(mydata,0.7);
  

%Resize images in the image datastores to match the pretrained network GoogLeNet.

mydataResizedTrain = augmentedImageDatastore([224 224],mydataTrain,'colorpreprocessing','gray2rgb'); 

mydataResizedValidation = augmentedImageDatastore([224 224],mydataValidation,'colorpreprocessing','gray2rgb');

% colorpreprocessing option above makes sure that if your data set includes

% both color and  grayscale images there won't be a problem loading them to the datastore.
% Color images usually have a dimension of mxnx3 where as grayscales are mxnx1

load MerchNewLayers  %network created for transfer learning using deepNetworkDesigner & GoogleNet

%SET OPTIONS FOR TRANSFER LEARNING
%Set InitialLearnRate to a small value to slow down learning in the transferred layers
% Specify a small number of epochs. An epoch is a full training cycle on
% the entire training data set. For transfer learning, you do not need to train for as many epochs.
% Shuffle the data every epoch.
% Specify the mini-batch size, that is, how many images to use in each iteration
% Specify validation data and validation frequency
% Turn on the training plot to monitor progress while you train

options = trainingOptions('sgdm', ...
'MiniBatchSize',10,... 
'MaxEpochs',6,...
'InitialLearnRate',1e-4,...   %this is 0.0001
'Shuffle','every-epoch',...
'ValidationData',mydataResizedValidation,...
'ValidationFrequency',6,...
'Verbose',false,...
'Plots','training-progress');