Issue with batch normalization layer of saved CNN

Illustration
technicalsource9 - 2021-04-26T13:44:31+00:00
Question: Issue with batch normalization layer of saved CNN

When loading a previously trained CNN, I got an issue with the batch normalization layers. When looking into the loaded CNN model the trainable mean and variance are empty. Name: 'batchnorm_1' TrainedMean: [] TrainedVariance: [] So the checkpoint doesn't seem to save these parameters. Are there any workarounds for this issue? I am using Matlab R2018b.  

Expert Answer

Profile picture of John Michell John Michell answered . 2025-11-20

We were able to reproduce the issue. We will inform you once the issue is fixed.
Since TrainedMean and TrainedVariance are calculated after the training is finished, therefore as a workaround you can use the below mentioned codes to explicitly save and load the Model.
%To save model with name "demoModel", assuming your network is in "net" 
save('demoModel','net') 
%To load model to variable net1
net1=load('demoModel.mat','net');
net1.net.Layers(n).TrainedMean %where n is the batch normalization layer


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!