Calculate total number of parameters in pretrained models

calculate total number of parameters in pretrained models
100 descargas
Actualizado 15 jul 2020

Ver licencia

calculate the total number of parameters in pretrained models
like alexnet,googlenet,...
clc;clear
%x=['googlenet','resnet18','resnet50','VGG16','darknet19','alexnet','mobilenet','Xception','custome'];
%par=[5976627,134272835,23487619,136310547,20838179,56880515,4233133,20808883,2985263]
%accuracy=[91.3,91.3,92,90.3,88.9,89.7,90.7,91.2,99.8]
%executiontime=[1,2,3,4,5,6,7,8,9]
%myDLnet=load('ALEXNET_1_among_5_folds.mat','netTransfer');%par 56880515
%myDLnet=load('xception_1_among_5_folds.mat','netTransfer');%par 20808883
%myDLnet=load('darknet19_1_among_5_folds.mat','netTransfer');%par 20838179
%myDLnet=load('googlenet_1_among_5_folds.mat','netTransfer');%par 5976627
%myDLnet=load('ResNet18_1_among_5_folds.mat','netTransfer');%par 11173251
%myDLnet=load('ResNet50_1_among_5_folds.mat','netTransfer');%par 23487619
%myDLnet=load('nasnetmobile_2_among_5_folds.mat','netTransfer');%par 4233133
% myDLnet=load('newcustomisedmodel_1_among_5_folds.mat','netTransfer');%par 2985263
% myDLnet=load('vgg16_1_among_5_folds.mat','netTransfer');%par 136310547
layers=myDLnet.netTransfer.Layers;
num_layers = size(layers,1);
num_para=0;
num_para1=0;
num_para2=0;
num_para3=0;
for i=2:num_layers
n=contains(class(myDLnet.netTransfer.Layers(i)),["Conv","Fully"]);
m=contains(class(myDLnet.netTransfer.Layers(i)),"Batch");
if (n==1)
num_para=num_para+prod(size(myDLnet.netTransfer.Layers(i,1).Weights));
num_para1=num_para1+prod(size(myDLnet.netTransfer.Layers(i,1).Bias));
end

if (m==1)
num_para2=num_para2+prod(size(myDLnet.netTransfer.Layers(i,1).Offset));
num_para3=num_para3+prod(size(myDLnet.netTransfer.Layers(i,1).Scale));
% disp(['num of Weights=',num2str(num_para),'for layer number =',num2str(i)])
% disp(['num of Bias=',num2str(num_para1),'for layer number =',num2str(i)])
end
end
total=num_para+num_para1;
disp(['total number of parameters=',num2str(total)])

Citar como

Amr Ez Eldin Elsayed Rashed (2024). Calculate total number of parameters in pretrained models (https://www.mathworks.com/matlabcentral/fileexchange/77771-calculate-total-number-of-parameters-in-pretrained-models), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2020a
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
1.3.0

solve some errors in calculations

1.2.0

draw a figure that shows the relation between prediction time, accuracy and the total number of parameters in each pretrained model

1.1.0

add offset and scale of batch normalization layer

1.0.0