FCN not being able to resume

2 views (last 30 days)
filipendo125
filipendo125 on 27 Jan 2018
Answered: Suvidha Tripathi on 23 Aug 2018
So I have performed some training on my data, and wanted to test my solution half-way through running training of FCN network for semantic segmentation. However, I got this error:
Error using trainNetwork (line 140)
The last layer must be an output layer.
Error in neural2 (line 93)
[sp, info] = trainNetwork(datasource,war.Layers,options);
Caused by:
Error using nnet.internal.cnn.layer.util.inferParameters (line 7)
The last layer must be an output layer.
What I have done is just loaded that checkpoint and tried to run training on it again, but that failed. Below is a short piece of my code with else statement not working:
imageSize = [227 227];
numClasses = numel(classes);
lgraph = fcnLayers(imageSize,numClasses,'type','16s');
st = fullfile('imade','checkPoint');
datasource = pixelLabelImageSource(imdsTrain,pxdsTrain);
doTraining = true;
if doTraining
options = trainingOptions('sgdm',...
'Plots','training-progress',...
'MiniBatchSize',1,...
'CheckpointPath', st,...
'Momentum',0.99,...
'InitialLearnRate', 1e-12,...
'L2Regularization',0.0005);
[net, info] = trainNetwork(datasource,lgraph,options);
else
options = trainingOptions('sgdm',...
'Plots','training-progress',...
'MaxEpochs',19, ...
'MiniBatchSize',1,...
'CheckpointPath', st,...
'Momentum',0.99,...
'InitialLearnRate', 1e-12,...
'L2Regularization',0.0005);
data = load (strcat(st,filesep,'convnet_checkpoint__4607__2018_01_27__21_25_03.mat'));
war = data.net;
[sp, info] = trainNetwork(datasource,war.Layers,options);
end

Answers (1)

Suvidha Tripathi
Suvidha Tripathi on 23 Aug 2018
When you are resuming training from a checkpoint in case of layer graph object, then just do this modification
newlgraph=layerGraph(net);
new_net = trainNetwork(pximds,newlgraph,options)
where net is your last checkpoint network.

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!