MATLAB Answers

How to get the calculation amount of deep network FLOPS? Analyze Network app does not seem to count this metric?

4 views (last 30 days)
cui
cui on 9 Aug 2019
Edited: cui on 30 Jul 2021
In the matlab analyzeNetwork app, the general CNN model can have the required number of parameters, the size of the feature map, but no flops?...

Answers (2)


cui
cui on 7 Jul 2021
Edited: cui on 30 Jul 2021
gpuDevice
Error using gpuDevice (line 26)
Failed to load graphics driver. Unable to load library 'libcuda.so.1'. The error was:
libcuda.so.1: cannot open shared object file: No such file or directory
Update or reinstall your graphics driver. For more information on GPU support, see GPU Support by Release.
%% MATLAB R2021a
net50 = resnet50;
h=224;
w = 224;
layer = 'fc1000';
%% evaluate
X = gpuArray(rand(h,w,3));
features = activations(net50,X,layer);
dev = gpuDevice(1);
for i = 1:100
scalar = i;
X = gpuArray(rand(h*scalar,w*scalar,3));
% X = dlarray(X);
try % Out of memory on device.
t1 = tic;
features = activations(net50,X,layer,...
'Acceleration','none',...
'ExecutionEnvironment','gpu');
[H,W,C] = size(X);
ElapseTime(i) = toc(t1);
avaiableMem(i) = dev.AvailableMemory/(1024^2);
sizeInput(i) = H;
fprintf('input size:(%i*%i),耗时:%.2f秒,可用显存大小为:%g Mb\n',...
H,W,ElapseTime(i),avaiableMem(i));
catch
break
end
end
%% plot
figure('Color','white');
yyaxis left;
plot(sizeInput,ElapseTime,'-o','LineWidth',2);
xlabel('input image size')
ylabel('ElapseTime(s)')
yyaxis right;
plot(sizeInput,avaiableMem,'-o','LineWidth',2);
ylabel('Avaiable Memory(MB)')
grid on;
title('Indirect Evaluation of DeepNetwork computational power and number of parameters ')
FLOPs and #params correspond to ElapseTime, Avaiable Memory respectively.
The answer can be seen indirectly in this diagram.
run in MATLAB 2021a, win10

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!