MATLAB Answers

1

How to classify with DAG network from checkpoint

Asked by Yoshinori Abe on 12 Oct 2018
Latest activity Edited by Gediminas Simkus on 1 Mar 2019
I want to use classify() with DAG network from checkpoint network.
I trained inceptionv3 by transfer learning for a long epochs and it was successed. I set 'CheckpointPath' and have networks at each epoch. I want to evaluate these networks, so I loaded one and used classify(). But error message occuerd and it said "Use trainNetwork". How can I use classify() with network loaded from checkpoint?

  2 Comments

Could you please provide the whole error message and the exact command that you executed?
Thank you for your comment.
My training code is below:
net = inceptionv3();
lgraph = layerGraph(net);
lgraph = removeLayers(lgraph, {'predictions','predictions_softmax','ClassificationLayer_predictions'});
numClasses = 2;
newlayers = [ ...
fullyConnectedLayer(numClasses,'Name','fc','WeightLearnRateFactor',20,'BiasLearnRateFactor',20)
softmaxLayer('Name','softmax')
classificationLayer('Name','classoutput')];
lgraph = addLayers(lgraph,newlayers);
lgraph = connectLayers(lgraph,'avg_pool','fc');
layers = lgraph.Layers;
connections = lgraph.Connections;
layers(1:281) = freezeWeights(layers(1:281));%mixed9までフリーズさせたつもり
lgraph = createLgraphUsingConnections(layers,connections);
optionsTransfer = trainingOptions('sgdm', ...
'MaxEpochs', 15, ...
'MiniBatchSize', 16, ...
'InitialLearnRate', 0.0001, ...
'CheckpointPath','c:\');
netTransfer = trainNetwork(Itrain,categtrain,lgraph,optionsTransfer);%Itrain and categtrain are loaded elesewhere
My test code is below:
load('c:\net_checkpoint__147__2018_10_11__14_02_59.mat');
categtest_test = classify(net,Itest); % Itest is loaded elsewhere
Error messages are below:
Error using nnet.internal.cnn.layer.BatchNormalization/predict (line 135)
Unable to use networks with batch normalization layers before training is complete. Use trainNetwork to complete network training.
Error in nnet.internal.cnn.DAGNetwork/predict (line 383)
outputActivations = thisLayer.predict(XForThisLayer);
Error in DAGNetwork/predict (line 622)
YBatch = predictNetwork.predict(X);
Error in DAGNetwork/classify (line 693)
scores = this.predict( X, varargin{:} );
Thanks in advance for you help.

Sign in to comment.

Products


Release

R2018b

1 Answer

Answer by Naoya
on 15 Oct 2018
 Accepted Answer

Thank you very much for providing the details.
The checkpoint network containing BatchNormalization layers is not supported on the current latest release (R2018b). I will forward this functionality as an enhancement request to our development team.
We applogize for causing inconvenience on the current checkpoint functionality.

  3 Comments

Please, mention clearly about this bug in your documentation. Wasted so much time because of this.
I agree. I have lost time trying to use one of my Checkpoints similar to Naoya's efforts. Please add this functionality ASAP.
Guys, what you could do is that you select the desired checkpoint and set in your trainingOptions to train with very little 'InitialLearnRate' for a single epoch. That shouldn't change your model much and end up with deployed network model.

Sign in to comment.