MATLAB: How to add a regression layer at the end of an existing CNN

cnnComputer Vision Toolboxconvnetdeep learningDeep Learning ToolboxStatistics and Machine Learning Toolboxtransfer learning

Hi
I have been trying to use transfer learning with a regression layer at the end. However, I end up with NaNs when I try to predict new images with the ConvNet. How should I put together the layers at the end? Like this?
% Load VGG network
net = vgg19;
% Remove last 3 layers.
layersTransfer = net.Layers(1:end-3);
% Add a fully connected layer and a regression layer
layers = [layersTransfer
fullyConnectedLayer(1)
regressionLayer];
% Training options
transferLayerOptions = trainingOptions('sgdm','MiniBatchSize',25,...
'InitialLearnRate',0.001, ...
'MaxEpochs',7, 'Verbose', true);

Best Answer

As Birju Patel suggested. I believe the problem was a too high initial learn rate. Lowering it to 1e-5 worked.
Related Question