概述
神經網絡模型運算可以看成一個數據流入流出的過程,涉及的計算包含內存占用和浮點運算量兩個方面。數據占用的空間計算很容易,數據量乘以表示單個數據所占用的字節數 (e.g, 4, 8)。復雜一點的是 layer 部分的參數占用的空間。
本篇不涉及訓練時的梯度保存空間。
data-->layer-->data
浮點運算概念
參考自:https://blog.csdn.net/sinat_34460960/article/details/84779219
FLOPs:floating point operations,即表示浮點運算次數。
FLOPS:floating point operations per second,意指每秒浮點運算次數。
下圖是各種顯卡的計算能力(TFLOPS,每秒萬億次浮點運算 $10^{12} FLOPs /s$)。參考NVIDIA.
全連接型神經網絡
輸入data: (x,1);
輸出data: (y, 1);
$ params = y \times (x+1) $
"+1": bias.
$ FLOPs = y \times x [乘] + y \times x [加] $
卷積神經網絡
輸出feature map大小計算公式:
$ out_w = \frac{(in_w + 2P-f)}{2}+1 $
P 是 padding size,f是卷積核大小, $out_h$同理。
輸入data:$in_w, in_h, in_{chs}$;
輸出data: $out_w, out_h, out_{chs}$;
$ params = f \times f \times(in_{chs} + 1) $
$ FLOPs = 2 \times (f \times f \times in_{chs})\times(out_w\times out_h \times out_{chs}) $;加和乘各一半。